4

如果我有一个 sAjaxSource,我可以通过它传递参数以使我的页面更灵活吗?这是我现在的样子:

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

最终目标是当用户登陆页面时,预定义参数加载特定数据。在用户对更新参数的其他信息进行选择之后,然后更新数据表。

这是大多数准备好的功能

        $(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

3 回答 3

5

使用您的示例代码,它看起来像这样:

$(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,
    ...

这样的设置将传递所有正常的 Datatables 参数以及 region_type、region_code、ind_min 和 ind_max。

在 sAjaxSource 代码中,您可以像正常一样检索这些参数(我使用 VB)

    Dim RegionType As Integer = Request("region_type")
于 2013-11-27T19:50:45.793 回答
0

显然 fnServerParams 不适用于旧版本的数据表。使用 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",
...
于 2015-01-24T08:38:56.750 回答
-1

您想要使用的方式不是 datatbles 使用的方式,因此请尝试使用fnServerParams

$('#example').dataTable( {
    "bProcessing": true,
    "bServerSide": false,
    "sAjaxSource": "scripts/server_processing.php",
    "fnServerParams": function ( aoData ) {
      aoData.push( { "name": "more_data", "value": "my_value" } );
    }
  } );
于 2013-04-03T12:35:49.570 回答