Get the selected value of the checkbox
Get the selected value of the checkbox
Hi,
I'm using Select and jquery-datatables-checkboxes https://github.com/gyrocode/jquery-datatables-checkboxes
I'm retriving the selected value like this
var tempContactId = table52.rows( { selected: true } ).data().pluck(2).toArray();
I'm wondering is there another way using Datatables function to get the same result, I'm wondering if there is a better way or this code is just ok?
Note I'm not using server-side process.
Thanks
This question has an accepted answers - jump to answer
Answers
That is the way to get an array of selected rows where the array contains the values in column 2. Are you trying to achieve something different?
Kevin
If column with index 2 is the column containing checkboxes, you could use:
For all other columns I thought you could use selector-modifier as shown below, however it doesn't work in my tests, could be a bug in the DataTables possibly ?
I created an example where
column().data()
doesn't work as expected, maybe Allan can take a look at it.See more articles about jQuery DataTables on gyrocode.com.
This won't work with row selection. You need to use
rows()
when selecting by rows.Kevin
Maybe then documentation is not 100% correct, since
column()
API method documentation states thatselector-modifier
can be usedfor operations which involve rows
.See more articles about jQuery DataTables on gyrocode.com.
Could be. Allan can comment on that part.
Maybe Allan's answer in this thread will help explain why it doesn't work as expected.
Kevin
It is working as expected, though possibly counter-intuitively.
By default, the Select extension will select rows - so when you use
column()
andselector-modifier
{selected: true}
, since no columns are selected, everything is returned.If you set
select.items
tocolumns
, so you select the columns, then you do get what you expect - see example here.Hope that helps make it clearer. So for you, Kevin's suggestion of
rows()
is the way to go.Colin
Hi @Colin you code example having an error, missing a semi colon...
Thanks