Reputation: 9678
I've succesfully set up a Datatables plugin, created a new table and filled it with content using an AJAX call:
var table= $("#mytable").DataTable({
ajax: "list.json",
columns: [
{"data": "name"},
{"data": "location"},
{"data": "date"}
]
});
The example above has output all of the items from the JSON file I am importing.
What I want is to filter the output, e.g. fill the table with only the data of those users, whose location is "England".
Datatables is an extremely powerful plugin, so I got lost on this. Any help would be appreciated.
Upvotes: 0
Views: 2889
Reputation: 58920
You have a few options:
ajax.dataSrc
option or xhr
eventUse search
or searchCols
options to define initial search, either globally or for specific column:
var table= $("#mytable").DataTable({
ajax: "list.json",
columns: [
{"data": "name"},
{"data": "location"},
{"data": "date"}
],
searchCols: [
null,
{ "search": "England" },
null
]
});
See this jsFiddle for code and demonstration.
Upvotes: 1