filter ajax.data in dataTables 1.10. Error : d.filter is not a function

filter ajax.data in dataTables 1.10. Error : d.filter is not a function

mailman_shumailman_shu Posts: 2Questions: 2Answers: 0
edited April 2016 in Free community support

I've encountered with a problem trying to filter ajax data in dataTables 1.10.
I've got a table with the data from the ajax file and <input type="search" id="extra"> which a user will use to filter rows in the third column. Right now it doesn't make any changes in the table. In the console I've got the error d.filter is not a function Obviously, the problem is hiding inside of "data": function(d). My script looks like this:

$(document).ready(function() {
    $('#example').DataTable( {
        "ajax": {
            "url": "ajax.json",
            "data": function (d) {
            return d.filter(function(i){return i[2] === $('#extra').val()});
    }
  }
    });
});

If I understand dataTables documentation correctly, function (d) must return a filtered array of arrays that stored in ajax.json.

my ajax.json (a standart example)

{
  "data": [
    [
      "Tiger Nixon",
      "System Architect",
      "Edinburgh",
      "5421",
      "2011/04/25",
      "$320,800"
    ],
    [
      "Garrett Winters",
      "Accountant",
      "Tokyo",
      "8422",
      "2011/07/25",
      "$170,750"
    ],...

Answers

  • allanallan Posts: 63,552Questions: 1Answers: 10,476 Site admin

    ajax.data controls the data sent to the server with the request. ajax.dataSrc is the property which can be used to modify the data that was returned from the server before it is given to DataTables.

    In ajax.data d is an object, which does not have a filter() method - hence the error you are seeing.

    Allan

This discussion has been closed.