How to get single column from selected rows for sort() and unique()?
How to get single column from selected rows for sort() and unique()?
I want to get a list of unique values from all 'selected' rows for a single column. I can iterate over the rows using $orders.rows({selected:true}) but I really want just a single column so I can pass the data() to sort() and unique().
I thought I could do the following chain...
$orders.rows({selected:true}).columns(2).data().sort().unique()
However this just gives me data for column(2) and all rows. I think I understand why but I'm still stuck.
This question has an accepted answers - jump to answer
Answers
There is a little "trick" (or knowledge depending on how you look at it!) to making this work! First we need to keep in mind that Select allows rows, columns and cells to each be selected. So you could use
.cells( {selected: true} )
to get the selected cells - but only if cells are selected - it does not related to selected rows - they are orthogonal!So what we need to do here is get the rows that have been selected, and then use them as a selector for
cells()
along with a suitable column selector:Hope that makes sense!
Allan