How to give options in dataTables based on javascript variables?

How to give options in dataTables based on javascript variables?

arpitsinghalarpitsinghal Posts: 3Questions: 0Answers: 0
edited October 2013 in General
I want to do something like following:

I need to initialize multiple DataTables on a single page. And I would need to turn on/off pagination by using a value from a javascript variable. One way is to duplicate the datatable initializing code code within if else javascript. Is there simple way to use javascript if else within datatable initialization. Thanks.

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    I'm not sure I quite understand - wouldn't you just use the variables directly?

    [code]
    var paging = false;

    $('#example').dataTable( {
    bPaginate: paging
    } );
    [/code]

    Allan
  • jammerjammer Posts: 2Questions: 0Answers: 0
    Hi

    I am also interested in learning how to dynamically change which options are assigned in the datatable initialization code.

    I can easily do what Allen had suggested for adjusting certain option parameters, but am interested in finding out how to have an option removed completely.

    Example:
    [code]
    $('#example').dataTable( {
    "bPaginate": true,
    "aaSorting": [[ 2, 'desc' ]],
    "aaSortingFixed": [[0,'asc']]
    } );
    [/code]

    So in the previous example, how would one go about removing the fixed sorting option or disabling it completely when a certain condition is met.

    Sorry if I am hijacking the thread, but I thought that perhaps arpitsinghal's issue may be similar to what I was trying to accomplish.

    Thanks.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    [code]
    "aaSortingFixed": condition ? [[0,'asc']] : []
    [/code]

    Allan
  • jammerjammer Posts: 2Questions: 0Answers: 0
    Fantastic!

    Thank You.
  • arpitsinghalarpitsinghal Posts: 3Questions: 0Answers: 0
    that is what I was expecting. Also, how can you see the default value of the certain parameter. Like, I want to use sDom parameter into certain tables only based on a parameter, what should I give default sDom value as. Thanks.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    If you look at the documentation for each option you will see its default listed.

    Allan
This discussion has been closed.