SAjaxSource Params

If I have sAjaxSource, can I pass parameters to make my page more flexible? Here's how I have it now:

"sAjaxSource": "Data/IndustryTable?region_type=4&region_code=51&ind_min=10&ind_max=99" 

The ultimate goal is that when a user lands on a page, predefined parameters load specific data. After the user makes a choice for such other information that updates the parameters, then the data is updated.

Here is the majority of the finished function

  $(document).ready(function () { var anOpen = []; var oTable = $('#VADataTable').dataTable ({ // "sDom": 'T<"clear">lfrtip', // "oTableTools": // { // "sSwfPath": "/swf/copy_csv_xls_pdf.swf" // }, //flash must be enabled "iDisplayLength": 5, //defalut amount of rows shown on page "bServerSide": false, //uses sever for filter curently turned off "bFilter": false, //makes columns clickable to filter "bProcessing": true, //"bserverSide":true, "bJQueryUI": true, //enables user interface "bSort": true, //sorting for columns "bScrollInfinite": true, //using this takes away ddl of selection "sAjaxSource": "Data/IndustryTable?region_type=4&region_code=51&ind_min=10&ind_max=99", //where ajax commands renders results "sScrollY": "200px", "sScrollX": "100%", "sScrollXInner": "100%", "bScrollCollapse": true, 
+4
source share
3 answers

Using your sample code, it will look something like this:

 $(document).ready(function () { var anOpen = []; var oTable = $('#VADataTable').dataTable ({ // "sDom": 'T<"clear">lfrtip', // "oTableTools": // { // "sSwfPath": "/swf/copy_csv_xls_pdf.swf" // }, //flash must be enabled "iDisplayLength": 5, //defalut amount of rows shown on page "bServerSide": false, //uses sever for filter curently turned off "bFilter": false, //makes columns clickable to filter "bProcessing": true, //"bserverSide":true, "bJQueryUI": true, //enables user interface "bSort": true, //sorting for columns "bScrollInfinite": true, //using this takes away ddl of selection "sAjaxSource": "Data/IndustryTable", //I use a custom .aspx page for my source "fnServerParams": function ( aoData ) { aoData.push( { "name": "region_type", "value": "4" }, { "name": "region_code", "value": "51"}, { "name": "ind_min", "value": "10"}, { "name": "ind_max", "value": "99"} ); }, "sScrollY": "200px", "sScrollX": "100%", "sScrollXInner": "100%", "bScrollCollapse": true, ... 

A similar setting will pass all the usual Datatables parameters, as well as region_type, region_code, ind_min and ind_max.

In sAjaxSource code, you can get these parameters as usual (I use VB)

  Dim RegionType As Integer = Request("region_type") 
+2
source

FnServerParams does not seem to work on older versions of Datatables. How about using PHP:

 ... "bScrollInfinite": true, //using this takes away ddl of selection "sAjaxSource": "Data/IndustryTable?region_type=<?=$_GET['region_type'];?>&region_code=<?=$_GET['region_code'];?>&ind_min=<?=$_GET['ind_min'];?>&ind_max=<?=$_GET['ind_max'];?>", //where ajax commands renders results "sScrollY": "200px", ... 
0
source

Their path you want to use is not the way to use datatbles, so try using fnServerParams :

 $('#example').dataTable( { "bProcessing": true, "bServerSide": false, "sAjaxSource": "scripts/server_processing.php", "fnServerParams": function ( aoData ) { aoData.push( { "name": "more_data", "value": "my_value" } ); } } ); 
-1
source

All Articles