Added data does not match known number of columns using aoColumnDefs! What's wrong ??
Added data does not match known number of columns using aoColumnDefs! What's wrong ??
i've encountered the same problem as somebody else..when i use datatables 1.7.4..
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 allan's solution..3q...!!!
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 allan's solution..3q...!!!
This discussion has been closed.
Replies
I just want to use 1.7.4 because it has the new feature x-scroll and y-scroll which is very practical.....
DataTables warning (table id = 'dataTable'):Added data (size 6) does not match known number of columns (3)
1. (size 6): this size could be 4?5? 6 ?7 etc. which is delivered by action.do(java) in terms of json.
2. columns (3): this is the original column size .
???
how could i change this dynamicly with aoColumnDefs or aoColumn in 1.7.4...
3q!!!