+------+-----------------+----------+----------+
| name | email | status | complete |
+------+-----------------+----------+----------+
| Joe | me@example.com | 1 |1 |
+------+-----------------+----------+----------+
| Jim | you@example.com | 1 |0 |
+------+-----------------+----------+----------+
| Sara | him@example.com | 0 |0 |
+------+-----------------+----------+----------+
我在用
this script
从数据库中检索数据。
0
和
1
,但这个过滤器
二者都
status
complete
柱。我想找
话
active
inactive
和
完成
incomplete
而不是
1
.
我在用数据表
columns.render
我的数据表代码是;
$('#example').dataTable({
"ajaxSource": "results.php", // output below
"columns": [{
"data": "name"
}, {
"data": "email"
}, {
"data": "status",
"render": function(data, type, row, meta) {
// row[2] returns an int of 0 or 1 from the db. inactive/active
if (row[2] == 0) {
return `inactive`;
}
if (row[2] == 1) {
return `active`;
}
}
}, {
"data": "complete",
"render": function(data, type, row, meta) {
// row[2] returns an int of 0 or 1 from the db. incomplete/complete
if (row[3] == 0) {
return `incomplete`;
}
if (row[3] == 1) {
return `complete`;
}
}
}, ]
});
results.php
文件返回以下内容:;
"data": [
[
"Joe",
"me@example.com ",
"1",
"1",
],
[
"Jim",
"you@example.com ",
"1",
"0",
],
[
"Sara",
"him@example.com ",
"0",
"0",
],
]
我的前端HTML表如下所示;
+------+-----------------+----------+------------+
| name | email | status |complete |
+------+-----------------+----------+------------+
| Joe | me@example.com | active |complete |
+------+-----------------+----------+------------+
| Jim | you@example.com | active |incomplete |
+------+-----------------+----------+------------+
| Sara | him@example.com | inactive |incomplete |
+------+-----------------+----------+------------+
目前过滤器似乎过滤数据库
int
值而不是单元格文本。
0
和
.