add/change parameter

add/change parameter

zackzack Posts: 6Questions: 0Answers: 0
edited January 2013 in General
I'd like to add parameter to DataTable object.

initially...
[code]
var oTable = jQuery("#table_id").dataTable({
"bServerSide": true,
"bPaginate": false,
}
[/code]

then I'd like to add/change parameter
[code]
"bPaginate": true,
"aaSorting":[[1, "asc" ]],
[/code]

to make object in the below.
[code]
jQuery("#table_id").dataTable({
"bServerSide": true,
"bPaginate": true,
"aaSorting":[[1, "asc" ]],
}
[/code]

What should I do....

Thank everyone in advance!

Replies

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Just do exactly what you have in the last example? You can't dynamically alter the initialisation options - you'd need to destroy the table and then recreate it with the new features if you want that.

    Allan
  • zackzack Posts: 6Questions: 0Answers: 0
    Thank you, Allan.

    What I'd like to do was like ...
    using kind of perl template which makes basic common options.
    in forms, call the template at first.
    and then, add sort depned on each form.

    perl making common options
    [code]
    var oTable = jQuery("#table_id").dataTable({
    "bServerSide": true,
    "bPaginate": true,
    }
    [/code]

    html1
    [code]
    |

    jQuery("#menu").menu({
    disabled: false
    });

    ~call perl~
    oTable = blah-blah ( "aaSorting":[[1, "asc" ]] );

    jQuery("#accordion").accordion({
    collapsible: true,
    });

    |
    [/code]

    html2
    [code]
    |

    jQuery("#menu").menu({
    disabled: false
    });

    ~call perl~
    oTable = blah-blah ( "aaSorting":[[2, "asc" ]] );

    jQuery("#accordion").accordion({
    collapsible: true,
    });

    |
    [/code]

    html3
    [code]
    |

    jQuery("#menu").menu({
    disabled: false
    });

    ~call perl~
    oTable = blah-blah ( "aaSorting":[[3, "asc" ]] );

    jQuery("#accordion").accordion({
    collapsible: true,
    });

    |
    [/code]

    If there is not method/function to add like above exsample, it's OK.
    I'll do somehow.

    But thank you again, Allan.
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Two options:

    1. Set the default as you need - http://datatables.net/release-datatables/examples/advanced_init/defaults.html
    2. Create a Javascript object that you add options to, initialising the table only once when it is fully built.

    I'd probably go with option 1 myself, assuming there is only 1 table on each page, otherwise option 2.

    Allan
  • zackzack Posts: 6Questions: 0Answers: 0
    edited January 2013
    Thank you for your advice, Allan!!
    I'll try option 1!

    And thank you for creating & opening this hyper awesome cool jQuery!
This discussion has been closed.