Changing aoColumnDefs parameters of a present table

Changing aoColumnDefs parameters of a present table

markjomarkjo Posts: 66Questions: 0Answers: 0
edited August 2012 in General
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

Replies

  • markjomarkjo Posts: 66Questions: 0Answers: 0
    I changed my code to following code.
    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]
  • markjomarkjo Posts: 66Questions: 0Answers: 0
    edited August 2012
    Now I initialize my table like this:
    [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]
  • markjomarkjo Posts: 66Questions: 0Answers: 0
    It seems like we can't change "sPaginationType" after initialization of the table.
    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]
  • markjomarkjo Posts: 66Questions: 0Answers: 0
    edited August 2012
    Alternatively I can set aocolumndefs like the code below.
    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]
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    > How can I change "aoColumnDefs" after the initialization of the table?

    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
  • yosale_hamuzimyosale_hamuzim Posts: 2Questions: 1Answers: 0

    still no support for that?

    thanks

This discussion has been closed.