Change a row attribute after json
Change a row attribute after json
I'm slightly new to datatables in jquery. I have some datatables on my asp.net page and each one holds previous table's related information. I have some ajax responses that changes second table's content upon selection on table one. But I also need the specific attribute (a row's attribute) that I defined during initialization of table. After clearing and adding rows on datatable, I've no longer access the attribute of table row, because datatables script destroys it.
Here are the codes:
$(document).ready(function () {
var table0 = $('#sample_0').DataTable({
select:true
});
$('#sample_0 tbody').on('click', 'tr', function () {
var rix = $(this).attr('id');
var tempScrollTop = $(window).scrollTop();
getAMDs(rix, tempScrollTop);
});
var table1 = $('#sample_1').DataTable({
select: true
});
});
This is the ajax function, which triggered by click on a row:
function getAMDs(ptRegId, scrollValue) {
$.ajax({
url: '/Academics/AMX.aspx/GetAMDs',
method: 'post',
contentType: 'application/json',
data: '{r_id:' + ptRegId + '}',
dataType: 'json',
success: function (data) {
$('#sample_1').dataTable().fnClearTable();
var table = $('#sample_1').dataTable();
var str = data.d;
var strArr = str.split('&');
var cc = 0;
$.each(strArr, function (value, text) {
cc++;
});
for (var i = 0; i < cc - 1; i++) {
var scnArr = strArr[i].split(',');
table.fnAddData([scnArr[0], scnArr[1], scnArr[2], scnArr[3], scnArr[4], scnArr[5]]);
//here i need to define row's attribute (eg. id)
}
},
error: function (error) {
alert(error);
}
});
}
Appreciate for help.
Answers
We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin