0

I have a button in ajax mode datatable. A click event is attached with the button which further sends ajax to change the record. After that i have reloaded the table using

 this.table.ajax.reload();

The function is working fine also the table is perfectly updated the record but the click function triggered twice and sends ajax twice to update data.

     $('body').on('click', '.status-change', function(e) {
        this.changeStatus(e.target.dataset.itemStatus,e.target.dataset.itemId);
      });

if i attach unbind with body like:

$('body').unbind('click').on('click', '.status-change', function(e) {
        this.changeStatus(e.target.dataset.itemStatus,e.target.dataset.itemId);
});

Now the click event is triggering once. But there is no change in table. Table sends ajax to reload new Data. but table is not getting update.

7
  • 1
    Make sure and check that you have not accidentally included your script twice in your HTML page. Commented Jul 2, 2019 at 10:22
  • I am using vue.js component
    – Neha
    Commented Jul 2, 2019 at 10:24
  • 1
    @Neha: Take a look at this link: stackoverflow.com/questions/45613692/… Commented Jul 2, 2019 at 10:31
  • 1
    Does $("#table").DataTable().draw(); redraw it correctly after the event is triggered but not changing the table? Commented Jul 2, 2019 at 12:30
  • 1
    Why not do $('body .status-change').off('mynamespace.click').on('mynamespace.click',function(e){...}); Commented Jul 3, 2019 at 12:06

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.