Equivalent of fnGetData() for filtered/searched rows
Equivalent of fnGetData() for filtered/searched rows
Before you write this off as a duplicate of many other questions (including: https://datatables.net/forums/discussion/10321/fngetdata-of-visible-rows-only), I need to point out that:
$(...).dataTable().fnGetData();
and
$(...).dataTable()._filter('tr', { "filter":"applied" });
are NOT equivalent (beyond just showing un-/filtered data).
Using the Chrome console window to display results, the fn method returns an object with only the data Objects, length, and proto 'fields' whereas the _ method returns the data Objects, as well as $, ajax, cell, [...] definitions.
I'm trying to post results to an API, and using JSON.stringify(results) includes all of the unwanted properties of the _ method results :(. Am I stuck doing what wazza did in his ad-hock solution before Allan showed the _ method?
This question has an accepted answers - jump to answer
Answers
Use
rows().data()
for this - its far more flexible than the legacyfnGetData
or_
methods.What you would use is:
Note also the use of
toArray()
to convert the DataTables API instance to an array. That wayJSON.stingify()
or whatever serialisation you use will note pick up all the DataTables API methods etc.Allan
I was unaware that those fn and _ methods methods were legacy, that's how I was basing my searches :(.
Work perfectly, thanks!