Automatic initialization

The easiest way to get going is to include the datatableview.js (or datatableview.min.js) file bundled with the app:

<script type="text/javascript" charset="utf8" src="{{ STATIC_URL }}js/datatableview.js"></script>
    

This file introduces a global ``datatableview`` object that wraps the utilities and initialization function. A jQuery document.ready handler is also provided, which by default will initialize any .datatable elements on the page. Tables rendered into a template using the tools provided by this app will automatically meet this criteria.

To disable automatic initialization, you can include the script, and then set a property on the global object:

datatableview.auto_initialize = false;
    

To easily initialize datatables in Javascript, you can select your elements and send them to datatableview.initialize():

$(function(){
    datatableview.initialize($('.mytable'));
    
    // Or, if there are common options that should be given to all select elements,
    // you can specify them now.  data-* API attributes will override these options.
    var common_options = {};
    datatableview.initialize($('.mytable'), common_options);
});
    

Global dataTables.js default options can be specified normally, but if the page requires specific options for its datatable(s) and you are using automatic initialization (i.e., you didn't have an opportunity to set special options in advance), you can specify a global function hook that will be given the options object that will be sent to the dataTable constructor. Including this hook somewhere in the global namespace will ensure that you have control over custom options:

function confirm_global_datatable_options(options, datatable) {
    // "datatable" variable is the jQuery object, not the oTable, since it
    // hasn't been initialized yet.
    options.fnRowCallback = function(...){ ... };
    return options;
}
    

Note that this function hook is not required for the automatic initialization to work.