Number of Columns does not change
Number of Columns does not change
schmidtphil
Posts: 2Questions: 0Answers: 0
Sorry for putting this in General, but I did not want to put it in bug reports, since it's rather a lack of my understanding of datatables than a bug.
I am building a table that shows different data inputs. They all have a different content and a different number of columns. I am using an ajax call to get the data from the server. It would be great if the datatable could adjust to the number of columns. So far I have managed to update the content, but the number of columns seems to stay fixed from the first data call. I have played around with the b-options and this combination seems to be the best working one for me. The debugger returns "iquqak".
Table definition:
[code]
[/code]
Ajax Call:
[code]
var oTable = null;
$.ajax({
url: config.renderURL + "/" + id,
success: function(json) {
data = json;
if (oTable !== null) {
oTable.fnClearTable();
oTable.fnAddData(json.aaData);
} else {
oTable = $('#foobar').dataTable({
"iDisplayLength": -1,
"bDestroy": true,
"bSort": false,
"bRetrieve": true,
"aaData": json.aaData,
"aoColumns": json.aoColumns
});
}
oTable.fnDraw();
error: function(xhr, err) {
alert("No content found");
}
});
[/code]
For example if I use this json for the first call, it works fine:
[code]
{"iTotalRecords": "4",
"aoColumns": [
{"sTitle": "", "sDefaultContent": "", "mDataProp": null},
{"sTitle": "Column 1", "sDefaultContent": "", "mDataProp": null},
{"sTitle": "Column 2", "sDefaultContent": "", "mDataProp": null},
{"sTitle": "Column 3", "sDefaultContent": "", "mDataProp": null}],
"aaData": [
["Row 1", "1", "2", "2"],
["Row 2", "1", "2", "3"],
["Row 3", "45", "5", "6"],
["Row 4", "6", "6", "7"]],
"iTotalDisplayRecords": "4",
"sEcho": "0"}
[/code]
If I want to load a table with more than 4 columns it will still only show 4.
I am building a table that shows different data inputs. They all have a different content and a different number of columns. I am using an ajax call to get the data from the server. It would be great if the datatable could adjust to the number of columns. So far I have managed to update the content, but the number of columns seems to stay fixed from the first data call. I have played around with the b-options and this combination seems to be the best working one for me. The debugger returns "iquqak".
Table definition:
[code]
[/code]
Ajax Call:
[code]
var oTable = null;
$.ajax({
url: config.renderURL + "/" + id,
success: function(json) {
data = json;
if (oTable !== null) {
oTable.fnClearTable();
oTable.fnAddData(json.aaData);
} else {
oTable = $('#foobar').dataTable({
"iDisplayLength": -1,
"bDestroy": true,
"bSort": false,
"bRetrieve": true,
"aaData": json.aaData,
"aoColumns": json.aoColumns
});
}
oTable.fnDraw();
error: function(xhr, err) {
alert("No content found");
}
});
[/code]
For example if I use this json for the first call, it works fine:
[code]
{"iTotalRecords": "4",
"aoColumns": [
{"sTitle": "", "sDefaultContent": "", "mDataProp": null},
{"sTitle": "Column 1", "sDefaultContent": "", "mDataProp": null},
{"sTitle": "Column 2", "sDefaultContent": "", "mDataProp": null},
{"sTitle": "Column 3", "sDefaultContent": "", "mDataProp": null}],
"aaData": [
["Row 1", "1", "2", "2"],
["Row 2", "1", "2", "3"],
["Row 3", "45", "5", "6"],
["Row 4", "6", "6", "7"]],
"iTotalDisplayRecords": "4",
"sEcho": "0"}
[/code]
If I want to load a table with more than 4 columns it will still only show 4.
This discussion has been closed.
Replies