Module: JSE/Libs/datatable

DataTable Library

This is a wrapper library for the manipulation of jQuery DataTables. Use the "create" method with DataTable configuration to initialize a table on your page. All you need when using this library is an empty <table> element. Visit the official website of DataTables to check examples and other information about the plugin.

Official DataTables Website

Example - Create A New Instance

var tableApi = jse.libs.datatable.create($('#my-table'), {
     ajax: 'http://shop.de/table-data.php',
     columns: [
         { title: 'Name', data: 'name' defaultContent: '...' },
         { title: 'Email', data: 'email' },
         { title: 'Actions', data: null, orderable: false, defaultContent: 'Add | Edit | Delete' },
     ]
});

Example - Add Error Handler

jse.libs.datatable.error($('#my-table'), function(event, settings, techNote, message) {
     // Log error in the JavaScript console.
     console.log('DataTable Error:', message);
});
Source:

Methods

(static) ajaxComplete($target, callback)

Sets the callback method when ajax load of data is complete.

This method is useful for checking PHP errors or modifying the data before they are displayed to the server.

http://datatables.net/reference/event/xhr

Parameters:
Name Type Description
$target object

jQuery object for the target table.

callback object

Provide a callback method called with the "event", "settings", "techNote", "message" arguments (see provided link).

Source:

(static) create($target, configuration) → {object}

Creates a DataTable Instance

This method will create a new instance of datatable into a <table> element. It enables developers to easily pass the configuration needed for different and more special situations.

Parameters:
Name Type Description
$target object

jQuery object for the target table.

configuration object

DataTables configuration applied on the new instance.

Source:
Returns:

Returns the DataTable API instance (different from the jQuery object).

Type
object

(static) error($target, callback)

Sets the error handler for specific DataTable.

DataTables provide a useful mechanism that enables developers to control errors during data parsing. If there is an error in the AJAX response or some data are invalid in the JavaScript code you can use this method to control the behavior of the app and show or log the error messages.

http://datatables.net/reference/event/error

Parameters:
Name Type Description
$target object

jQuery object for the target table.

callback object

Provide a callback method called with the "event", "settings", "techNote", "message" arguments (see provided link).

Source:

(static) getGermanTranslation() → {object}

Returns the german translation of the DataTables

This method provides a quick way to get the language JSON without having to perform and AJAX request to the server. If you setup your DataTable manually you can set the "language" attribute with this method.

Source:
Returns:

Returns the german translation, must be the same as the "german.lang.json" file.

Type
object

(static) indexColumn($target, columnIndex)

Sets the table column to be displayed as an index.

This method will easily enable you to set a column as an index column, used for numbering the table rows regardless of the search, sorting and row count.

http://www.datatables.net/examples/api/counter_columns.html

Parameters:
Name Type Description
$target object

jQuery object for the target table.

columnIndex number

Zero based index of the column to be indexed.

Source: