我正在为IgnitedDatatables使用DataTables(CodeIgniter库)。生成表没有问题,但如果我搜索/过滤它,一次只能过滤一列。如果我将“bServerSide”设置为false它可以工作,但后来我失去了服务器端功能。
在示例中,这个正在工作: http://datatables.net/release-datatables/examples/ajax/custom_data_property.html
虽然这不是(服务器端): http://datatables.net/release-datatables/examples/data_sources/server_side.html
运行服务器端时无法实现这一点吗?
这是我的JSON响应(缩短并替换了数据):
{"sEcho":0,"iTotalRecords":45438,"iTotalDisplayRecords":45438,"aaData":[["abc","12345","example@example.com","","","2010-01-27 22:31:10","Edit<\/a> Delete<\/a>"],["abc2"," test123","test@test.com","","","2008-06-15 22:09:33","Edit<\/a> Delete<\/a>"]],"sColumns":"fname,lname,email,phone,cellphone,created,edit"}
JavaScript代码:
$("#members").dataTable( {
"bProcessing": true,
"bServerSide": true,
'sAjaxSource': '<?php echo base_url();?>members/listener',
"fnServerData": function ( sSource, aoData, fnCallback ) {
$.ajax( {
"dataType": 'json',
"type": 'POST',
"url": sSource,
"data": aoData,
"success": fnCallback
} );
},
"bLengthChange": false,
"aaSorting": [[ 0, "asc" ]],
"iDisplayLength": 15,
"sPaginationType": "full_numbers",
"bAutoWidth": false,
"aoColumnDefs": [
{ "sName": "fname", "aTargets": [ 0 ] },
{ "sName": "lname", "aTargets": [ 1 ] },
{ "sName": "email", "aTargets": [ 2 ] },
{ "sName": "phone", "sWidth": "80px", "aTargets": [ 3 ] },
{ "sName": "cellphone", "sWidth": "100px", "aTargets": [ 4 ] },
{ "sName": "created", "sWidth": "120px", "aTargets": [ 5 ] },
{ "bSortable": false, "sName": "edit", "sWidth": "115px", "aTargets": [ 6 ] }
]
});
谢谢!
答案 0 :(得分:1)
嗯,如果您过滤服务器端的问题是您正在通过SQL查询进行过滤,这就是您发布的example上写的内容;
- 过滤
- 注意这与内置的DataTables过滤不匹配
- 在任何字段上逐字逐句。可以在这里做,但关注效率
- 在非常大的表上,MySQL的正则表达式功能非常有限
基本上你可以做你想做的事(正则表达式匹配所有列)但它会杀死性能服务器端。
我通常做的是为每列提供一个过滤器,我需要过滤。