Get column values with DataTables API
Get column values with DataTables API
I'm trying to set up a search possibility in DataTables like on this example: http://datatables.net/examples/api/multi_filter_select.html .
My code for initializing DataTables:
var oTable = $('#relations').DataTable({
processing: true,
serverSide: true,
ajax: "php/datatables/server_processing_relations.php"
});
On the example page you see the code for creating those select search fields. The select interface is displayed when I try it, but there are no values in it. I started looking and went to a simple example to check if I can get the data.
$('#relations tfoot').find('th:nth-child(1)').each(function(i) {
console.log(oTable.column(i).data());
});
That gives me an Object but i suppose its the complete table. In Object[context][0][aoData] for example I can see all rows...
I suppose I'm using the API right by calling .DataTable instead of .datatable + there is no error when using the function column(). But still the column doesn't get selected... I must admit that I don't fully master the .each that I placed after find. But I don't know how to perform a function otherwise after find is done. Maybe there is the problem...?
Can somebody help please? Thanks in advance
This question has an accepted answers - jump to answer
Answers
You need to create the filters in
initComplete
if you are using Ajax. Otherwise the data won't have loaded by the time the filters are created (thea
in Ajax stands for asynchronous after all!).The other thing is that if you are using server-side processing, then only the data for the current page is available, and therefore the list of 'select' options will be limited. You would need to send back all of the options available in the initial data request and use that data, rather than reading from the DataTable.
Allan
Thank you Allan, that makes sense :).