@@ -144,34 +144,42 @@ listings_UI <- function(module_id) { # nolint
144144 DT :: dataTableOutput(ns(TBL $ TABLE_ID ), height = " 87vh" ),
145145 shiny :: tags [[" script" ]](shiny :: HTML(sprintf("
146146 $('#%s').on('init.dt', function(e, settings) {
147- const table_container_id = '%s';
148- const table = document.querySelector('#' + table_container_id + ' table.dataTable');
149- if (!table) return;
150-
151- const fixed_headers = table.querySelectorAll('thead tr')[0]?.querySelectorAll('th.dtfc-fixed-left');
152- const filters = table.querySelectorAll('thead tr')[1]?.querySelectorAll('td');
153-
154- if (!fixed_headers || !filters) return;
155- for(let idx = 0; idx < fixed_headers.length; ++idx){
156- const th = fixed_headers[idx];
157- const td = filters[idx];
158- if (!td) return;
159-
160- const computed_style = window.getComputedStyle(th);
161- const left = computed_style.left;
162- const zIndex = computed_style.zIndex;
163-
164- /* Character filters have an element with z-index 25 therefore we choose 26. This is an empirical founding as
165- I found no reference in the documentation therefore this magic number may change.
166- */
167- magic_z_index = 26;
168-
169- td.classList.add('dtfc-fixed-left');
170- td.style.position = 'sticky';
171- td.style.left = left;
172- td.style.zIndex = magic_z_index;
173- td.style.background = 'white';
174- }
147+ const table_container_id = '%s';
148+ const table = document.querySelector('#' + table_container_id + ' table.dataTable');
149+ if (!table) return;
150+
151+ // Make column filters scroll horizontally along the rest of the table rows
152+ const fixed_headers = table.querySelectorAll('thead tr')[0]?.querySelectorAll('th.dtfc-fixed-left');
153+ const filters = table.querySelectorAll('thead tr')[1]?.querySelectorAll('td');
154+
155+ if (!fixed_headers || !filters) return;
156+ for(let idx = 0; idx < fixed_headers.length; ++idx){
157+ const th = fixed_headers[idx];
158+ const td = filters[idx];
159+ if (!td) return;
160+
161+ const computed_style = window.getComputedStyle(th);
162+ const left = computed_style.left;
163+ const zIndex = computed_style.zIndex;
164+
165+ /* Character filters have an element with z-index 25 therefore we choose 26. This is an empirical finding as
166+ I found no reference in the documentation, therefore this magic number may change. */
167+ magic_z_index = 26;
168+
169+ td.classList.add('dtfc-fixed-left');
170+ td.style.position = 'sticky';
171+ td.style.left = left;
172+ td.style.zIndex = magic_z_index;
173+ td.style.background = 'white';
174+ }
175+
176+ // Extend width of factor search boxes to fit options (adapted from https://stackoverflow.com/a/76771419)
177+ let tds = table.querySelectorAll('td[data-type=\" factor\" ]');
178+ for(let i = 0; i < tds.length; i += 1){
179+ let td = tds[i];
180+ let dropdown_content = td.querySelector('div.selectize-dropdown-content');
181+ dropdown_content.setAttribute('style','width:max-content; background-color:white; border:1px solid rgba(0, 0, 0, 0.15); border-radius:4px; box-shadow:0 6px 12px rgba(0, 0, 0, 0.175);');
182+ }
175183 });" , ns(TBL $ TABLE_ID ), ns(TBL $ TABLE_ID ))))
176184 )
177185}
@@ -556,7 +564,12 @@ listings_server <- function(module_id,
556564 ),
557565 # FIXME: Update to use https://datatables.net/reference/option/layout
558566 dom = " Bfrtilp" , # Buttons, filtering, processing display element, table, information summary, length, pagination
559- fixedColumns = list (left = fixed_columns_left )
567+ fixedColumns = list (left = fixed_columns_left ),
568+ drawCallback = htmlwidgets :: JS("
569+ function(settings) {
570+ $('.dataTables_wrapper thead input[type=\" search\" ]').removeAttr('disabled');
571+ }
572+ " ) # Keep filtering enabled even for columns that have a unique value
560573 ),
561574 selection = " none"
562575 )
0 commit comments