Added data does not match known number of columns using aoColumnDefs
Added data does not match known number of columns using aoColumnDefs
I have a case where I have defined a table with 18 columns using 18 table > thead > th-tags.
The data is loaded by sAjaxSource from a json source with 18 fields. The features of the columns is then configured with aoColumnDefs.
Now im trying to add a index column to the front of the table but when I add another th-tag to the table definition, datatable complains about "DataTables warning .... Added data (size 18) does not match known number of columns (19)". Which is correct, there are one more column than the json dataset contains.
Do I have to add a dummy column to the json-source to match the new 19th field in the view just to have datatable not complain and ignore the value and use the column for a static index count?
The data is loaded by sAjaxSource from a json source with 18 fields. The features of the columns is then configured with aoColumnDefs.
Now im trying to add a index column to the front of the table but when I add another th-tag to the table definition, datatable complains about "DataTables warning .... Added data (size 18) does not match known number of columns (19)". Which is correct, there are one more column than the json dataset contains.
Do I have to add a dummy column to the json-source to match the new 19th field in the view just to have datatable not complain and ignore the value and use the column for a static index count?
This discussion has been closed.
Replies
But i'm absolutely right when i use 1.6..
i try to plus the following code to fix the column problem .but it does't work. omg......
[code]
var theadInnerHtml = "Time";
$("#ddlSubField option").each(function(){
var text = $(this).text().split("[")[0];
theadInnerHtml += "" + text + "";
});
$("#dataTable>thead>tr").html(theadInnerHtml);
///----------- recreate the array of aoColumnDefs !!
var tempColumn = ddlSubField.split(",");
var kkk = 0;
if(dataTable != null){
dataTable.fnSettings().aoColumnDefs = [];
for(var k = 0; k < tempColumn.length - 1; k++){
kkk = k;
alert(k + "--" + tempColumn[k]);
dataTable.fnSettings().aoColumnDefs.push('{"sWidth":"100px","aTargets":[' + k + ']},');
}
kkk++;
dataTable.fnSettings().aoColumnDefs.push('{"sWidth":"100px","aTargets":[' + kkk + ']}');
for(var k = 0; k < dataTable.fnSettings().aoColumnDefs.length; k++){
alert(dataTable.fnSettings().aoColumnDefs[k]);
}
}
[/code]
how could i use aoColumnDefs when i want to add or delete some colunms dynamic.
the data is call by ajax Below:
[code]
//Operate datatables
function operateDataTables(ajaxPath){
if(dataTable == null){
dataTable = $('#dataTable').dataTable( {
"bAutoWidth" : false, // ???????? ",
"aoColumnDefs": [{"sWidth":"120px", "aTargets": [ 0 ]},{"sWidth":"120px", "aTargets": [ 1 ]},{"sWidth":"120px", "aTargets": [ 2 ]}],
"sScrollY": 200,
"sScrollX": "550px",
"sScrollXInner": "110%",
"sDom": '<"wrapper"pi>rt<"wrapper"ip>',
"bStateSave" : true,//
"bProcessing" : true, // ?????????????
"bServerSide" : true, // ???????????
"bFilter" : false, // ???????
"bLengthChange" : false, // ????????????
"iDisplayLength" : 20, // ????8???
"sAjaxSource" : ajaxPath,// The AJAX url
"sPaginationType" : "full_numbers", // ??????
});
}else{
dataTable.fnDraw();
}
}
[/code]
I'M looking forward to allen's solution..3q...!!!