@@ -5,13 +5,15 @@ import "../node_modules/tabulator-tables/dist/css/tabulator_bootstrap5.min.css";
55import {
66 CellComponent ,
77 EditModule ,
8+ Filter ,
89 FilterModule ,
910 FormatModule ,
1011 InteractionModule ,
1112 PopupModule ,
1213 ResizeColumnsModule ,
1314 ResizeTableModule ,
1415 ResponsiveLayoutModule ,
16+ Sorter ,
1517 SortModule ,
1618 Tabulator ,
1719 TooltipModule ,
@@ -282,6 +284,25 @@ async function main() {
282284
283285 console . log ( data [ 0 ] ) ;
284286
287+ const qs = new URLSearchParams ( window . location . search ) ;
288+ const sort : Sorter [ ] = [ { column : "code" , dir : "asc" } ] ;
289+ const filters : Filter [ ] = [ ] ;
290+ if ( qs ) {
291+ ;
292+ for ( const [ key , value ] of qs . entries ( ) ) {
293+ if ( key == "sort" ) {
294+ sort [ 0 ] . column = value ;
295+ continue ;
296+ }
297+ if ( key == "dir" ) {
298+ sort [ 0 ] . dir = ( value == "desc" ) ? "desc" : "asc" ;
299+ }
300+ if ( key && value ) {
301+ filters . push ( { field : key , type : "=" , value : value } ) ;
302+ }
303+ }
304+ }
305+
285306 Tabulator . registerModule ( [
286307 EditModule ,
287308 FilterModule ,
@@ -299,6 +320,20 @@ async function main() {
299320 autoResize : true ,
300321 data,
301322 columns : [
323+ {
324+ cellClick : ( e , cell ) => {
325+ const data = cell . getRow ( ) . getData ( ) ;
326+ e . preventDefault ( ) ;
327+ e . stopPropagation ( ) ;
328+ table . alert ( `${ data . name } (U+${ data . code } ) copied to clipboard` ) ;
329+ setTimeout ( ( ) => table . clearAlert ( ) , 1000 ) ;
330+ navigator . clipboard . writeText ( data . example ) ;
331+ } ,
332+ field : "" ,
333+ formatter : ( ) => `<img src="/images/icons/clipboard.svg" alt="Copy to clipboard" height="16">` ,
334+ headerSort : false ,
335+ title : "" ,
336+ } ,
302337 {
303338 field : "example" ,
304339 headerFilter : "input" ,
@@ -312,6 +347,7 @@ async function main() {
312347 return headerValue == rowValue ;
313348 } ,
314349 headerHozAlign : "center" ,
350+ headerSort : false ,
315351 hozAlign : "center" ,
316352 responsive : 0 ,
317353 title : "Character" ,
@@ -386,6 +422,9 @@ async function main() {
386422 } ,
387423 headerFilter : "input" ,
388424 headerFilterFunc : filterName ,
425+ headerPopup : `Use <code>^</code> to search at the beginning<br/>Use <code>/regex/</code> to search with a regular expression` ,
426+ headerPopupIcon :
427+ '<span class="badge rounded-pill text-bg-primary">?</span>' ,
389428 responsive : 0 ,
390429 //sorter: "string",
391430 width : 375 ,
@@ -400,7 +439,7 @@ async function main() {
400439 } ,
401440 ] ,
402441 height : "100%" ,
403- // initialHeaderFilter: [{ field: "ar21", type: "=", value: true }] ,
442+ initialHeaderFilter : filters ,
404443 initialSort : [ { column : "code" , dir : "asc" } ] ,
405444 layout : "fitDataStretch" ,
406445 placeholder : "No matches" ,
@@ -416,11 +455,27 @@ async function main() {
416455 var el = document . getElementById ( "rowcount" ) ;
417456 if ( filters && filters . length > 0 ) {
418457 el ! . innerHTML = `Rows: ${ rows . length . toLocaleString ( ) } of ${ data . length . toLocaleString ( ) } ` ;
458+ var qs = filters
459+ . map ( f => `${ encodeURIComponent ( f . field ) } =${ encodeURIComponent ( f . value ) } ` )
460+ . join ( "&" ) ;
461+ qs += `&sort=${ table . getSorters ( ) [ 0 ] ?. column . getField ( ) } &dir=${ table . getSorters ( ) [ 0 ] ?. dir } ` ;
462+ window . history . replaceState ( null , "" , "?" + qs ) ;
419463 } else {
420464 el ! . innerHTML = `Rows: ${ data . length . toLocaleString ( ) } ` ;
421465 }
422466 } ) ;
423467
468+ table . on ( "dataSorted" , function ( sorters , rows ) {
469+ var qs = `sort=${ sorters [ 0 ] ?. column . getField ( ) } &dir=${ sorters [ 0 ] ?. dir } ` ;
470+ const filters = table . getFilters ( true ) ;
471+ if ( filters && filters . length > 0 ) {
472+ qs = filters
473+ . map ( f => `${ encodeURIComponent ( f . field ) } =${ encodeURIComponent ( f . value ) } ` )
474+ . join ( "&" ) + "&" + qs ;
475+ }
476+ window . history . replaceState ( null , "" , "?" + qs ) ;
477+ } ) ;
478+
424479 document . getElementById ( "loading" ) ! . style . display = "none" ;
425480 document . getElementById ( "achtable" ) ! . style . display = "block" ;
426481}
0 commit comments