Adding button using fnRender and getting oObj.aData[0] bugs
Adding button using fnRender and getting oObj.aData[0] bugs
tknop
Posts: 14Questions: 0Answers: 0
Hi,
I'm having a hard time figuring out where is the bug in the code below :
I have a table and i add in the first column a button, as well as in the last two columns. However, it seems that the oObj.aData[1] varies with time, which is totally beyond understanding.
As you can see in the code, the first column i process uses oObj.aData[0] in the fnRender function, and oObj.aData[0] corresponds to the id from the data.
Further, i process another column, but i can't reach the id from the data : oObj.aData[0] corresponds now to the code of the button of the first column i've processed, while oObj.aData[1] corresponds to the field "day" of the data, and not "id"...
Here are the debug links : http://debug.datatables.net/eyefah
Thanks in advance for you help !
[code]
Select
Id
Day
Begin
AM/PM
End
AM/PM
Title
Details
isNow
Edit
Delete
$(function() {
var oTable;
var editor;
f();
$.extend( $.fn.dataTableExt.oStdClasses, {
'sWrapper': 'dataTables_wrapper form-inline'
});
// Set the classes that TableTools uses to something suitable for Bootstrap
$.extend( true, $.fn.DataTable.TableTools.classes, {
'container': 'btn-group',
'buttons': {
'normal': 'btn',
'disabled': 'disabled'
},
'collection': {
'container': 'DTTT_dropdown dropdown-menu',
'buttons': {
'normal': '',
'disabled': 'disabled'
}
}
} );
// Have the collection use a bootstrap compatible dropdown
$.extend( true, $.fn.DataTable.TableTools.DEFAULTS.oTags, {
'collection': {
'container': 'ul',
'button': 'li',
'liner': 'a'
}
});
});
var aj = function getSchedulesConfig(day){
$.ajax({
url: 'pages/administration/getSchedulesConfigJSON.php',
type: 'POST',
data: {value: day},
dataType:'json',
success: function(data){
idTable = '';
oTable = $('#datatableDay1').dataTable({
//'sDom': '<\'row-fluid\'<\'span6\'l><\'span6\'fT>r>t<\'row-fluid\'<\'span6\'i><\'span6\'p>>',
'fnCreatedRow': function( nRow, aData, iDataIndex ) {
if(aData[8] == 1){
$('td', nRow).css('background-color', '#dff0d8');
} else {
$('td', nRow).css('background-color', '#fcf8e3');
}
},
"aaSorting": [[ 1, "asc" ]],
"aoColumns": [
{
"mDataProp": null,
"sClass": "selecting",
"bSortable" : false,
"sDefaultContent": '
I'm having a hard time figuring out where is the bug in the code below :
I have a table and i add in the first column a button, as well as in the last two columns. However, it seems that the oObj.aData[1] varies with time, which is totally beyond understanding.
As you can see in the code, the first column i process uses oObj.aData[0] in the fnRender function, and oObj.aData[0] corresponds to the id from the data.
Further, i process another column, but i can't reach the id from the data : oObj.aData[0] corresponds now to the code of the button of the first column i've processed, while oObj.aData[1] corresponds to the field "day" of the data, and not "id"...
Here are the debug links : http://debug.datatables.net/eyefah
Thanks in advance for you help !
[code]
Select
Id
Day
Begin
AM/PM
End
AM/PM
Title
Details
isNow
Edit
Delete
$(function() {
var oTable;
var editor;
f();
$.extend( $.fn.dataTableExt.oStdClasses, {
'sWrapper': 'dataTables_wrapper form-inline'
});
// Set the classes that TableTools uses to something suitable for Bootstrap
$.extend( true, $.fn.DataTable.TableTools.classes, {
'container': 'btn-group',
'buttons': {
'normal': 'btn',
'disabled': 'disabled'
},
'collection': {
'container': 'DTTT_dropdown dropdown-menu',
'buttons': {
'normal': '',
'disabled': 'disabled'
}
}
} );
// Have the collection use a bootstrap compatible dropdown
$.extend( true, $.fn.DataTable.TableTools.DEFAULTS.oTags, {
'collection': {
'container': 'ul',
'button': 'li',
'liner': 'a'
}
});
});
var aj = function getSchedulesConfig(day){
$.ajax({
url: 'pages/administration/getSchedulesConfigJSON.php',
type: 'POST',
data: {value: day},
dataType:'json',
success: function(data){
idTable = '';
oTable = $('#datatableDay1').dataTable({
//'sDom': '<\'row-fluid\'<\'span6\'l><\'span6\'fT>r>t<\'row-fluid\'<\'span6\'i><\'span6\'p>>',
'fnCreatedRow': function( nRow, aData, iDataIndex ) {
if(aData[8] == 1){
$('td', nRow).css('background-color', '#dff0d8');
} else {
$('td', nRow).css('background-color', '#fcf8e3');
}
},
"aaSorting": [[ 1, "asc" ]],
"aoColumns": [
{
"mDataProp": null,
"sClass": "selecting",
"bSortable" : false,
"sDefaultContent": '
This discussion has been closed.
Replies
> However, it seems that the oObj.aData[1] varies with time, which is totally beyond understanding.
The value you return from fnRender overwrites the original value. This is one of the many reasons you will want to not use it!
Use mRender instead.
Allan