order.listener()
Add an ordering listener to an element, for a given column.
Description
This method provides the ability to attach ordering listeners to any DOM element on the page. This is the same method as DataTables uses internally for the ordering listeners which are attached to the header cells for each column, and as such provides the same functionality (i.e. click to order, shift click to multi-column order etc).
Although not a common method to be used, it can be useful for allowing sorting to be triggered externally from the table (equally order()
and its columns counterparts could also be used).
Note that unlike order()
and columns().order()
when the ordering listener attached by this function is activated, it will cause the table to redraw automatically - i.e. there is no need to call draw()
.
Type
function order.listener( node, column, callback )
- Description:
Attach an ordering listener to a specified element
- Parameters:
Name Type Optional 1 node
No Selector / node to pick the elements on the page to which the ordering listener should be attached. This can be a DOM node, a jQuery collection of nodes or a jQuery selector string.
2 column
No Column data index of the column that that a click on this node will order the table upon
3 callback
Yes - default: Callback function that is executed whenever the ordering performed by the listener is completed, when the listener is activated. No parameters are passed in and no return is expected.
- Returns:
DataTables API instance with the current order in the result set
Example
Sort on column 1, when '#sorter' element is clicked upon:
var table = new DataTable('#myTable');
table.order.listener('#sorter', 1);
Related
The following options are directly related and may also be useful in your application development.