unable to get position and data when more than one datatable on the page
unable to get position and data when more than one datatable on the page
I have a dynamic number of datatables on the page. If only one datatable is showing, I'm able to get the position and data using fnGetPosition and fnGetData. However, if there is more than one table on the page, I'm getting the position and data from the last table on the page only.
I think this problem has something to do with the way I'm assigning oTable. How should I do this so that I can properly identify the tables?
[code]
$(document).ready(
function() {
...other stuff
var oTable;
$('.myTable').each(function() {
var tid = $(this).attr('id');
//alert(tid);
oTable= $(this).dataTable({
bFilter: false,
sPaginationType: 'full_numbers',
bSort: true,
bJQueryUI: true,
fnDrawCallback: function(oSettings) {
},
aoColumns: [
null,
null,
null,
null,
null,
null,
null,
null,
null,
{
data: " {'E':'Letter E','F':'Letter F','G':'Letter G', 'selected':'F'}",
type: 'select',
submit: 'ok'
}
]
});
});
$('[id^="reason"]').on('change',
function(){
var aPos = oTable.fnGetPosition(this);
var selrow = oTable.fnGetData(aPos[0]);
var valu = $(this).find('select#reason').val();
alert(selrow); //THIS IS THE DATA FROM THE LAST TABLE
}
);
[/code]
I think this problem has something to do with the way I'm assigning oTable. How should I do this so that I can properly identify the tables?
[code]
$(document).ready(
function() {
...other stuff
var oTable;
$('.myTable').each(function() {
var tid = $(this).attr('id');
//alert(tid);
oTable= $(this).dataTable({
bFilter: false,
sPaginationType: 'full_numbers',
bSort: true,
bJQueryUI: true,
fnDrawCallback: function(oSettings) {
},
aoColumns: [
null,
null,
null,
null,
null,
null,
null,
null,
null,
{
data: " {'E':'Letter E','F':'Letter F','G':'Letter G', 'selected':'F'}",
type: 'select',
submit: 'ok'
}
]
});
});
$('[id^="reason"]').on('change',
function(){
var aPos = oTable.fnGetPosition(this);
var selrow = oTable.fnGetData(aPos[0]);
var valu = $(this).find('select#reason').val();
alert(selrow); //THIS IS THE DATA FROM THE LAST TABLE
}
);
[/code]
This discussion has been closed.
Replies