DataTables custom events?

DataTables custom events?

benekastahbenekastah Posts: 3Questions: 0Answers: 0
edited September 2011 in Feature requests
Does DataTables emit any of it's own events? I would like to be able to do something like this:

[code]
var dt = $('#someTable').dataTable()
.bind('sort', function () { /* do something... */ })
.bind('change', function () { /* do something... */ });
[/code]

There are a few events that would be especially helpful (if they exist):

1. change: Whenever data is changed or added, display order is modified, page changes, etc.
2. sort
3. page

Replies

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin
    The answer to this is yes it does - but with the cravat that its a bit experimental (not because custom events are experimental, but because I haven't yet fully implemented it as I would wish). There is some discussion from me in the commit comment for this (including what events are supported): https://github.com/DataTables/DataTables/commit/8a8ca1e7b8c62463eba0f8fb04d5e46ed6de2dc2 .

    Regards,
    Allan
  • benekastahbenekastah Posts: 3Questions: 0Answers: 0
    Great! I'll try these out.
  • DaScritchDaScritch Posts: 1Questions: 0Answers: 0
    Not bad at all !

    But is there any way to access to a sort event between the click on the and before the 'draw' event ?
  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin
    No - you would need to unbind the sort listener that DataTables adds and then bind your own - or a 'pre-sort' event could potentially be added.

    Certainly I'm sure that other events beyond the 4 I've got at the moment will be useful, so I'll keep a record of what people would find useful and add them when it becomes clear that they would be useful.

    Allan
This discussion has been closed.