DataTable or dataTable but not both ?
DataTable or dataTable but not both ?
I'm trying to code my own filter for Datatables, but I'm having an error. My table is defined like this:
var table = $('#table_id').DataTable({ ... });
And I want to count the number of rows like this:
var rowCount = table.fnGetData().length;
However, I get a javascript error which says that fnGetData() is not a function. I've managed to fix this by changing DataTable to dataTable in the object constructor... However, if I do this, then this line stops working:
var idx = table.column(2).data();
And the error states that column() is not a function.
So, what am I doing wrong? It seems I can't use fnGetData() and column() at the same time because one requires DataTable in the object constructor and the other requires dataTable... Is this a bug?
Ok, I found that I was using an old API and row counting should be like this:
table.data().length
Problem solved.
This question has an accepted answers - jump to answer
Answers
Correct - and you wouldn't want to. Use
data()
if you want the data for the table, rather than the old fnGetData method. The full current API reference is available here: https://datatables.net/reference/api .Allan
Thank you very much. :)