[英]DataTables and columnDefs Rendering Data
I am using datatables 1.10.19 and I would like to filter data based on the contents of a table cell. 我正在使用数据表1.10.19,我想根据表单元格的内容过滤数据。
I am using the columnDefs option to alter the contents of the returned data. 我正在使用columnDefs选项更改返回数据的内容。
I am using this php script to retrieve data. 我正在使用此php脚本来检索数据。
My code is; 我的代码是;
$('#example').DataTable({
processing : true,
serverSide : true,
ajax: url": '/server_processing.php',
columnDefs: [{
targets: 5, // row 6 in the html table
"render": function(data, type, row) {
if (row[5] == 0) {
data = 'rejected';
}
return data;
},
}]
});
This successfully displays a table, and rejected
in column 6 when 0
is returned from the database. 这将成功显示一个表,并在从数据库返回0
时在第6列中将其rejected
。 However datatables won't allows me to filter on the word rejected
. 但是数据表不允许我过滤rejected
的单词 。 I get No matching records found
, however I can filter on the integer 0
. 我No matching records found
,但是我可以对整数0
进行过滤。
I thought datatables was supposed to filter what was displayed in the table? 我以为datatables应该过滤表中显示的内容?
Any advice is appreciated. 任何建议表示赞赏。
You have server-side processing mode enabled ( serverSide: true
) which means that you have to perform search yourself on the server-side. 您已启用服务器端处理模式( serverSide: true
),这意味着您必须在服务器端serverSide: true
执行搜索。 This could be done manually or by using helper classes/libraries. 这可以手动完成,也可以使用帮助程序类/库来完成。
For example, for PHP use SSP helper class ( ssp.class.php
) available in DataTables distribution. 例如,对于PHP,请使用DataTables发行版中可用的SSP帮助程序类( ssp.class.php
)。 For Laravel framework, there is Laravel DataTables . 对于Laravel框架,有Laravel DataTables 。
DataTables plug-in performs the search for you only in client-side processing mode. DataTables插件仅在客户端处理模式下为您执行搜索。
很简单,我要做的就是设置这个。
serverSide: false
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.