Skip to content

Commit

Permalink
New - experimental: Add custom events into DataTables - the events av…
Browse files Browse the repository at this point in the history
…ailable are "draw", "filter", "sort", "page" and "xhr". These are very useful for knowing when these actions happen and binding an action to them. Useful for plugin developers and developers using DataTables both. Note that it would be possible to put in a _LOT_ more custom events ("predraw" etc) which is why this feature is currently considered experimental. It will not be documented in the DataTables documentation until this has stabilised (likely 1.9 or 2.0) and a scheme has been fully confirmed for these events, but I want to include them now to see if and how they are used by developers to see them or talk to me (as this has been asked for a few times). I'm also slightly concerned about the overhead that would be generated if there were custom events for everything.
  • Loading branch information
Allan Jardine committed Sep 10, 2011
1 parent 31ccd95 commit 8a8ca1e
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion media/js/jquery.dataTables.js
Original file line number Diff line number Diff line change
Expand Up @@ -1337,7 +1337,10 @@
settings.jqXHR = $.ajax( {
"url": url,
"data": data,
"success": callback,
"success": function (json) {
$(settings.oInstance).trigger('xhr', json);
callback( json );
},
"dataType": "json",
"cache": false,
"error": function (xhr, error, thrown) {
Expand Down Expand Up @@ -3388,6 +3391,7 @@
{
oSettings.aoDrawCallback[i].fn.call( oSettings.oInstance, oSettings );
}
$(oSettings.oInstance).trigger('draw');

/* Draw is complete, sorting and filtering must be as well */
oSettings.bSorted = false;
Expand Down Expand Up @@ -4345,6 +4349,7 @@

/* Tell the draw function we have been filtering */
oSettings.bFiltered = true;
$(oSettings.oInstance).trigger('filter');

/* Redraw the table */
oSettings._iDisplayStart = 0;
Expand Down Expand Up @@ -4730,6 +4735,7 @@

/* Tell the draw function that we have sorted the data */
oSettings.bSorted = true;
$(oSettings.oInstance).trigger('sort');

/* Copy the master data into the draw array and re-draw */
if ( oSettings.oFeatures.bFilter )
Expand Down Expand Up @@ -5123,6 +5129,7 @@
{
_fnLog( oSettings, 0, "Unknown paging action: "+sAction );
}
$(oSettings.oInstance).trigger('page');

return iOldStart != oSettings._iDisplayStart;
}
Expand Down

3 comments on commit 8a8ca1e

@mikhailov
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you, it's very useful

@DataTables
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent - good to hear :-). Personally I love this as well, but want to draw up a proper plan to implement it well and with enough flexibility that it can do all that is needed, but with as little overhead as possible. But it's a start... :-)

@mikhailov
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it's really really good feature, because I had to rewrite Datatables internals (_fnFeatureHtmlFilter) to handle selectbox change event to trigger Datatables redraw. I'm looking forward for #trigger functionality across the whole engine. thank you again!

Please sign in to comment.