Changing aoColumnDefs parameters of a present table
Changing aoColumnDefs parameters of a present table
I'm sorry for newbie question..
I have such following code:
[code] $('#mytable').dataTable(
{
"aoColumnDefs":[
{ "sType":"title-numeric", "aTargets":[ 3 ] },
{ "sType":"title-numeric", "aTargets":[ 7 ] },
{ "bSortable":false, "aTargets":[ 0 ] },
{ "bSortable":false, "aTargets":[ 8 ] },
{ "bSortable":false, "aTargets":[ 9 ] },
{ "sClass":"center", "aTargets":[ 2, 3, 4, 5, 6, 7 ] }
],
"bPaginate":true,
"sPaginationType": paginationType,
"sDom":'<"top"iflp<"clear">>rt<"bottom"iflp<"clear">>',
"fnDrawCallback": function () { myfunction() },
"iDisplayLength":25,
"oLanguage":{
"sProcessing":"aaa...",
"sLengthMenu":"bbb",
"sZeroRecords":"ccc",
}
}
);[/code]
I need to change "aoColumnDefs" regarding to one parameter.
For example if user comes from mobile device I will use another "aoColumnDefs".
I don't want to duplicate all code.
I need to write desktop/mobile common code first and write "aoColumnDefs" regarding to mobile user parameter.
How can I do this.
Thank you very much
I have such following code:
[code] $('#mytable').dataTable(
{
"aoColumnDefs":[
{ "sType":"title-numeric", "aTargets":[ 3 ] },
{ "sType":"title-numeric", "aTargets":[ 7 ] },
{ "bSortable":false, "aTargets":[ 0 ] },
{ "bSortable":false, "aTargets":[ 8 ] },
{ "bSortable":false, "aTargets":[ 9 ] },
{ "sClass":"center", "aTargets":[ 2, 3, 4, 5, 6, 7 ] }
],
"bPaginate":true,
"sPaginationType": paginationType,
"sDom":'<"top"iflp<"clear">>rt<"bottom"iflp<"clear">>',
"fnDrawCallback": function () { myfunction() },
"iDisplayLength":25,
"oLanguage":{
"sProcessing":"aaa...",
"sLengthMenu":"bbb",
"sZeroRecords":"ccc",
}
}
);[/code]
I need to change "aoColumnDefs" regarding to one parameter.
For example if user comes from mobile device I will use another "aoColumnDefs".
I don't want to duplicate all code.
I need to write desktop/mobile common code first and write "aoColumnDefs" regarding to mobile user parameter.
How can I do this.
Thank you very much
This discussion has been closed.
Replies
But I got this error:
[quote] Datatables warning ( tableid = mytable): Cannot reinitialize Datatable.
To retrieve the Datatables object for this table, pass no arguments or see the docs for bRetrieve and bDestroy[/quote]
[code] $('#mytable').dataTable(
{
"bPaginate":true,
"sDom":'<"top"iflp<"clear">>rt<"bottom"iflp<"clear">>',
"fnDrawCallback": function () { aaa() },
"iDisplayLength":25,
"oLanguage":{
"sProcessing":"bbb...",
}
}
);
if (!mobileUser) {
$('#mytable').dataTable(
{
"aoColumnDefs":[
{ "sType":"title-numeric", "aTargets":[ 3 ] },
{ "sType":"title-numeric", "aTargets":[ 7 ] },
{ "bSortable":false, "aTargets":[ 0 ] }
],
"sPaginationType": "full_numbers"
}
);
}
if (mobileUser) {
$('#mytable').dataTable(
{
"sPaginationType": "two_button"
}
);
}[/code]
[code] var oTable = $('#mytable').dataTable(
{
"bPaginate":true,
"sDom":'<"top"iflp<"clear">>rt<"bottom"iflp<"clear">>',
"fnDrawCallback": function () { aaa() },
"iDisplayLength":25,
"oLanguage":{
"sProcessing":"bbb...",
}
}
);[/code]
So how can I change following parameters??
[code]"aoColumnDefs":[
{ "sType":"title-numeric", "aTargets":[ 3 ] },
{ "sType":"title-numeric", "aTargets":[ 7 ] },
{ "bSortable":false, "aTargets":[ 0 ] }
],
"sPaginationType": "full_numbers"
[/code]
I tried this but didn't work:
[code] oTable.sPaginationType("full_numbers");[/code]
So I'm searching for "aoColumnDefs".
How can I change "aoColumnDefs" after the initialization of the table?
[code] "aoColumnDefs":[
{ "sType":"title-numeric", "aTargets":[ 7 ] },
{ "bSortable":false, "aTargets":[ 0 ] },
{ "sClass":"center", "aTargets":[ 2, 3, 4, 5, 6, 7 ] }[/code]
How can I set "aoColumnDefsType" parameter to put into dataTables initialization??
[code] var aoColumnDefsType;
if (mobileUser) {
aoColumnDefsType = "aoColumnDefs":[
{ "sType":"title-numeric", "aTargets":[ 7 ] },
{ "bSortable":false, "aTargets":[ 0 ] },
{ "sClass":"center", "aTargets":[ 2, 3, 4, 5, 6, 7 ] }
} else {
aoColumnDefsType= "aoColumnDefs":[
{ "sType":"title-numeric", "aTargets":[ 5 ] },
{ "bSortable":false, "aTargets":[ 1 ] },
{ "sClass":"center", "aTargets":[ 2, 3, 4, 7 ] }
}
var oTable = $('#usersTable').dataTable(
{
"aoColumnDefs": aoColumnDefsType,
...
....
...
...
}[/code]
You can't - this is not a supported feature of DataTables. The closest you can come to that is to destroy the table with bDestroy as the error message suggests, and recreate the table with your new initialisation options.
Allan
still no support for that?
thanks