Extend draw.dt Callback

Extend draw.dt Callback

coisoxcoisox Posts: 4Questions: 3Answers: 0

Hi, I need help.

To get id and ajax data, we can do this:

$('body').on('draw.dt', function(e, ctx){
    var api = new $.fn.dataTable.Api(ctx)
    console.log('The ID  : ', api.table().node().id)
    console.log('The data: ', api.ajax.json())
})

I want to extend (without touching datatables.js) the draw.dt so that my team can do this:

$('body').on('draw.dt', function(e, ctx, id, data){
    console.log('The ID  : ', id)
    console.log('The data: ', data)
})

Answers

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin

    without touching datatables.js

    You can't. The only way to add the DataTable API instance to the parameters of the event callback would be to modify the source.

    The only other option would be to trigger your own event (custom-draw for example) from inside the draw event handler. Then you can pass your own parameters to it.

    Allan

This discussion has been closed.