Jquery DataTables 以及如何在表单中选择/输入更改时推送数据
我有一个表单来过滤表中的数据。但我对如何将数据传递到 DataTables 以及如何在任何选择或输入更改时刷新表有一些疑问。
这是代码的一部分:
function renderDataTable(selector) {
var out = [];
var tables = jQuery(selector);
var sorting;
for ( var i=0, iLen=tables.length ; i<iLen ; i++ ){
var defaultCol = jQuery('th', tables[i]).index(jQuery(".dataTable-defaultSort",tables[i]));
if(defaultCol >= 0){
sorting = [ defaultCol, 'desc' ];
}else{
sorting = [12,'desc'];
}
var oTable2 = jQuery(tables[i]).dataTable({
"sDom": 'T<"clearfix">lfrt<"clearfix">ip',
"aaSorting": [ sorting ],
"bStateSave": true,
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "list.php",
"iDisplayLength": 20,
"aLengthMenu": [[20, 50, 100], [20, 50, 100]],
"sPaginationType": "full_numbers",
});
out.push( oTable2 );
}
return out;
}
$(document).ready(function() {
renderDataTable("#main_table");
$("select#myVar").change(function () {
var myVar = $(this).val();
// push data to table and refresh?
});
});
有人可以帮我吗?提前致谢。
I have a form to filter out data in a table. But I'm having some questions in how to pass that data to DataTables and how to refresh the table on any of the select or input change.
Here is the part of the code:
function renderDataTable(selector) {
var out = [];
var tables = jQuery(selector);
var sorting;
for ( var i=0, iLen=tables.length ; i<iLen ; i++ ){
var defaultCol = jQuery('th', tables[i]).index(jQuery(".dataTable-defaultSort",tables[i]));
if(defaultCol >= 0){
sorting = [ defaultCol, 'desc' ];
}else{
sorting = [12,'desc'];
}
var oTable2 = jQuery(tables[i]).dataTable({
"sDom": 'T<"clearfix">lfrt<"clearfix">ip',
"aaSorting": [ sorting ],
"bStateSave": true,
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "list.php",
"iDisplayLength": 20,
"aLengthMenu": [[20, 50, 100], [20, 50, 100]],
"sPaginationType": "full_numbers",
});
out.push( oTable2 );
}
return out;
}
$(document).ready(function() {
renderDataTable("#main_table");
$("select#myVar").change(function () {
var myVar = $(this).val();
// push data to table and refresh?
});
});
Can anyone help me out here please? Thanx in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,找到了答案,我将其发布在这里,以便任何有需要的人都可以使用它。
我发现我正在寻找的事情可以这样完成:
函数 fnReloadAjax() 不包含在 jquery.dataTables.min.js 中,但可以在这里找到它 http://www.datatables.net/plug-ins/api#fnGetHiddenNodes
感谢ShadowScripter 指出了一些方向。
OK, found the answer and I'm posting it here so anyone who needs the same can use it.
I've found that the thing I was looking for can be done like this:
The function fnReloadAjax() is not included in the jquery.dataTables.min.js, but it can be found here http://www.datatables.net/plug-ins/api#fnGetHiddenNodes
Thanks to ShadowScripter for pointing out some directions.