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

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

patricknypatrickny Posts: 15Questions: 7Answers: 0

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

This discussion has been closed.