关于angularjs dataTables 怎么传参

2025-03-03 21:55:28
推荐回答(1个)
回答1:

我们一般都是页面布局:上面几个查询条件,有个【查询】按钮,然后下面是个grid
关于dataTables 怎么接收参数,调用ajax,然后把结果显示出来。
我就卡在传参数这块。
一般的ajax

var example_table = $('#example_table').DataTable({
'ajax': {
"type" : "POST",
"url" : '/path/to/your/URL',
"data" : function( d ) {
d.example_key1= $('#example_input1').val();
d.example_key2= $('#example_input2').val();
d.example_key3= $('#example_input3').val();
},
"dataSrc": ""
},
'columns': [
{"data" : "metric_name"},
{"data" : "metric_type"},
{"data" : "metric_timestamp"},
{"data" : "metric_duration"}
]
});
//To Reload The Ajax
//See DataTables.net for more information about the reload method
example_table.ajax.reload()

As you can see, you simply can see any property of the parameter “d” and set a value. DataTables when then set the “data” object to those properites.