@@ -73,6 +73,10 @@ class AboutCodeClueDataTable extends Controller {
7373
7474 // Get the column's filter select box
7575 const select = $ ( `select#clue-${ columnName } ` ) ;
76+ select . empty ( ) . append ( `<option value="">All</option>` ) ;
77+
78+ // Add the chart value options and select it.
79+ select . append ( `<option value="${ value } ">${ value } </option>` ) ;
7680 select . val ( value ) . change ( ) ;
7781 }
7882
@@ -101,6 +105,7 @@ class AboutCodeClueDataTable extends Controller {
101105 scrollX : true ,
102106 scrollResize : true ,
103107 deferRender : true ,
108+ initComplete : ( ) => this . _initComplete ( ) ,
104109 drawCallback : ( ) => this . _drawCallback ( ) ,
105110 buttons : [
106111 { // Do not allow the first column to be hidden
@@ -279,42 +284,94 @@ class AboutCodeClueDataTable extends Controller {
279284 } ) ;
280285 }
281286
287+ _initComplete ( ) {
288+ const pathCol = this . dataTable ( ) . columns ( 0 ) ;
289+
290+ const footer = $ ( pathCol . footer ( ) ) ;
291+ // keep the buttons horizontally aligned
292+ footer . css ( 'white-space' , 'nowrap' ) ;
293+
294+ const genFiltersButton = $ ( `<button id="gen-filters-button" type="button">Generate Filters</button>` ) ;
295+ const clearFiltersButton = $ ( `<button id="clear-filters-button" type="button">Clear Filters</button>` ) ;
296+
297+ footer . append ( genFiltersButton ) ;
298+ footer . append ( clearFiltersButton ) ;
299+
300+ this . dataTable ( ) . columns ( ) . every ( function ( columnIndex ) {
301+ const columnInfo = AboutCodeClueDataTable . TABLE_COLUMNS [ columnIndex ] ;
302+
303+ if ( 'skipFilter' in columnInfo && columnInfo . skipFilter ) {
304+ return ;
305+ }
306+
307+ const column = this ;
308+ const footer = $ ( column . footer ( ) ) ;
309+ const columnName = columnInfo . name ;
310+
311+ const select = $ ( `<select id="clue-${ columnName } "></select>` )
312+ . on ( 'change' , function ( ) {
313+ const val = $ ( this ) . val ( ) ;
314+ column
315+ . search ( val , false , false )
316+ . draw ( ) ;
317+ } ) ;
318+
319+ footer . append ( select ) ;
320+ } ) ;
321+ }
322+
282323 _drawCallback ( ) {
283324 $ ( '.dataTables_scrollBody' ) . scrollTop ( 0 ) ;
284325 }
285326
286- setColumnFilters ( ) {
327+ resetColumnFilters ( ) {
328+ $ . each ( AboutCodeClueDataTable . TABLE_COLUMNS , ( i , column ) => {
329+ const columnSelect = $ ( `select#clue-${ column . name } ` ) ;
330+ columnSelect . empty ( ) ;
331+ columnSelect . val ( '' ) ;
332+ this . dataTable ( )
333+ . column ( `${ column . name } :name` )
334+ . search ( '' , false , false ) ;
335+ } ) ;
336+ // clear the global search box
337+ this . dataTable ( ) . search ( '' ) . columns ( ) . search ( '' ) . draw ( ) ;
338+ }
339+
340+ genFilters ( ) {
341+ this . resetColumnFilters ( ) ;
287342 const that = this ;
288- const pathCol = this . dataTable ( ) . columns ( 0 ) ;
289343
290- // Add a select element to each column's footer
291344 this . dataTable ( ) . columns ( ) . every ( function ( columnIndex ) {
292345 const columnInfo = AboutCodeClueDataTable . TABLE_COLUMNS [ columnIndex ] ;
346+ const currentColumn = that . dataTable ( ) . columns ( columnIndex ) ;
293347
294348 if ( 'skipFilter' in columnInfo && columnInfo . skipFilter ) {
295349 return ;
296350 }
297351
352+ // skip columns that are not currently visible
353+ if ( currentColumn . visible ( ) [ 0 ] === false ) {
354+ return ;
355+ }
356+
298357 const column = this ;
299358 const footer = $ ( column . footer ( ) ) ;
300359 const columnName = columnInfo . name ;
301360
302361 footer . empty ( ) ;
303- const select = $ ( `<select id="clue-${ columnName } "></select>` )
362+
363+ const select = $ ( '#clue-' + columnName )
304364 . empty ( )
305- . appendTo ( footer )
306365 . on ( 'change' , function ( ) {
307366 const val = $ ( this ) . val ( ) ;
308367 column
309368 . search ( val , false , false )
310369 . draw ( ) ;
311370 } ) ;
312371
313- const currPath = pathCol . search ( ) [ 0 ] ;
372+ const currPath = that . _selectedPath ;
314373 const where = { path : { $like : `${ currPath } %` } } ;
315-
316- where [ columnName ] = { $ne : null } ;
317-
374+
318375 that . db ( ) . sync . then ( ( db ) => db . FlatFile . findAll ( {
319376 attributes : [
320377 Sequelize . fn ( 'TRIM' , Sequelize . col ( columnName ) ) ,
@@ -342,6 +399,7 @@ class AboutCodeClueDataTable extends Controller {
342399 select . append ( `<option value="${ filterValue } ">${ filterValue } </option>` ) ;
343400 } ) ;
344401 } ) ;
402+ footer . append ( select ) ;
345403 } ) ;
346404 }
347405
0 commit comments