Title: How to get data values of checked rows of DataTables
Tags: javascript;jquery;datatables
Question: I have a DataTables with a checkbox column on the 1st column of the DataTables, I need to get the data value of checked row, so for example:
checkBox  simsPid  ICCID  IMEI
--------  -------  -----  ----
1     98789  AABBCC
x        2     18729  A3B4C5
I need to get the data values of checked row (in my use case above, I need to get simsPid, ICCID, and IMEI)
I have tried codes below, I have got checked rows but I don't have an idea on how to get the value?
I need advice.
$('#sims').DataTable({
destroy: true,
responsive: true,
info: false,
autoWidth: false,
filter: true,
lengthChange: false,
paging: false,
searching: true,
order: [1, 'asc'],
ajax: {
url: '@Models.AppSettings.Path.Deployment' + '/SIM/List/',
dataSrc: ''
},
columns: [
{
'data': null,
'defaultContent': '',
'targets': 0,
'checkboxes': {
'selectRow': true
}
},
{ data: 'simsPid', visible: false },
{ data: 'iccid', className: 'text-left', width: '10%', responsivePriority: 1 },
{ data: 'imei', className: 'text-left', orderable: true, width: '10%', responsivePriority: 2 }
],
dom: '<&quot;card-header border-bottom p-1&quot;<&quot;head-label&quot;&gt;<&quot;dt-action-buttons text-end&quot;B&gt;&gt;<&quot;d-flex justify-content-between align-items-center mx-0 row&quot;<&quot;col-sm-12 col-md-6&quot;l&gt;<&quot;col-sm-12 col-md-6&quot;f&gt;&gt;t<&quot;d-flex justify-content-between mx-0 row&quot;<&quot;col-sm-12 col-md-6&quot;i&gt;<&quot;col-sm-12 col-md-6&quot;p&gt;&gt;',
buttons: [
{
text: 'Set Status',
className: 'btn btn-outline-warning',
action: function(e, dt, node, config) {
var client_table = $('#sims').dataTable();
var rows = $(client_table.$('input[type=&quot;checkbox&quot;]').map(function() {
return $(this).prop(&quot;checked&quot;) ? $(this).closest('tr') : null;
}));
// here I got the rows, but I don't know how to get the value of simsPid. iccid, and imei
$.each(rows, function(index, rowId) {

});
}
},
{
text: 'Discard',
className: 'btn btn-outline-secondary',
action: function(e, dt, node, config) {

}
}
]
});
})
Comment: Have you checked this question? https://stackoverflow.com/questions/29191760/jquery-datatables-getting-selected-row-values. Shows how to get the selected rows.

Comment: its simple, just enable the use of `data-*` attribute and u make a function for the checkbox to get the data by the `data-*` attribute

Comment: yes, but it's bit different with my issue, they use .selected and neither mine, actually I already got the number of checked but the problem is I don't know how to get the data values of the checked items.



{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 0, 'CommentCount': 3, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2022:00:08/09/22', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<javascript><jquery><datatables>', 'Title': 'How to get data values of checked rows of DataTables', 'ViewCount': 47, 'id': 73288496, 'user_AboutMe': None, 'user_AccountId': 22673146.0, 'user_DisplayName': 'Dev ', 'user_Reputation': 61.0, 'user_Views': 11.0, 'user_id': 16844607.0}}