数据表服务器端个别列过滤 [英] DataTables Server Side Individual Column Filtering

查看:82
本文介绍了数据表服务器端个别列过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望有人可以帮助我。我一直在疯狂地运行这个。



我有一种情况,我加载DataTables网格(一切顺利!),一切都很好。然后我去搜索,遇到问题。在网格中填充的数据来自两个不同的数据库表(这是很好的),但是当有人执行搜索时,我无法知道去哪里并获取数据。我需要知道搜索的标准(即标题或联系)。我看到当通过默认搜索框从服务器调用搜索时,会有诸如sSearch_0之类的变量都是未设置的,这些变量是如何设置的?



是表的初始化代码:

  oTable = $('#example')。dataTable({
bJQueryUI:true,
bFilter:true,
sPaginationType:full_numbers,
bPaginate:true,
bServerSide:true,
sAjaxSource:php / tabledata.php,
aoColumnDefs:[
{bSortable:false,aTargets:[0,6,8]},
{sClass:tdCenter,aTargets:[0,1,2,3,4,5,6,7,8]}
],
fnServerData:function(sSource ,aoData,fnCallback){
aoData.push({name:userid,value:userid});
$ .getJSON(sSource,aoData,function(json){
fnCallback(json)
});
}

})



我已经研究了将数据添加到fnServerData的选项,实际使用该f或第一个初始化服务器调用,但不确定如何使用它来进行后续的服务器调用。我试图使用fnFilter,但是我看不到执行一个服务器调用更多的数据。在这一点上,除了默认搜索框之外,我还没有看到任何其他方式执行服务器调用,我看到了一些知道搜索列的方式。



可以有人在这里帮助我,指向正确的方向?

解决方案

如果您从服务器获取DataTables插件的数据,您必须将bServerSide设置为true,将sAjaxSource设置为适当的URL,如果需要执行任何回调,则理想地配置fnServerData。



如果使用服务器端处理,所有排序,筛选和分页都需要由您在服务器上处理。如果正确配置DataTables,它将在任何时候发生分页,筛选或排序事件时从服务器请求数据。



DataTables服务器端API文档



服务器端处理的PHP示例


I was hoping someone can help me with this. I have been running myself crazy with this.

I have a situation where I load the DataTables grid (awesome piece by the way!) and all is great. Then I go to search and I run into problems. The data being populated in the grid is coming from two different database tables (which is fine) but when someone executes a search I have no way of knowing where to go and get the data. I would need to know what criteria the search is about (i.e. title or contact). I see what when the search is called from the server via the default search box there are variables like "sSearch_0" which are all unset, how do those get set?

Here is the initialization code for the table:

oTable = $('#example').dataTable({
"bJQueryUI": true,
"bFilter": true,
"sPaginationType": "full_numbers",
"bPaginate " : true,
"bServerSide" : true,
"sAjaxSource" : "php/tabledata.php",
"aoColumnDefs": [
     { "bSortable": false, "aTargets": [ 0,6,8 ] },
 { "sClass": "tdCenter", "aTargets": [ 0,1,2,3,4,5,6,7,8 ] }
     ],
"fnServerData": function ( sSource, aoData, fnCallback ) {
aoData.push( { "name": "userid", "value": userid } );
$.getJSON( sSource, aoData, function (json) { 
fnCallback(json)
});
}           

});

I have looked into options for adding data to the "fnServerData " and actually use that for the first initialization server call but am unsure how to use that for a subsequent server call. I have tried to use "fnFilter" but I do not see that executing a server call for more data. At this point I do not see any other way to execute a server call besides the default search box and I see some way of knowing which column the search is for.

Can someone help me here and point me in the right direction?

解决方案

If you are getting data from the server for the DataTables plugin, you have to set bServerSide to true, set the sAjaxSource to the appropriate URL, and ideally configure fnServerData if you need to do any callbacks.

If you use server-side processing, all sorting, filtering, and paging needs to be handled by you on the server. If you configure DataTables correctly, it will request data from the server any time there is a paging, filtering, or sorting event.

DataTables server-side API documentation

PHP example of server-side processing

这篇关于数据表服务器端个别列过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆