动态更改设置值?

时间:2010-05-25 23:21:16

标签: jquery datatables

是否可以在飞行中更改jQuery DataTables设置值。接下来我的问题是,我需要立即更改sAjaxSource。已经尝试过这样的事情:

var oDefault = {
    "bServerSide": true,
    "bProcessing": true,
    "bJQueryUI": true,
    "bLengthChange": false,
    "bFilter": true,
    "iDisplayLength": 8,
    "sAjaxSource": "my.php?" + "idKat="+aData[3],
    "aaSorting": [[ 0, "asc" ],[ 3, "asc" ]],
    "sDom": '<"top"ir>t<"bottom"pf<"clear">',
    "sPaginationType": "full_numbers",
    "oLanguage": {
        "sUrl": "<?php echo $full_path_jezik_2;?>"
    },
    "aoColumns": [
        { "sName": "rb","sWidth": "15%", "sClass": "center","sType": "numeric" },
        { "sName": "chkZaBrisanje","sWidth": "20%", "sClass": "center", "bSortable":false },
        { "sName": "rbPrvaSlika","sWidth": "15%", "sClass": "center","bSortable":false  },
        { "sName": "nazivSlike","sWidth": "50%", "sClass": "center", "sSortDataType": "dom-text"  }
    ]
};

var oST = $.extend( true, {}, oDefault );
oST.sAjaxSource = "my.php?" + "idKat="+aData[3];

alert(oST.sAjaxSource);

if (typeof oTable == 'undefined') {
    oTable = $("#my-table").dataTable(oST);
}
else
{               
    oTable.fnDraw();
} 

点击后我的aData[3]已更改。

3 个答案:

答案 0 :(得分:45)

你试过吗

 oTable = $("#my-table").dataTable(oST);
 var oSettings = oTable.fnSettings();
 oSettings.sAjaxSource  = "new value";

答案 1 :(得分:3)

您可以使用fnReloadAjax()函数,查看官方数据表站点上的插件。

答案 2 :(得分:1)

对于DataTables 1.10 +

使用如下所示的ajax.url() API方法设置Ajax URL并立即从新来源加载数据:

var table = $('#example').DataTable({
    ajax: 'data.json'
});

table.ajax.url('newData.json').load();

对于DataTables 1.9

使用fnReloadAjax()插件从Ajax源重新加载表格数据。请注意,此插件已被弃用。