getting undefined value on retriving values
getting undefined value on retriving values
Aslamdot
Posts: 1Questions: 1Answers: 0
<button id="button">btn</button>
<table id="example" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>City</th>
<th>Descption</th>
<th>Devicename</th>
</tr>
</thead>
</table>
$(document).ready(function () {
table = $('#example').DataTable({
ajax: {
url: 'https://api.fda.gov/device/510k.json?search=product_code:NBW&limit=100',
dataSrc: 'results',
cache: true,
},
columns: [
{data: 'city'},
{data: 'advisory_committee_description'},
{data: 'device_name'}
],
select: true,
});
$('#example tbody').on('click', 'tr', function () {
$(this).toggleClass('selected');
});
$('#button').click(function () {
var ids = $.map(table.rows('.selected').data(), function (item) {
return item[0]
});
console.log(ids)
alert(table.rows('.selected').data()[0][0] + ' row(s) selected');
});
});
on click of a buttton on alert i should value of city but i am getting undefined value can some check on this?
Answers
You have object based data using
columns.data
. When accessing the data use object notation in stead of array notation. For examplereturn item[0]
should bereturn item.city
.Kevin