Number of Columns mismatch
Number of Columns mismatch
bluesapphire
Posts: 17Questions: 0Answers: 0
I have three columns in thead and iam getting six columns data from server. I want to concatinate two or more columns returned from server and display them under client side thead columns. Iam using following :
'aoColumnDefs' : [
{
'sName': 'engine' , 'sTitle' : 'Engine Title', 'aTargets' : [0],
'fnRender' : function (obj) {
return obj.aData[0]+' '+obj.aData[1];
}
},
{
'sName': 'browser' , 'sTitle' : 'Browser Title', 'aTargets' : [1],
'fnRender' : function (obj) {
return obj.aData[2]+' '+obj.aData[3];
}
},
{
'sName': 'platform' , 'sTitle' : 'Platform Title', 'aTargets' : [2],
'fnRender' : function (obj) {
return obj.aData[4]+' '+obj.aData[5];
}
},
],
But it is giving me errors :
"DataTables warning (table id = 'example'): Added data (size 6) does not match known number of columns (3)"
Can some one guide me what Iam doing wrong and how it can be rectified.
Thanks in advance
'aoColumnDefs' : [
{
'sName': 'engine' , 'sTitle' : 'Engine Title', 'aTargets' : [0],
'fnRender' : function (obj) {
return obj.aData[0]+' '+obj.aData[1];
}
},
{
'sName': 'browser' , 'sTitle' : 'Browser Title', 'aTargets' : [1],
'fnRender' : function (obj) {
return obj.aData[2]+' '+obj.aData[3];
}
},
{
'sName': 'platform' , 'sTitle' : 'Platform Title', 'aTargets' : [2],
'fnRender' : function (obj) {
return obj.aData[4]+' '+obj.aData[5];
}
},
],
But it is giving me errors :
"DataTables warning (table id = 'example'): Added data (size 6) does not match known number of columns (3)"
Can some one guide me what Iam doing wrong and how it can be rectified.
Thanks in advance
This discussion has been closed.
Replies
Allan
We're also having some difficulties here. What if we don't know in advance the number of columns that we get from the server?
Perhaps you could explain your scenario a little more?
Allan
The problem we're experiencing (I'm with pmalves) is as follows:
We support both client-side and server-side paging and sorting. The former is handled by using the Javascript array initialisation. Under those conditions, we handle the AJAX requests ourselves, and build the {aaData:[], aoColumns:[]} object once the AJAX request has returned its data. Since we have complete control over the creation of aoColumns before DataTables is initialised, all goes according to plan.
When we're paginating and sorting server-side, we resort to the fnServerData callback to do our querying. Since we're querying the exact same data source, we have the same limitations: only when the query within fnServerData yields results do we have access to the column metadata. At this point in the execution process, dataTables.fnSettings().aoColumns reports at least some columns already created, and we couldn't quite find anything in the API that would let us manipulate those columns.
So I guess our question is: How do we go about changing the table layout in a data-dependent manner, when the data comes from fnServerData?