If I have a sAjaxSource can i pass parameters through that to make my page more flexiable? Here is how I have it now:
"sAjaxSource": "Data/IndustryTable?region_type=4®ion_code=51&ind_min=10&ind_max=99"
The end goal is that when a user lands on the page predefined parameters load the specific data. After a user makes a selection to so other information that updates the parameters then updates the datatable.
Here is majority of the ready 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®ion_code=51&ind_min=10&ind_max=99", //where ajax mands renders results
"sScrollY": "200px",
"sScrollX": "100%",
"sScrollXInner": "100%",
"bScrollCollapse": true,
If I have a sAjaxSource can i pass parameters through that to make my page more flexiable? Here is how I have it now:
"sAjaxSource": "Data/IndustryTable?region_type=4®ion_code=51&ind_min=10&ind_max=99"
The end goal is that when a user lands on the page predefined parameters load the specific data. After a user makes a selection to so other information that updates the parameters then updates the datatable.
Here is majority of the ready 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®ion_code=51&ind_min=10&ind_max=99", //where ajax mands renders results
"sScrollY": "200px",
"sScrollX": "100%",
"sScrollXInner": "100%",
"bScrollCollapse": true,
Share
Improve this question
edited Apr 3, 2013 at 12:28
tereško
58.5k25 gold badges100 silver badges150 bronze badges
asked Apr 3, 2013 at 12:22
Troy BryantTroy Bryant
1,0248 gold badges30 silver badges61 bronze badges
2
- No...worked around by hard coding the values – Troy Bryant Commented Jun 20, 2014 at 14:56
- @TroyBryant I had tried same thing but not able to update parameter after page load..basically i am storing user filter query parameter in database for report purpose and retrieve it when user show its saved reports..in sort want to store datatable state.. – Naitik Shah Commented Nov 10, 2014 at 9:29
3 Answers
Reset to default 5Using your example code, it would 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 setup like that will pass all the normal Datatables parameters as well as region_type, region_code, ind_min, and ind_max.
In the sAjaxSource code, you can retrieve these parameters like normal (I use VB)
Dim RegionType As Integer = Request("region_type")
Apparently fnServerParams isn't working on older versions of Datatables. What about using PHP:
...
"bScrollInfinite": true, //using this takes away ddl of selection
"sAjaxSource": "Data/IndustryTable?region_type=<?=$_GET['region_type'];?>®ion_code=<?=$_GET['region_code'];?>&ind_min=<?=$_GET['ind_min'];?>&ind_max=<?=$_GET['ind_max'];?>", //where ajax mands renders results
"sScrollY": "200px",
...
They way that you want to use is not the way that datatbles uses, so try to use fnServerParams:
$('#example').dataTable( {
"bProcessing": true,
"bServerSide": false,
"sAjaxSource": "scripts/server_processing.php",
"fnServerParams": function ( aoData ) {
aoData.push( { "name": "more_data", "value": "my_value" } );
}
} );