sAjaxSource Params

asp.net-mvc, datatables, javascript, jquery

Solution

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

Problem

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, ```

Original source