aoColumns: does not match known number of columns
aoColumns: does not match known number of columns
I am using aoColumns to add an additional column to each row so I can add a edit/delete feature. But keep getting:
DataTables warning (table id = 'sortable'): Added data (size 6) does not match known number of columns (7). I can not figure out why this is happenning..
[code]
$.fn.dataTableExt.oStdClasses.sWrapper = 'no-margin last-child';
$.fn.dataTableExt.oStdClasses.sInfo = 'message no-margin';
$.fn.dataTableExt.oStdClasses.sLength = 'float-left';
$.fn.dataTableExt.oStdClasses.sFilter = 'float-right';
$.fn.dataTableExt.oStdClasses.sPaging = 'sub-hover paging_';
$.fn.dataTableExt.oStdClasses.sPagePrevEnabled = 'control-prev';
$.fn.dataTableExt.oStdClasses.sPagePrevDisabled = 'control-prev disabled';
$.fn.dataTableExt.oStdClasses.sPageNextEnabled = 'control-next';
$.fn.dataTableExt.oStdClasses.sPageNextDisabled = 'control-next disabled';
$.fn.dataTableExt.oStdClasses.sPageFirst = 'control-first';
$.fn.dataTableExt.oStdClasses.sPagePrevious = 'control-prev';
$.fn.dataTableExt.oStdClasses.sPageNext = 'control-next';
$.fn.dataTableExt.oStdClasses.sPageLast = 'control-last';
$(document).ready(function() {
$('.sortable').each(function(i)
{
var table = $(this),
oTable = table.dataTable({
"sPaginationType": "full_numbers",
"bProcessing": false,
"bServerSide": true,
"sAjaxSource": "./server_processing.php",
"aoColumns": [null, null, null, null, null, null, { "bSortable": false,
"fnRender": function(oObj) {
var cId = oObj.aData[0];
return ''+cId+'';
}
}],
/*
* Set DOM structure for table controls
* @url http://www.datatables.net/examples/basic_init/dom.html
*/
sDom: '<"block-controls"<"controls-buttons"p>>rti<"block-footer clearfix"lf>',
/*
* Callback to apply template setup
*/
fnDrawCallback: function()
{
this.parent().applyTemplateSetup();
},
fnInitComplete: function()
{
this.parent().applyTemplateSetup();
}
});
// Sorting arrows behaviour
table.find('thead .sort-up').click(function(event)
{
// Stop link behaviour
event.preventDefault();
// Find column index
var column = $(this).closest('th'),
columnIndex = column.parent().children().index(column.get(0));
// Send command
oTable.fnSort([[columnIndex, 'asc']]);
// Prevent bubbling
return false;
});
table.find('thead .sort-down').click(function(event)
{
// Stop link behaviour
event.preventDefault();
// Find column index
var column = $(this).closest('th'),
columnIndex = column.parent().children().index(column.get(0));
// Send command
oTable.fnSort([[columnIndex, 'desc']]);
// Prevent bubbling
return false;
});
} );
});
[/code]
My html is:
[code]
ID
Name
Company
Email
Role
Active
Actions
[/code]
I'm using the server side php script that came with the demo (works great for my needs!) almost as-is.. Can someone tell me what I am missing?
Thanks!
Dennis
DataTables warning (table id = 'sortable'): Added data (size 6) does not match known number of columns (7). I can not figure out why this is happenning..
[code]
$.fn.dataTableExt.oStdClasses.sWrapper = 'no-margin last-child';
$.fn.dataTableExt.oStdClasses.sInfo = 'message no-margin';
$.fn.dataTableExt.oStdClasses.sLength = 'float-left';
$.fn.dataTableExt.oStdClasses.sFilter = 'float-right';
$.fn.dataTableExt.oStdClasses.sPaging = 'sub-hover paging_';
$.fn.dataTableExt.oStdClasses.sPagePrevEnabled = 'control-prev';
$.fn.dataTableExt.oStdClasses.sPagePrevDisabled = 'control-prev disabled';
$.fn.dataTableExt.oStdClasses.sPageNextEnabled = 'control-next';
$.fn.dataTableExt.oStdClasses.sPageNextDisabled = 'control-next disabled';
$.fn.dataTableExt.oStdClasses.sPageFirst = 'control-first';
$.fn.dataTableExt.oStdClasses.sPagePrevious = 'control-prev';
$.fn.dataTableExt.oStdClasses.sPageNext = 'control-next';
$.fn.dataTableExt.oStdClasses.sPageLast = 'control-last';
$(document).ready(function() {
$('.sortable').each(function(i)
{
var table = $(this),
oTable = table.dataTable({
"sPaginationType": "full_numbers",
"bProcessing": false,
"bServerSide": true,
"sAjaxSource": "./server_processing.php",
"aoColumns": [null, null, null, null, null, null, { "bSortable": false,
"fnRender": function(oObj) {
var cId = oObj.aData[0];
return ''+cId+'';
}
}],
/*
* Set DOM structure for table controls
* @url http://www.datatables.net/examples/basic_init/dom.html
*/
sDom: '<"block-controls"<"controls-buttons"p>>rti<"block-footer clearfix"lf>',
/*
* Callback to apply template setup
*/
fnDrawCallback: function()
{
this.parent().applyTemplateSetup();
},
fnInitComplete: function()
{
this.parent().applyTemplateSetup();
}
});
// Sorting arrows behaviour
table.find('thead .sort-up').click(function(event)
{
// Stop link behaviour
event.preventDefault();
// Find column index
var column = $(this).closest('th'),
columnIndex = column.parent().children().index(column.get(0));
// Send command
oTable.fnSort([[columnIndex, 'asc']]);
// Prevent bubbling
return false;
});
table.find('thead .sort-down').click(function(event)
{
// Stop link behaviour
event.preventDefault();
// Find column index
var column = $(this).closest('th'),
columnIndex = column.parent().children().index(column.get(0));
// Send command
oTable.fnSort([[columnIndex, 'desc']]);
// Prevent bubbling
return false;
});
} );
});
[/code]
My html is:
[code]
ID
Name
Company
Role
Active
Actions
[/code]
I'm using the server side php script that came with the demo (works great for my needs!) almost as-is.. Can someone tell me what I am missing?
Thanks!
Dennis
This discussion has been closed.
Replies
Allan
I worked aroudn it by bring in another field from the table which wasn't needed (zipcode) than replaced the contents with what I needed.. Works.. but doesn't seem like a proper way to do it..
[code]
"sAjaxSource": "./server_processing.php",
"aoColumns": [null, null, null, null, null, null, { "bSortable": false,
"fnRender": function(oObj) {
return ' ';
}
}],
[/code]
The above is just placeholders for now to see how it would look..
Allan
Right now I have "" empty strings from the server-side.
Is there any way to pre-process the JSON from the server to add empty strings (or better, add the actual content i.e. Edit, Delete)?
thanks a lot, datatables is really great!
If you don't mind me suggesting an option that may fix Thirdy's and my concern of presentation. Is it possible to add "bSkip": to aoColumns and aoColumnDefs that would hint dataTables to avoid the specific column? In such a case, the error message will be generated if
[code]aDataSupplied.length != ( oSettings.aoColumns.length - ( oSettings.aoColumns.grep( function ( elem ) {
return ( elem.bSkipped === true );
} ) ).length )[/code] Styles can still be applied to the skipped columns by using aoColumns and aoColumnDefs but cells will be left blank unless fnRender is specified.
I've searched around the forums and became aware that quite a few people are looking for a similar solution option. What do you think? This way, we can separate data from presentation and things would be cleaner.
Either way, your plugin is awesome!!!
There are of course cases when this simply isn't enough - a common one I find myself using is a hidden column for the row ID. This is really meta data for the table, rather than presentation data, and I intent to make this part considerably more flexible in 1.8. For the display part, I will probably continue to enforce that what is to be displayed must be defined (otherwise, how do you represent undefined data...).
One possible way of doing it at the moment with 1.7 is to use fnServerData to pre-process the JSON returned from the server - although you don't then have access to the object again... Keep an eye out for 1.8 :-)
Allan