jquery - 当列内容为html时,jQuery Datatables过滤列
问题描述
我在要过滤的数据表中有一个列。我可以按如下定义的列进行过滤:
"columns": [
{
"data": function (data) {
return data['columnToFilter'];
}
},
];
但是,我找不到一种方法来过滤超过原始值的列,例如这个:
"columns": [
{
"data": function (data) {
return '<h1>' + data['columnToFilter'] + '</h1>';
}
}
];
如何告诉 dataTables 第二列的原始值(没有 html)是什么?
这是我进行过滤的代码:
$.fn.dataTable.ext.search.push(
function( settings, data, dataIndex ) {
// tabLocation can only be filtered if the value is returned without additional html
var tabLocation = data[0];
if ($("#myFilter").hasClass("down")) {
return true;
} else {
if (tabLocation == 0) {
return true;
}
}
}
);
$.fn.toggleText = function(t1, t2){
if (this.text() == t1) this.text(t2);
else this.text(t1);
return this;
};
解决方案
我使用的解决方案是这样的:
"columns": [
{
"data": function (data) {
return data['columnToFilter'];
},
"render": {
"display": function ( data, type, row, meta ) {
return '<h1>' + data['columnToFilter'] + '</h1>';
},
},
"bSortable": false,
},
];
推荐阅读
- c# - 我可以将 BitVector32 分成两半吗?
- scala - 如何使用可运行的片段编写 Scala 文档,类似于 mdbook?
- python - 如何使评论出现在树视图表中的行上悬停?
- java - 如何在数组中向左移动元素 int 然后在末尾添加一个数字?
- javascript - 每分钟刷新从 API 接收到的数据 React, Javascript
- api - 创建 OneDrive API 上传会话时出现 400 错误
- influxdb - InfluxDB Flux - 过滤字段匹配值的位置
- r - 为什么 as.numeric("1221008815753031681") 返回 1221008815753031680?
- python - 在 python 中运行程序时,.txt 出现未定义错误的问题
- java - Spring Boot 多(maven)模块项目找不到它的存储库——如何解决这个问题?