@@ -57,19 +57,7 @@ export const tabulatorPlugin: Plugin<TabulatorSpec> = {
5757 }
5858
5959 const spec : TabulatorSpec = specReview . approvedSpec ;
60- const buttons = spec . editable
61- ? `<div class="tabulator-buttons">
62- <button type="button" class="tabulator-add-row">Add Row</button>
63- <button type="button" class="tabulator-reset">Reset</button>
64- </div>`
65- : '' ;
66-
67- container . innerHTML = `<div class="tabulator-parent">
68- <div class="tabulator-nested"></div>
69- ${ buttons }
70- </div>` ;
71- const nestedDiv = container . querySelector ( '.tabulator-nested' ) ;
72-
60+
7361 if ( ! Tabulator && index === 0 ) {
7462 errorHandler ( new Error ( 'Tabulator not found' ) , pluginName , index , 'init' , container ) ;
7563 continue ;
@@ -99,6 +87,29 @@ export const tabulatorPlugin: Plugin<TabulatorSpec> = {
9987 delete options . selectableRows ; //remove selectableRows from options if editable
10088 }
10189
90+ // Build all buttons in one HTML string
91+ let buttonsHtml = '' ;
92+ if ( spec . editable || selectableRows ) {
93+ buttonsHtml = '<div class="tabulator-buttons">' ;
94+
95+ if ( spec . editable ) {
96+ buttonsHtml += '<button type="button" class="tabulator-add-row">Add Row</button>' ;
97+ buttonsHtml += '<button type="button" class="tabulator-reset">Reset</button>' ;
98+ }
99+
100+ if ( selectableRows ) {
101+ buttonsHtml += '<button type="button" class="tabulator-invert-selection">Invert Selection</button>' ;
102+ }
103+
104+ buttonsHtml += '</div>' ;
105+ }
106+
107+ container . innerHTML = `<div class="tabulator-parent">
108+ <div class="tabulator-nested"></div>
109+ ${ buttonsHtml }
110+ </div>` ;
111+ const nestedDiv = container . querySelector ( '.tabulator-nested' ) ;
112+
102113 const table = new Tabulator ( nestedDiv as HTMLElement , options ) ;
103114
104115 const tabulatorInstance : TabulatorInstance = {
@@ -211,6 +222,11 @@ export const tabulatorPlugin: Plugin<TabulatorSpec> = {
211222 }
212223 table . setColumns ( columns ) ;
213224
225+ // Select all rows by default if selectableRows is enabled
226+ if ( selectableRows && data . length > 0 ) {
227+ table . selectRow ( 'all' ) ;
228+ }
229+
214230 if ( tabulatorInstance . listening ) {
215231 outputData ( ) ;
216232 }
@@ -242,6 +258,30 @@ export const tabulatorPlugin: Plugin<TabulatorSpec> = {
242258 }
243259 }
244260
261+ if ( selectableRows ) {
262+ const invertBtn = container . querySelector ( '.tabulator-invert-selection' ) as HTMLButtonElement ;
263+
264+ if ( invertBtn ) {
265+ invertBtn . onclick = ( ) => {
266+ const allRows = table . getRows ( ) ;
267+ const selectedRows = table . getSelectedRows ( ) ;
268+
269+ // Create a set of selected row IDs for quick lookup
270+ const selectedRowIds = new Set ( selectedRows . map ( row => row . getIndex ( ) ) ) ;
271+
272+ // Invert selection: select unselected rows, deselect selected rows
273+ allRows . forEach ( row => {
274+ const rowId = row . getIndex ( ) ;
275+ if ( selectedRowIds . has ( rowId ) ) {
276+ row . deselect ( ) ;
277+ } else {
278+ row . select ( ) ;
279+ }
280+ } ) ;
281+ } ;
282+ }
283+ }
284+
245285 return {
246286 ...tabulatorInstance ,
247287 initialSignals,
0 commit comments