order.dt event fired on table.draw

order.dt event fired on table.draw

BevanBevan Posts: 4Questions: 2Answers: 0

Good morning.

I am trying to fill a datatable when a user clicks a button. I would like to handle the paging and ordering myself.
My problem stems from the search click event which immediately fires the order.dt function when _table.draw() is executed.
How can I prevent the order.dt function from executing when _table.draw() is called?
The datatable is initialized as follows:

var _table = $('#tbl').DataTable();

$('#Search').on('click', function(){
    _table.clear();
    _table.rows.add(dataSet);
    _table.draw();
});

$'#tbl').on('page.dt', function(){
    var info = table.page.info();
    _table.clear();
    _table.rows.add(<new dataSet>);
    _table.draw();
});

$('#tbl').on('order.dt', function(){
    var order = table.order();
    _table.clear();
    _table.rows.add(<new dataSet>);
    _table.draw();
});

Any help would be greatly appreciated. Thank you in advance.

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599
    Answer ✓

    Hi @Bevan ,

    It's not the draw that's triggering it, it's more the sequence of the events. This live demo here may help, it shows what events are being called when you order/search/page etc.

    Hope that makes it clearer,

    Cheers,

    Colin

  • BevanBevan Posts: 4Questions: 2Answers: 0

    Thank you.

This discussion has been closed.