Please wait...

Front-end callbacks

wpDataTable Front-end callbacksJavaScript hooks for customizing the table layout

The front-end (JS) part of wpDataTables plays a significant role in the plugin’s functionality. Generally, front-end rendering is done by the DataTables jQuery plugin, but wpDataTables introduces some callbacks of its own.

All wpDataTables existing on the page are reflected in the global JavaScript object called ‘wpDataTables‘. If you check this variable in the JS developer console you will see the wpDataTables as properties of this object:

addOnDrawCallback( function callback() );

To assign a simple function to the redraw event we can use e.g. this jQuery snippet:

<script type="text/javascript">
jQuery(window).load(function(){
  wpDataTables.table_1.addOnDrawCallback(
  function(){
    jQuery('#callback_msg_container').append('Callback triggered!');
   })
});
</script>

The snippet is live on this page – try to sort, filter, or switch pages in the table to see how it works!

If we check the developer console, we can see that this wpDataTable can be accessed by means of a global variable:

wpDataTables.table_1

Here’s a wpDataTable:

 

Never miss new features!

Join 3000+ newsletter subscribers

Never miss notifications about new cool features, promotions, giveaways or freebies - subscribe to our newsletter! We send about one mail per month, and do our best to keep our announcements interesting.

By clicking "subscribe" you consent that the information you provide via this form will be securely processed and stored in compliance with EU privacy laws (GDPR).
This  information will be used to send you newsletters as well as pre-populate any forms, should you want to edit your newsletter preferences.
You can always use this link to unsubscribe from the newsletter. You can see our Privacy Policy here.