I added a Datatable to a page of my Django project. This tables is supposed to show some data retrieved from a Django Rest Framework API endpoint.
Here is how a sample of the data retrieved looks like:
{
"item": "Someitem",
"Price": 120,
"Status": "Free"
},
{
"item": "SecondItem,
"Price": 90,
"Status": "Taken"
},
I want to filter these records so that only the ones with the Status set to Free are shown in the table, but i don't really know how to do that from Jquery.
Here is the code i use to load the table:
$(document).ready(function() {
var table = $('#mydb').DataTable({
"serverSide": true,
"ajax": "/myapi/?format=datatables",
"columns": [
{data: "item",
{data: "Price"},
]
});
setInterval( function () {
table.ajax.reload();
}, 10000 );
});
I tried to add an if statement to check data.Pair inside the Ajax call, but it gave me an undefined. Is there any other way to do this? Any advice is appreciated