| 4 |
lars |
1 |
/**
|
|
|
2 |
* It can be quite useful to jump straight to a page which contains a certain
|
|
|
3 |
* piece of data (a user name for example). This plug-in provides exactly that
|
|
|
4 |
* ability, searching for a given data parameter from a given column and
|
|
|
5 |
* immediately shifting the paging of the table to jump to that point.
|
|
|
6 |
*
|
|
|
7 |
* If multiple data points match the requested data, the paging will be shifted
|
|
|
8 |
* to show the first instance. If there are no matches, the paging will not
|
|
|
9 |
* change.
|
|
|
10 |
*
|
|
|
11 |
* Note that unlike the core DataTables API methods, this plug-in will
|
|
|
12 |
* automatically call `dt-api draw()` to redraw the table with the current page
|
|
|
13 |
* shown.
|
|
|
14 |
*
|
|
|
15 |
* @name page.JumpToData()
|
|
|
16 |
* @summary Jump to a page by searching for data from a column
|
|
|
17 |
* @author [Allan Jardine](http://sprymedia.co.uk)
|
|
|
18 |
* @requires DataTables 1.10+
|
|
|
19 |
*
|
|
|
20 |
* @param {*} data Data to search for
|
|
|
21 |
* @param {integer} column Column index
|
|
|
22 |
* @returns {Api} DataTables API instance
|
|
|
23 |
*
|
|
|
24 |
* @example
|
|
|
25 |
* var table = $('#example').DataTable();
|
|
|
26 |
* table.page.jumpToData( "Allan Jardine", 0 );
|
|
|
27 |
*/
|
|
|
28 |
|
|
|
29 |
jQuery.fn.dataTable.Api.register( 'page.jumpToData()', function ( data, column ) {
|
|
|
30 |
var pos = this.column(column, {order:'current'}).data().indexOf( data );
|
|
|
31 |
|
|
|
32 |
if ( pos >= 0 ) {
|
|
|
33 |
var page = Math.floor( pos / this.page.info().length );
|
|
|
34 |
this.page( page ).draw( false );
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
return this;
|
|
|
38 |
} );
|