Get data from entire table, but only displayed columns
Get data from entire table, but only displayed columns
We've set up the option for the user to choose which columns they want to display and are now trying to figure out how to get only the data from the columns they've chosen from the entire table. So say we are returning 20 columns of data, but the user has only chosen to display 10 of them and they have 5 pages with 10 rows on each page in the datatable, I want some way to get the column headers and all 50 rows of data, showing only those 10 columns, and pass them to a web service api call to be able to export to a file. If I do something like table.data(), it returns all columns.
Answers
Figured out how to do this based on example from another site: http://nirajkvinit.blogspot.com/2013/07/exporting-and-printing-jquery-datatable.html
We were already building a dynamic array of columns(self.dataColumns) to pass to the "columns" property when initializing the datatable. I used that in conjunction with the fnGetFilteredData extension to be able to get the columns and the correct rows if it's been filtered from the datatable as they are displayed onscreen.
Here is the code for the extension which I included right after the datatable was iniitialized:
All of this gets called from a button click event:
It all works well using only JavaScript and not having to use Flash.