Retrieving Row Values Using Checkboxes
Retrieving Row Values Using Checkboxes
It's so simple, but I couldn't find it. sorry.
I'm using checkboxes.
For example, I want to get the age "15" when "TOM"s checkbox is pressed.
I want to get by the column name "AGE".
I think it will probably be written something like this
table.checkboxes.selected().colomun('AGE').value
please tell me the correct way to write
$(document).ready( function () {
let option = {
data:[
{ NAME: "TOM" , AGE: "15" },
{ NAME: "JIM" , AGE: "45" },
{ NAME: "MIKE" , AGE :"32" },
{ NAME: "BOB" , AGE: "21" }
],
columns: [
{
data: null,
defaultContent: '<input type="checkbox" name="chkbx">',
},
{ data: 'NAME' },
{ data : 'AGE' }
]
};
let table = $('#example').DataTable( option );
This question has an accepted answers - jump to answer
Answers
I updated a checkbox demo from another thread to show getting a specific column.
http://live.datatables.net/mutavegi/511/edit
I uses
rows().nodes()
with arow-selector
as a function to get the checked checkboxes. It usespluck()
to get thename
column. It optionally usestoArray()
to convert the API data set to a Javascript object.Kevin
Thank you for reply again Kevin-san!
Is it possible to get only the pressed row when the checkbox is pressed?
I was able to get the checkbox pressed event by the following method.
And also I was able to get the index of the row where the checkbox was pressed by the following method
I believe that I can achieve this by combining these elements and devising further.
Take a look at this example. You will need to get the
td
ortr
of the clicked row to pass intorow().data()
as therow-selector
. Something like this:Kevin
Thank you again Kevin-san !
I was able to solve the problem again with your help !