how do I turn $('#example').dataTable() into a function?

how do I turn $('#example').dataTable() into a function?

mxm304mxm304 Posts: 4Questions: 0Answers: 0
edited September 2010 in General
Hi, I would like to call $('#example').dataTable() from an event (e.g. button click) rather then automatically on document ready (as in the examples). Possible I might call it several times each time with a different argument and have to destroy previously created datable. Is there any example for this?
Thanks and kind regards,
Patrick

Replies

  • ruzzruzz Posts: 49Questions: 0Answers: 0
    Just do it - I do exactly that. Well, almost...

    ruzz
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    [code]
    $('#whatever').click( function () {
    $('#example').dataTable( { "bDestroy": true, ... } );
    } );
    [/code]
    will do it nicely.

    Allan
  • mxm304mxm304 Posts: 4Questions: 0Answers: 0
    Ok, my problem was more a jquery problem then a dataTables problem. I'm really only a few weeks old in jQuery.
    This is what I wanted to ask ... and googled the following solution:
    [code]
    $(document).ready(function() {
    $('select').change(function(){
    drawTable(val);
    });
    function drawTable(arg1) {
    $('#example').dataTable( { "bDestroy": true, ... } ); }
    });
    [/code]

    Works nice. I really start to like dataTables.
    Ruzz, Allan, thanks.

    -Patrick
This discussion has been closed.