DataTables Filter Cell Content not DB Value












5















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.










share|improve this question





























    5















    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.










    share|improve this question



























      5












      5








      5








      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.










      share|improve this question
















      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.







      javascript jquery mysql datatables






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 15 '18 at 15:26







      TheOrdinaryGeek

















      asked Nov 14 '18 at 16:39









      TheOrdinaryGeekTheOrdinaryGeek

      823215




      823215
























          1 Answer
          1






          active

          oldest

          votes


















          0














          The below seems to work just fine. Typing "Inactive" shows only Sara as a result. What are you doing differently?



          Edit: I have updated the snippet to match your latest code. It seems you are passing down an array of arrays for your data, so I am surprised that your table is even initializing, as the data options are not valid in that case (how can data select the "name" attribute if it doesn't exist in your result set? It should be the array index). After updating the data options to the array index, the table searches your rendered table correctly. Searching "Incomplete" returns Jim/ Sara, while searching "Inactive" returns Sara.






          $(document).ready(function() {
          var data = getDummyData();
          $('#example').dataTable({
          "data": data,
          "columns": [{
          "data": 0
          },
          {
          "data": 1
          },
          {
          "data": 2,
          "render": function(data, type, row, meta) {
          // row[2] returns an int of 0 or 1 from the db. inactive/active
          if (data == 0) {
          return `inactive`;
          }
          if (data == 1) {
          return `active`;
          }
          }
          },
          {
          "data": 3,
          "render": function(data, type, row, meta) {
          // row[2] returns an int of 0 or 1 from the db. incomplete/complete
          if (data == 0) {
          return `incomplete`;
          }
          if (data == 1) {
          return `complete`;
          }
          }
          },
          ]
          });
          });

          function getDummyData() {
          return [
          [
          "Joe",
          "me@example.com ",
          "1",
          "1",
          ],
          [
          "Jim",
          "you@example.com ",
          "1",
          "0",
          ],
          [
          "Sara",
          "him@example.com ",
          "0",
          "0",
          ],
          ]
          }

          <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

          <link href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.css" rel="stylesheet" type="text/css" />
          <script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.js"></script>

          <table id="example">
          <thead>
          <tr>
          <th>name</th>
          <th>email</th>
          <th>status</th>
          <th>complete</th>
          </tr>
          </thead>
          <tbody>
          </tbody>
          </table>








          share|improve this answer


























          • I've updated my response. After integrating your data format, I am still able to search the data correctly. The only differences now is that I commented out data options because they are not valid with your result set, and that I am using static data, rather than ajax sourced data.

            – Rich
            Nov 15 '18 at 14:44











          • If you are still having issues, try testing it with static data so we can eliminate the difference of the data source as the issue.

            – Rich
            Nov 15 '18 at 14:46











          • Thanks for the help. I'm going round in circles, I'm using this script to retrieve db results if that helps github.com/DataTables/DataTablesSrc/blob/master/examples/…

            – TheOrdinaryGeek
            Nov 15 '18 at 15:26











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53304941%2fdatatables-filter-cell-content-not-db-value%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          The below seems to work just fine. Typing "Inactive" shows only Sara as a result. What are you doing differently?



          Edit: I have updated the snippet to match your latest code. It seems you are passing down an array of arrays for your data, so I am surprised that your table is even initializing, as the data options are not valid in that case (how can data select the "name" attribute if it doesn't exist in your result set? It should be the array index). After updating the data options to the array index, the table searches your rendered table correctly. Searching "Incomplete" returns Jim/ Sara, while searching "Inactive" returns Sara.






          $(document).ready(function() {
          var data = getDummyData();
          $('#example').dataTable({
          "data": data,
          "columns": [{
          "data": 0
          },
          {
          "data": 1
          },
          {
          "data": 2,
          "render": function(data, type, row, meta) {
          // row[2] returns an int of 0 or 1 from the db. inactive/active
          if (data == 0) {
          return `inactive`;
          }
          if (data == 1) {
          return `active`;
          }
          }
          },
          {
          "data": 3,
          "render": function(data, type, row, meta) {
          // row[2] returns an int of 0 or 1 from the db. incomplete/complete
          if (data == 0) {
          return `incomplete`;
          }
          if (data == 1) {
          return `complete`;
          }
          }
          },
          ]
          });
          });

          function getDummyData() {
          return [
          [
          "Joe",
          "me@example.com ",
          "1",
          "1",
          ],
          [
          "Jim",
          "you@example.com ",
          "1",
          "0",
          ],
          [
          "Sara",
          "him@example.com ",
          "0",
          "0",
          ],
          ]
          }

          <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

          <link href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.css" rel="stylesheet" type="text/css" />
          <script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.js"></script>

          <table id="example">
          <thead>
          <tr>
          <th>name</th>
          <th>email</th>
          <th>status</th>
          <th>complete</th>
          </tr>
          </thead>
          <tbody>
          </tbody>
          </table>








          share|improve this answer


























          • I've updated my response. After integrating your data format, I am still able to search the data correctly. The only differences now is that I commented out data options because they are not valid with your result set, and that I am using static data, rather than ajax sourced data.

            – Rich
            Nov 15 '18 at 14:44











          • If you are still having issues, try testing it with static data so we can eliminate the difference of the data source as the issue.

            – Rich
            Nov 15 '18 at 14:46











          • Thanks for the help. I'm going round in circles, I'm using this script to retrieve db results if that helps github.com/DataTables/DataTablesSrc/blob/master/examples/…

            – TheOrdinaryGeek
            Nov 15 '18 at 15:26
















          0














          The below seems to work just fine. Typing "Inactive" shows only Sara as a result. What are you doing differently?



          Edit: I have updated the snippet to match your latest code. It seems you are passing down an array of arrays for your data, so I am surprised that your table is even initializing, as the data options are not valid in that case (how can data select the "name" attribute if it doesn't exist in your result set? It should be the array index). After updating the data options to the array index, the table searches your rendered table correctly. Searching "Incomplete" returns Jim/ Sara, while searching "Inactive" returns Sara.






          $(document).ready(function() {
          var data = getDummyData();
          $('#example').dataTable({
          "data": data,
          "columns": [{
          "data": 0
          },
          {
          "data": 1
          },
          {
          "data": 2,
          "render": function(data, type, row, meta) {
          // row[2] returns an int of 0 or 1 from the db. inactive/active
          if (data == 0) {
          return `inactive`;
          }
          if (data == 1) {
          return `active`;
          }
          }
          },
          {
          "data": 3,
          "render": function(data, type, row, meta) {
          // row[2] returns an int of 0 or 1 from the db. incomplete/complete
          if (data == 0) {
          return `incomplete`;
          }
          if (data == 1) {
          return `complete`;
          }
          }
          },
          ]
          });
          });

          function getDummyData() {
          return [
          [
          "Joe",
          "me@example.com ",
          "1",
          "1",
          ],
          [
          "Jim",
          "you@example.com ",
          "1",
          "0",
          ],
          [
          "Sara",
          "him@example.com ",
          "0",
          "0",
          ],
          ]
          }

          <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

          <link href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.css" rel="stylesheet" type="text/css" />
          <script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.js"></script>

          <table id="example">
          <thead>
          <tr>
          <th>name</th>
          <th>email</th>
          <th>status</th>
          <th>complete</th>
          </tr>
          </thead>
          <tbody>
          </tbody>
          </table>








          share|improve this answer


























          • I've updated my response. After integrating your data format, I am still able to search the data correctly. The only differences now is that I commented out data options because they are not valid with your result set, and that I am using static data, rather than ajax sourced data.

            – Rich
            Nov 15 '18 at 14:44











          • If you are still having issues, try testing it with static data so we can eliminate the difference of the data source as the issue.

            – Rich
            Nov 15 '18 at 14:46











          • Thanks for the help. I'm going round in circles, I'm using this script to retrieve db results if that helps github.com/DataTables/DataTablesSrc/blob/master/examples/…

            – TheOrdinaryGeek
            Nov 15 '18 at 15:26














          0












          0








          0







          The below seems to work just fine. Typing "Inactive" shows only Sara as a result. What are you doing differently?



          Edit: I have updated the snippet to match your latest code. It seems you are passing down an array of arrays for your data, so I am surprised that your table is even initializing, as the data options are not valid in that case (how can data select the "name" attribute if it doesn't exist in your result set? It should be the array index). After updating the data options to the array index, the table searches your rendered table correctly. Searching "Incomplete" returns Jim/ Sara, while searching "Inactive" returns Sara.






          $(document).ready(function() {
          var data = getDummyData();
          $('#example').dataTable({
          "data": data,
          "columns": [{
          "data": 0
          },
          {
          "data": 1
          },
          {
          "data": 2,
          "render": function(data, type, row, meta) {
          // row[2] returns an int of 0 or 1 from the db. inactive/active
          if (data == 0) {
          return `inactive`;
          }
          if (data == 1) {
          return `active`;
          }
          }
          },
          {
          "data": 3,
          "render": function(data, type, row, meta) {
          // row[2] returns an int of 0 or 1 from the db. incomplete/complete
          if (data == 0) {
          return `incomplete`;
          }
          if (data == 1) {
          return `complete`;
          }
          }
          },
          ]
          });
          });

          function getDummyData() {
          return [
          [
          "Joe",
          "me@example.com ",
          "1",
          "1",
          ],
          [
          "Jim",
          "you@example.com ",
          "1",
          "0",
          ],
          [
          "Sara",
          "him@example.com ",
          "0",
          "0",
          ],
          ]
          }

          <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

          <link href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.css" rel="stylesheet" type="text/css" />
          <script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.js"></script>

          <table id="example">
          <thead>
          <tr>
          <th>name</th>
          <th>email</th>
          <th>status</th>
          <th>complete</th>
          </tr>
          </thead>
          <tbody>
          </tbody>
          </table>








          share|improve this answer















          The below seems to work just fine. Typing "Inactive" shows only Sara as a result. What are you doing differently?



          Edit: I have updated the snippet to match your latest code. It seems you are passing down an array of arrays for your data, so I am surprised that your table is even initializing, as the data options are not valid in that case (how can data select the "name" attribute if it doesn't exist in your result set? It should be the array index). After updating the data options to the array index, the table searches your rendered table correctly. Searching "Incomplete" returns Jim/ Sara, while searching "Inactive" returns Sara.






          $(document).ready(function() {
          var data = getDummyData();
          $('#example').dataTable({
          "data": data,
          "columns": [{
          "data": 0
          },
          {
          "data": 1
          },
          {
          "data": 2,
          "render": function(data, type, row, meta) {
          // row[2] returns an int of 0 or 1 from the db. inactive/active
          if (data == 0) {
          return `inactive`;
          }
          if (data == 1) {
          return `active`;
          }
          }
          },
          {
          "data": 3,
          "render": function(data, type, row, meta) {
          // row[2] returns an int of 0 or 1 from the db. incomplete/complete
          if (data == 0) {
          return `incomplete`;
          }
          if (data == 1) {
          return `complete`;
          }
          }
          },
          ]
          });
          });

          function getDummyData() {
          return [
          [
          "Joe",
          "me@example.com ",
          "1",
          "1",
          ],
          [
          "Jim",
          "you@example.com ",
          "1",
          "0",
          ],
          [
          "Sara",
          "him@example.com ",
          "0",
          "0",
          ],
          ]
          }

          <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

          <link href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.css" rel="stylesheet" type="text/css" />
          <script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.js"></script>

          <table id="example">
          <thead>
          <tr>
          <th>name</th>
          <th>email</th>
          <th>status</th>
          <th>complete</th>
          </tr>
          </thead>
          <tbody>
          </tbody>
          </table>








          $(document).ready(function() {
          var data = getDummyData();
          $('#example').dataTable({
          "data": data,
          "columns": [{
          "data": 0
          },
          {
          "data": 1
          },
          {
          "data": 2,
          "render": function(data, type, row, meta) {
          // row[2] returns an int of 0 or 1 from the db. inactive/active
          if (data == 0) {
          return `inactive`;
          }
          if (data == 1) {
          return `active`;
          }
          }
          },
          {
          "data": 3,
          "render": function(data, type, row, meta) {
          // row[2] returns an int of 0 or 1 from the db. incomplete/complete
          if (data == 0) {
          return `incomplete`;
          }
          if (data == 1) {
          return `complete`;
          }
          }
          },
          ]
          });
          });

          function getDummyData() {
          return [
          [
          "Joe",
          "me@example.com ",
          "1",
          "1",
          ],
          [
          "Jim",
          "you@example.com ",
          "1",
          "0",
          ],
          [
          "Sara",
          "him@example.com ",
          "0",
          "0",
          ],
          ]
          }

          <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

          <link href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.css" rel="stylesheet" type="text/css" />
          <script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.js"></script>

          <table id="example">
          <thead>
          <tr>
          <th>name</th>
          <th>email</th>
          <th>status</th>
          <th>complete</th>
          </tr>
          </thead>
          <tbody>
          </tbody>
          </table>





          $(document).ready(function() {
          var data = getDummyData();
          $('#example').dataTable({
          "data": data,
          "columns": [{
          "data": 0
          },
          {
          "data": 1
          },
          {
          "data": 2,
          "render": function(data, type, row, meta) {
          // row[2] returns an int of 0 or 1 from the db. inactive/active
          if (data == 0) {
          return `inactive`;
          }
          if (data == 1) {
          return `active`;
          }
          }
          },
          {
          "data": 3,
          "render": function(data, type, row, meta) {
          // row[2] returns an int of 0 or 1 from the db. incomplete/complete
          if (data == 0) {
          return `incomplete`;
          }
          if (data == 1) {
          return `complete`;
          }
          }
          },
          ]
          });
          });

          function getDummyData() {
          return [
          [
          "Joe",
          "me@example.com ",
          "1",
          "1",
          ],
          [
          "Jim",
          "you@example.com ",
          "1",
          "0",
          ],
          [
          "Sara",
          "him@example.com ",
          "0",
          "0",
          ],
          ]
          }

          <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

          <link href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.css" rel="stylesheet" type="text/css" />
          <script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.js"></script>

          <table id="example">
          <thead>
          <tr>
          <th>name</th>
          <th>email</th>
          <th>status</th>
          <th>complete</th>
          </tr>
          </thead>
          <tbody>
          </tbody>
          </table>






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 15 '18 at 14:48

























          answered Nov 14 '18 at 17:29









          RichRich

          650314




          650314













          • I've updated my response. After integrating your data format, I am still able to search the data correctly. The only differences now is that I commented out data options because they are not valid with your result set, and that I am using static data, rather than ajax sourced data.

            – Rich
            Nov 15 '18 at 14:44











          • If you are still having issues, try testing it with static data so we can eliminate the difference of the data source as the issue.

            – Rich
            Nov 15 '18 at 14:46











          • Thanks for the help. I'm going round in circles, I'm using this script to retrieve db results if that helps github.com/DataTables/DataTablesSrc/blob/master/examples/…

            – TheOrdinaryGeek
            Nov 15 '18 at 15:26



















          • I've updated my response. After integrating your data format, I am still able to search the data correctly. The only differences now is that I commented out data options because they are not valid with your result set, and that I am using static data, rather than ajax sourced data.

            – Rich
            Nov 15 '18 at 14:44











          • If you are still having issues, try testing it with static data so we can eliminate the difference of the data source as the issue.

            – Rich
            Nov 15 '18 at 14:46











          • Thanks for the help. I'm going round in circles, I'm using this script to retrieve db results if that helps github.com/DataTables/DataTablesSrc/blob/master/examples/…

            – TheOrdinaryGeek
            Nov 15 '18 at 15:26

















          I've updated my response. After integrating your data format, I am still able to search the data correctly. The only differences now is that I commented out data options because they are not valid with your result set, and that I am using static data, rather than ajax sourced data.

          – Rich
          Nov 15 '18 at 14:44





          I've updated my response. After integrating your data format, I am still able to search the data correctly. The only differences now is that I commented out data options because they are not valid with your result set, and that I am using static data, rather than ajax sourced data.

          – Rich
          Nov 15 '18 at 14:44













          If you are still having issues, try testing it with static data so we can eliminate the difference of the data source as the issue.

          – Rich
          Nov 15 '18 at 14:46





          If you are still having issues, try testing it with static data so we can eliminate the difference of the data source as the issue.

          – Rich
          Nov 15 '18 at 14:46













          Thanks for the help. I'm going round in circles, I'm using this script to retrieve db results if that helps github.com/DataTables/DataTablesSrc/blob/master/examples/…

          – TheOrdinaryGeek
          Nov 15 '18 at 15:26





          Thanks for the help. I'm going round in circles, I'm using this script to retrieve db results if that helps github.com/DataTables/DataTablesSrc/blob/master/examples/…

          – TheOrdinaryGeek
          Nov 15 '18 at 15:26




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53304941%2fdatatables-filter-cell-content-not-db-value%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Bressuire

          Vorschmack

          Quarantine