1- function toggleFilterDropdown ( ) {
2- const dropdown = document . getElementById ( 'filter-dropdown' ) ;
3- const chevronUp = document . getElementById ( 'chevron-up' ) ;
4- const chevronDown = document . getElementById ( 'chevron-down' ) ;
1+ function toggleFilterDropdown ( tableId ) {
2+ const reportTable = document . getElementById ( tableId ) ;
3+ const dropdown = reportTable . querySelector ( '#filter-dropdown' ) ;
4+ const chevronUp = reportTable . querySelector ( '#chevron-up' ) ;
5+ const chevronDown = reportTable . querySelector ( '#chevron-down' ) ;
56
67 if ( dropdown && chevronUp && chevronDown ) {
78 dropdown . classList . toggle ( 'show' ) ;
@@ -10,10 +11,11 @@ function toggleFilterDropdown() {
1011 }
1112}
1213
13- function filterAndSearchTable ( ) {
14- const table = document . getElementById ( 'filterable-table-body' ) ;
15- const checkboxes = document . querySelectorAll ( '.filter-checkbox' ) ;
16- const searchInput = document . getElementById ( 'name-search-input' ) ;
14+ function filterAndSearchTable ( tableId ) {
15+ const reportTable = document . getElementById ( tableId ) ;
16+ const table = reportTable . querySelector ( '#filterable-table-body' ) ;
17+ const checkboxes = reportTable . querySelectorAll ( '.filter-checkbox' ) ;
18+ const searchInput = reportTable . querySelector ( '#name-search-input' ) ;
1719 const searchText = searchInput . value . trim ( ) . toLowerCase ( ) ;
1820 const filters = { } ;
1921 const rows = Array . from ( table ?. rows || [ ] ) ;
@@ -27,25 +29,30 @@ function filterAndSearchTable() {
2729 if ( cb . checked ) filters [ key ] . push ( cb . value ) ;
2830 } ) ;
2931
30- const noRowsMessage = document . getElementById ( ' no-rows-message') ;
32+ const noRowsMessage = reportTable . querySelector ( '# no-rows-message') ;
3133
3234 // NEW: If any filter group has zero selected values → show no rows
33- const activeFilterKeys = [ ...new Set ( [ ...checkboxes ] . map ( cb => cb . getAttribute ( 'data-filter-key' ) ) ) ] ;
35+ const activeFilterKeys = [ ...new Set ( [ ...checkboxes ] . map ( ( cb ) => cb . getAttribute ( 'data-filter-key' ) ) ) ] ;
3436 const hasEmptyGroup = activeFilterKeys . some ( ( key ) => ! filters [ key ] || filters [ key ] . length === 0 ) ;
3537 if ( hasEmptyGroup ) {
3638 // Hide all rows and show no match message
3739 rows . forEach ( ( row ) => {
3840 if ( row . id !== 'no-rows-message' ) row . style . display = 'none' ;
3941 } ) ;
4042 if ( noRowsMessage ) noRowsMessage . style . display = '' ;
41-
43+
4244 // Update visible row count
43- const visibleRows = Array . from ( table . rows ) . filter ( row => row . style . display !== 'none' && row . id !== 'no-rows-message' ) ;
44- document . getElementById ( 'row-count' ) . textContent = `Showing ${ visibleRows . length } record${ visibleRows . length !== 1 ? 's' : '' } ` ;
45+ const visibleRows = Array . from ( table . rows ) . filter (
46+ ( row ) => row . style . display !== 'none' && row . id !== 'no-rows-message'
47+ ) ;
48+ reportTable . querySelector ( '#row-count' ) . textContent = `Showing ${ visibleRows . length } record${
49+ visibleRows . length !== 1 ? 's' : ''
50+ } `;
4551 return ;
4652 }
4753
4854 // Otherwise, apply filters and search
55+ let processedClasses = new Set ( ) ;
4956 rows . forEach ( ( row ) => {
5057 if ( row . id === 'no-rows-message' ) return ;
5158
@@ -54,9 +61,7 @@ function filterAndSearchTable() {
5461 // Apply checkbox filters
5562 for ( const key of Object . keys ( filters ) ) {
5663 const selectedValues = filters [ key ] ;
57- const cell = Array . from ( row . cells ) . find (
58- ( c ) => c . getAttribute ( 'key' ) === key
59- ) ;
64+ const cell = Array . from ( row . cells ) . find ( ( c ) => c . getAttribute ( 'key' ) === key ) ;
6065 const cellValue = cell ?. getAttribute ( 'value' ) || '' ;
6166 if ( ! selectedValues . includes ( cellValue ) ) {
6267 show = false ;
@@ -73,7 +78,11 @@ function filterAndSearchTable() {
7378 }
7479 }
7580
76- row . style . display = show ? '' : 'none' ;
81+ // row.style.display = show ? '' : 'none';
82+ if ( ! processedClasses . has ( row . classList [ 0 ] ) ) {
83+ hideOrShowData ( reportTable , row . classList [ 0 ] , show ) ;
84+ processedClasses . add ( row . classList [ 0 ] ) ;
85+ }
7786 if ( show ) visibleRowCount ++ ;
7887 } ) ;
7988
@@ -82,10 +91,46 @@ function filterAndSearchTable() {
8291 }
8392
8493 // Update visible row count
85- const visibleRows = Array . from ( table . rows ) . filter ( row => row . style . display !== 'none' && row . id !== 'no-rows-message' ) ;
86- document . getElementById ( 'row-count' ) . textContent = `Showing ${ visibleRows . length } record${ visibleRows . length !== 1 ? 's' : '' } ` ;
94+ const visibleRows = Array . from ( table . rows ) . filter (
95+ ( row ) => row . style . display !== 'none' && row . id !== 'no-rows-message'
96+ ) ;
97+ reportTable . querySelector ( '#row-count' ) . textContent = `Showing ${ visibleRows . length } record${
98+ visibleRows . length !== 1 ? 's' : ''
99+ } `;
87100}
88101
102+ function hideOrShowData ( reportTable , rowClass , show ) {
103+ const rows = Array . from ( reportTable . querySelectorAll ( `.${ rowClass } ` ) ) ;
104+ rows . forEach ( ( row ) => {
105+ row . style . display = show ? '' : 'none' ;
106+ } ) ;
107+ }
108+
109+ document . addEventListener ( 'DOMContentLoaded' , ( ) => {
110+ document . querySelectorAll ( '.collapsible-content' ) . forEach ( ( collapsibleContent ) => {
111+ collapsibleContent . style . display = 'none' ;
112+ } ) ;
113+
114+ var coll = document . getElementsByClassName ( 'collapsible' ) ;
115+ var i ;
116+
117+ for ( i = 0 ; i < coll . length ; i ++ ) {
118+ coll [ i ] . addEventListener ( 'click' , function ( ) {
119+ this . classList . toggle ( 'active' ) ;
120+ var content = this . nextElementSibling ;
121+ if ( content . style . display === 'block' ) {
122+ content . style . display = 'none' ;
123+ } else {
124+ content . style . display = 'block' ;
125+ }
126+ } ) ;
127+ }
128+
129+ document . querySelectorAll ( '.rpt-table-container' ) . forEach ( ( tableContainer ) => {
130+ filterAndSearchTable ( tableContainer . id ) ;
131+ } ) ;
132+ } ) ;
133+
89134// Expose globally so HTML inline event handlers can access them
90135window . toggleFilterDropdown = toggleFilterDropdown ;
91136window . filterAndSearchTable = filterAndSearchTable ;
0 commit comments