Using DataTables 1.10.19
I have a MySQL DB, the structure is as follows;
+------+-----------------+----------+----------+
| name | email | status | complete |
+------+-----------------+----------+----------+
| Joe | me@example.com | 1 |1 |
+------+-----------------+----------+----------+
| Jim | you@example.com | 1 |0 |
+------+-----------------+----------+----------+
| Sara | him@example.com | 0 |0 |
+------+-----------------+----------+----------+
I'm using this script to retrieve data from the db.
My datatable filter works as expected when searching for 0 and 1, but this filters both status and complete columns. I would like to search for the words active / inactive and complete / incomplete instead of 1 and 0.
I'm using the datatables columns.render option to render a custom output in these columns based on the row results.
My DataTable code is;
$('#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`;
}
}
}, ]
});
The results.php file returns the following;
"data": [
[
"Joe",
"me@example.com ",
"1",
"1",
],
[
"Jim",
"you@example.com ",
"1",
"0",
],
[
"Sara",
"him@example.com ",
"0",
"0",
],
]
My front end HTML table looks like this;
+------+-----------------+----------+------------+
| name | email | status |complete |
+------+-----------------+----------+------------+
| Joe | me@example.com | active |complete |
+------+-----------------+----------+------------+
| Jim | you@example.com | active |incomplete |
+------+-----------------+----------+------------+
| Sara | him@example.com | inactive |incomplete |
+------+-----------------+----------+------------+
Currently the filter seems to filter the db int value and not the cell text.
How can I search for the words instead of 0 and 1.