Set fnDrawCallback after initializing

Set fnDrawCallback after initializing

svierkantsvierkant Posts: 33Questions: 2Answers: 0
edited April 2013 in General
I'm using the row grouping (http://www.datatables.net/examples/advanced_init/row_grouping.html) so much, that I want to have it as a named function, so I can re-use it on every page with a DataTable. Unfortunately, I can't make it work in such a way that It's still working after a redraw.

Here's my script: http://live.datatables.net/egafik/edit#preview

Based on a comment in another topic (http://datatables.net/forums/discussion/5524/fndrawcallback-listener-adding/p1), I made another script: http://live.datatables.net/iboluz/2/edit#source. That one has the same effect.

Why is fnDrawCallback running only once?

Replies

  • allanallan Posts: 63,520Questions: 1Answers: 10,473 Site admin
    You cannot do:

    > oTable.fnDrawCallback = ...

    that is meaningless to DataTables. What you can do is listen for the 'draw' event:

    [code]
    $('#example').on('draw', function () { ... } );
    [/code]

    Worth noting that you are only assigning `undefined` to `oTable.fnDrawCallback` since you are actually executing the function.

    Allan
  • svierkantsvierkant Posts: 33Questions: 2Answers: 0
    edited April 2013
    Hi allan,

    Thanks for your reply!

    I tried, but I can't make it happen:
    http://live.datatables.net/egafik/4: $('#example').on('draw', GroupByColumn(oTable, 0) );
    http://live.datatables.net/egafik/5: $('#example').on('draw', function () { GroupByColumn(oTable, 0); });


    My last try was using on('draw'), but the 'init' doesn't work:
    $('#example').on('draw', function(e, oSettings) { GroupByColumn(oSettings, 0); } );
    $('#example').on('init', function(e, oSettings) { GroupByColumn(oSettings, 0); } );

    http://live.datatables.net/egafik/10

    What's going wrong?
  • svierkantsvierkant Posts: 33Questions: 2Answers: 0
    It looks like the init-event isn't working. I made a new live example, using console.log() to see what's (not) happing:

    http://live.datatables.net/ovaguw

    I used your example: http://datatables.net/forums/discussion/comment/38750#Comment_38750
  • allanallan Posts: 63,520Questions: 1Answers: 10,473 Site admin
    Well you are attaching the event listener after the table is drawn, and then not redrawing the table, so it is not sup rising that it isn't doing anything.

    If you redraw the table after the event listener has been added it does work: http://live.datatables.net/egafik/12/edit - although there is a script error with an indexing issue somewhere, but the function does at least run now.

    Allan
This discussion has been closed.