PluginProbe
Posts Table with Search & Sort / 1.3.5
Posts Table with Search & Sort v1.3.5
1.4.13 trunk 1.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.2 1.3 1.3.1 1.3.1-v2 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 All 40 releases
posts-data-table / assets / js / posts-data-table.js

posts-data-table.js in Posts Table with Search & Sort 1.3.5, at assets/js/posts-data-table.js

63 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1
2 ( function( $ ) {
3
4 $( document ).ready( function() {
5
6 let tables = $( '.posts-data-table' );
7
8 const adminBar = $( '#wpadminbar' ),
9 clickFilterColumns = ['categories', 'tags', 'author'];
10
11 tables.each( function() {
12 let $table = $( this ),
13 config = {
14 responsive: true,
15 processing: true // display 'processing' indicator when loading
16 };
17
18 // Set language - defaults to English if not specified
19 if ( ( typeof posts_data_table !== 'undefined' ) && posts_data_table.langurl ) {
20 config.language = { url: posts_data_table.langurl };
21 }
22
23 // Initialise DataTable
24 let table = $table.DataTable( config );
25
26 // If scroll offset defined, animate back to top of table on next/previous page event
27 $table.on( 'page.dt', function() {
28 if ( $( this ).data( 'scroll-offset' ) !== false ) {
29 let tableOffset = $( this ).parent().offset().top - $( this ).data( 'scroll-offset' );
30
31 if ( adminBar.length ) { // Adjust offset for WP admin bar
32 let adminBarHeight = adminBar.outerHeight();
33 tableOffset -= ( adminBarHeight ? adminBarHeight : 32 );
34 }
35
36 $( 'html,body' ).animate( { scrollTop: tableOffset }, 300 );
37 }
38 } );
39
40 // If 'search on click' enabled then add click handler for links in category, author and tags columns.
41 // When clicked, the table will filter by that value.
42 if ( $table.data( 'click-filter' ) ) {
43 $table.on( 'click', 'a', function() {
44 let $link = $( this ),
45 idx = table.cell( $link.closest( 'td' ).get( 0 ) ).index().column, // get the column index
46 header = table.column( idx ).header(), // get the header cell
47 columnName = $( header ).data( 'name' ); // get the column name from header
48
49 // Is the column click filterable?
50 if ( -1 !== clickFilterColumns.indexOf( columnName ) ) {
51 table.search( $link.text() ).draw();
52 return false;
53 }
54
55 return true;
56 } );
57 }
58
59 } ); // each table
60
61 } ); // end document.ready
62
63 } )( jQuery );