cannot destroy table when using init method on button instances

cannot destroy table when using init method on button instances

nlooijenlooije Posts: 49Questions: 10Answers: 0

Link to test case:
https://live.datatables.net/lotojaya/1/edit

Debugger code (debug.datatables.net):
ejesuy

Error messages shown:
Uncaught TypeError: Cannot read properties of undefined (reading 'split')
at U.<anonymous> (datatables.min.js:16:69323)
at U.off (datatables.min.js:16:47220)
at U.destroy (datatables.min.js:43:13470)
at _.remove (datatables.min.js:26:3846)
at _.destroy (datatables.min.js:26:2745)
at HTMLTableElement.<anonymous> (datatables.min.js:26:4414)
at HTMLTableElement.dispatch (jquery-1.11.3.min.js:4:8549)
at r.handle (jquery-1.11.3.min.js:4:5252)
at Object.trigger (jquery-1.11.3.min.js:4:7650)
at HTMLTableElement.<anonymous> (jquery-1.11.3.min.js:4:15517)

Description of problem:
I want to be able to destroy() a Datatable with buttons with custom init methods to be able to toggle the buttons based on certain permissions when (de)selecting rows.
Destroying is not an issue when init is not used or only set on one button.
Once more than one buttons uses a custom init method I get the above error.

Answers

  • allanallan Posts: 63,676Questions: 1Answers: 10,497 Site admin

    That is indicative of another issue - it is just that this is the easily visible part.

    The real problem is that you are replacing the selected button's init function with your own, and not setting it up the same way. That can be done, but the destroy method is expected that the original init was called. It isn't therefore they are out of sync.

    The easiest solution is simply to call the original init function:

      function buttonInit(dt, node, config){
        DataTable.ext.buttons.selected.init.call(this, dt, node, config);
        console.log('buttonInited');
      }
    

    https://live.datatables.net/lotojaya/2/edit

    Note that I have removed it from the create button since that doesn't extend from selected.

    Allan

  • nlooijenlooije Posts: 49Questions: 10Answers: 0

    Understood. I would not have thought of that. Thanks

Sign In or Register to comment.