Improved tables
$('.my-table').iTable();
Used for prefixing classes, default itable
$('.my-table').iTable({ namespace: 'custom-table' });
A callback function to filter the table
$('.my-table').iTable({
matcher: function (query, candidate) {
return candidate.indexOf(query) > -1;
}
});
Defines which columns are sortable, default true
// sort all columns
$('.my-table-1').iTable({ sortable: true });
// disable sorting
$('.my-table-1').iTable({ sortable: false });
// only sort first column
$('.my-table-1').iTable({ sortable: [0] });
Override options globally by modifying the $.iTableDefaults object
$.iTableDefaults.namespace = 'the-table';
Element | Attribute | Description |
---|---|---|
td | data-search | Specifies a different search value for the column |
td | data-sort | Specifies a different sorting value for the column |
Add a row to the end of the table
$('.my-table').iTable().append([1, 'Marco']);
Add a row to the beginning of the table
$('.my-table').iTable().prepend([2, 'Omar']);
Return a specific row, zero-indexed
$('.my-table').iTable().row(0).addClass('me');
Return all rows
$('.my-table').iTable().rows().click(function () {
// @TODO implement click handler
});
Remove all rows in the table
$('.my-table').iTable().empty();
Filter the table rows
$('.my-table').iTable().search('marco');
Sort rows by specific column and direction, zero-indexed
$('.my-table').iTable().sort(0, 'asc');
Return current sort
$('.my-table').iTable().sort().index; // 0
$('.my-table').iTable().sort().direction; // asc
Return the quantity of rows in the table
$('.my-table').iTable().size();
Call .iTable() as many times as you want, it's going to be instantiated only once.
The plugin add some useful classes for styling. Check theme.css for an example.