@@ -3,6 +3,7 @@ import * as List from "list.js";
33var dummy = new List ( ) ;
44
55function text_sort ( a , b , options ) {
6+ // sort by text content
67 return dummy . utils . naturalSort . caseInsensitive ( $ ( $ . parseHTML ( a . values ( ) [ options . valueName ] ) )
78 . text ( )
89 . trim ( )
@@ -21,11 +22,13 @@ $(document)
2122 var header_row = $ ( table )
2223 . find ( "thead > tr:first" ) ;
2324
25+ // get field classes from first thead row
2426 var fields = $ ( header_row )
2527 . find ( "*" )
2628 . map ( function ( ) {
2729 return $ ( this )
28- . attr ( "data-sort" ) ;
30+ . attr ( "data-sort" ) ? $ ( this )
31+ . attr ( "data-sort" ) : "" ;
2932 } )
3033 . toArray ( ) ;
3134
@@ -45,6 +48,7 @@ $(document)
4548 header_row . addClass ( "visually-hidden" ) ;
4649 }
4750
51+ // HTML for the search widget
4852 var searcher = $ . parseHTML ( `
4953 <div class="input-group my-3">
5054 <input type="search" class="search form-control" placeholder="Search"/>
@@ -62,13 +66,46 @@ $(document)
6266 var reset_search = $ ( searcher )
6367 . children ( "button.search-reset" ) ;
6468
69+ // var pager = $.parseHTML(`
70+ // <nav aria-label="Pagination control" class="visually-hidden">
71+ // <ul class="pagination"></ul>
72+ // </nav>`);
73+
74+ // $(table)
75+ // .after(pager);
76+
6577 var list_instance = [ ] ;
6678 var internal_table = [ ] ;
6779
80+ var pagination = $ ( table )
81+ . children ( "tbody" )
82+ . length == 1 ;
83+
84+ // list.js cannot deal with tables with multiple tbodys,
85+ // so maintain separate internal "tables" for
86+ // sorting/searching and update the DOM based on them
6887 $ ( table )
6988 . children ( "tbody" )
7089 . addClass ( "list" )
7190 . each ( function ( ) {
91+ // add the required classes to the cells
92+ $ ( this )
93+ . children ( "tr" )
94+ . each ( function ( ) {
95+ $ ( this )
96+ . children ( "th, td" )
97+ . each ( ( i , e ) => {
98+ $ ( e )
99+ . addClass ( fields [ i ] ) ;
100+ if ( fields [ i ] == "date" ) {
101+ // magic
102+ $ ( e )
103+ . addClass ( "text-end" ) ;
104+ }
105+ } ) ;
106+ } ) ;
107+
108+ // create the internal table and add list.js to them
72109 var thead = $ ( this )
73110 . siblings ( "thead:first" )
74111 . clone ( ) ;
@@ -80,12 +117,26 @@ $(document)
80117 . clone ( )
81118 . empty ( )
82119 . removeClass ( "tablesorter" )
120+ . wrap ( "<div id='abc'></div" )
83121 . append ( thead , tbody ) ;
84122
85123 internal_table . push ( parent ) ;
86124
125+ // if (pagination) {
126+ // console.log("Enabling pager.");
127+ // $(pager)
128+ // .removeClass("visually-hidden");
129+ // pagination = {
130+ // item: '<li class="page-item"><a class="page-link" href="#"></a></li>'
131+ // };
132+ // }
133+
87134 list_instance . push (
88- new List ( parent [ 0 ] , { valueNames : fields } ) ) ;
135+ new List ( parent [ 0 ] , {
136+ valueNames : fields ,
137+ // pagination: pagination,
138+ // page: 10
139+ } ) ) ;
89140 } ) ;
90141
91142 reset_search . on ( "click" , function ( ) {
0 commit comments