Troy Bryant
Troy Bryant

Reputation: 1024

sAjaxSource Params

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&region_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&region_code=51&ind_min=10&ind_max=99",   //where ajax commands renders results                              
            "sScrollY": "200px",
            "sScrollX": "100%",
            "sScrollXInner": "100%",
            "bScrollCollapse": true,

Upvotes: 4

Views: 11469

Answers (3)

Konservin
Konservin

Reputation: 1017

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'];?>&region_code=<?=$_GET['region_code'];?>&ind_min=<?=$_GET['ind_min'];?>&ind_max=<?=$_GET['ind_max'];?>",   //where ajax commands renders results                              
"sScrollY": "200px",
...

Upvotes: 1

Primalpat
Primalpat

Reputation: 374

Using 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")

Upvotes: 5

OQJF
OQJF

Reputation: 1350

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" } );
    }
  } );

Upvotes: -1

Related Questions