Number of Columns mismatch

Number of Columns mismatch

bluesapphirebluesapphire Posts: 17Questions: 0Answers: 0
edited April 2011 in General
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

Replies

  • allanallan Posts: 63,516Questions: 1Answers: 10,473 Site admin
    Do the concatenation on the server-side. DataTables currently requires that your JSON response has exactly the number of columns in it that are in the table.

    Allan
  • pmalvespmalves Posts: 18Questions: 0Answers: 0
    Hello 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?
  • allanallan Posts: 63,516Questions: 1Answers: 10,473 Site admin
    @pmalves: How to you give your column's titles? I ask because I think the answer to that will then relate to the answer to your own question. Basically you could build the table based on the JSON return and then initialise the table with that number of columns. Then if the number changes for the next table destroy it and construct a new table - etc.

    Perhaps you could explain your scenario a little more?

    Allan
  • pdpipdpi Posts: 2Questions: 0Answers: 0
    Hey 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?
This discussion has been closed.