Trying to get selected rows to output certain columns in data().toArray();
Trying to get selected rows to output certain columns in data().toArray();

I have a button that sends data to php via an ajax function. If the user Searches (filters) the table, and hits the button, a JSON array is sent to PHP. Same with if the user Selects a few rows. However, there was a bit of a processing delay that I didn't love, so I made the data().toArray(); function send out only certain columns.
var filteredData = table.columns([0,10], {filter : 'applied'} ).data().toArray(); //SELECT NAME, EMAIL COL
I got an array that looks like this:
(
[0] => Array
(
[0] => Allen, test
[1] => Anderson, Jayson
[2] => Barrett, Kayla
[3] => Bennett, Amira
)
[1] => Array
(
[0] => testallen@gmail.com
[1] => testjayson@yahoo.com
[2] => testkayla@gmail.com
[3] => testamira@hotmail.com
)
)
and everything was working great!
However, my problem lies in the 'Selected' rows now.
I want to do this, but I just get empty arrays:
var selectedData = table.columns([0,10], {selected: true} ).data().toArray(); //SELECT NAME, EMAIL COL
I tried this, but I got a Flat Array, unlike the top example:
var rows = table.rows( { selected: true } ).indexes();
var selectedData = table.cells( rows, [0,10] ).data().toArray();
I've seen answers on this question about how table.rows and table.columns dont work together, and one would have to Loop Through rows to pull columns.
Can somebody please provide an example of how I can 'Loop Through' the selected rows and pull columns 0 and 10 so that I might be able to get an array that looks like the one above?
This question has an accepted answers - jump to answer
Answers
The issue is that when selecting rows you can't use
{selected: true}
as aselector-modifier
forcolumns()
. You could if you were using Select to select columns.Instead of
columns()
you can usecells()
. You can pass arow-selector
and acolumn-selector
. Use the same technique to get the row indexes you have above. It will take two calls to thecells()
API to build the array structure you noted above. See this example:http://live.datatables.net/hepepoda/1/edit
You could use one
cells()
API call with an array ofcolumn-selector
s but that would result in a different array structure, for example:table.cells(rows, [0,10]).data().toArray();
Kevin