var object = {
"Data": "A",
"Id": "1"
};
var objectB = {
"Data": "B",
"Id": "2"
};
var dataSet = [];
dataSet.push(object);
dataSet.push(objectB);
console.log(dataSet);
var table = $('#Table').DataTable({
data: dataSet,
lengthMenu: [5, 10, 15, 20, 25],
columns: [{
'data': null,
}, {
'data': 'Id',
}, {
'data': 'Data',
}, {
'data': null,
}],
"oLanguage": {
"sEmptyTable": "Error: Empty Table. Please create a new question"
},
"fnRowCallback": function(nRow, aData, iDisplayIndex) {
$("td:first", nRow).html(iDisplayIndex + 1);
return nRow;
},
'columnDefs': [{
'targets': [0],
'searchable': true,
'orderable': false
}, {
"targets": [1],
"visible": false,
"searchable": false
}, {
'targets': [-1],
'searchable': false,
'orderable': false,
'render': function(data, type, full, meta) {
return '<button type="button" class="btn btn-warning Button">Get ID</button>';
}
}],
bProcessing: true,
bStateSave: false,
bPaginate: true,
})
var rowCount = $('#QuizTb').on('order.dt search.dt', function() {
table.column(0, {
search: 'applied'
}).nodes().each(function(cell, i) {
cell.innerHTML = i + 1;
});
});
$('#Table').on('click', '.Button', function() {
var tr = $(this).closest("tr");
var data = $(this).closest("tr").find('td:eq(1)').text();
alert(data);
});