| 
147 | 147 |             // make sure all other main checkboxes have the same checked status  | 
148 | 148 |             mainCheckboxes.forEach(elem => elem.checked = checkbox.checked);  | 
149 | 149 | 
  | 
 | 150 | +            // Ensure buttons are updated after mass checkbox changes  | 
 | 151 | +            window.crud.enableOrDisableBulkButtons(tableId);  | 
 | 152 | +
  | 
150 | 153 |             event.stopPropagation();  | 
151 | 154 |         };  | 
152 | 155 |     });  | 
 | 
174 | 177 |         const hasBulkActions = tableElement.getAttribute('data-has-bulk-actions') === 'true' ||   | 
175 | 178 |                           tableElement.getAttribute('data-has-bulk-actions') === '1';  | 
176 | 179 |           | 
177 |  | -        // Find all bulk buttons  | 
178 |  | -        const tableWrapper = document.getElementById(`${tableId}_wrapper`);  | 
179 |  | -        const bulkButtons = tableWrapper.querySelectorAll('.bulk-button');  | 
 | 180 | +        // Find all bulk buttons - search in table-specific locations first  | 
 | 181 | +        let bulkButtons = [];  | 
 | 182 | +          | 
 | 183 | +        const tableSpecificContainers = [  | 
 | 184 | +            document.querySelector(`#bottom_buttons_${tableId}`),  | 
 | 185 | +            document.querySelector(`#datatable_button_stack_${tableId}`)  | 
 | 186 | +        ];  | 
 | 187 | +          | 
 | 188 | +        for (const container of tableSpecificContainers) {  | 
 | 189 | +            if (container) {  | 
 | 190 | +                const containerButtons = container.querySelectorAll('.bulk-button');  | 
 | 191 | +                if (containerButtons.length > 0) {  | 
 | 192 | +                    bulkButtons = containerButtons;  | 
 | 193 | +                    break;  | 
 | 194 | +                }  | 
 | 195 | +            }  | 
 | 196 | +        }  | 
 | 197 | +          | 
 | 198 | +        if (bulkButtons.length === 0) {  | 
 | 199 | +            const tableWrapper = document.getElementById(`${tableId}_wrapper`);  | 
 | 200 | +            if (tableWrapper) {  | 
 | 201 | +                bulkButtons = tableWrapper.querySelectorAll('.bulk-button');  | 
 | 202 | +            }  | 
 | 203 | +        }  | 
180 | 204 |           | 
181 | 205 |         // Update all buttons based on selection state  | 
182 | 206 |         bulkButtons.forEach(btn => {  | 
183 | 207 |             if (hasSelectedItems) {  | 
184 | 208 |                 btn.classList.remove('disabled');  | 
 | 209 | +                btn.removeAttribute('disabled');  | 
185 | 210 | 
  | 
186 |  | -            if (btn.hasAttribute('onclick') && !btn._onclickReplaced) {  | 
 | 211 | +                if (btn.hasAttribute('onclick') && !btn._onclickReplaced) {  | 
187 | 212 |                     const originalOnclick = btn.getAttribute('onclick');  | 
188 | 213 |                       | 
189 | 214 |                     // Remove the original onclick attribute  | 
 | 
216 | 241 |                 }  | 
217 | 242 |             } else {  | 
218 | 243 |                 btn.classList.add('disabled');  | 
 | 244 | +                btn.setAttribute('disabled', 'disabled');  | 
219 | 245 |             }  | 
220 | 246 |         });  | 
221 | 247 |     }  | 
 | 
0 commit comments