selectAllRows() API

The selectAllRows() method has been added to the TablixJS Table class to provide a convenient way to select all currently visible/filtered rows.

Method Signature

table.selectAllRows(): number

Parameters

None

Returns

Behavior

Events

The method triggers a custom selectAll event with the following payload:

{
  selectedIds: string[],    // Array of selected row IDs
  selectedData: object[],   // Array of selected row data objects  
  count: number            // Number of rows selected
}

Usage Examples

Basic Usage

// Select all visible rows
const selectedCount = table.selectAllRows();
console.log(`Selected ${selectedCount} rows`);

With Event Listener

// Listen for selectAll events
table.eventManager.on('selectAll', (event) => {
  console.log(`Selected ${event.count} rows:`, event.selectedData);
});

// Trigger selection
table.selectAllRows();

With Keyboard Shortcut

document.addEventListener('keydown', (e) => {
  if (e.key === 'a' && (e.ctrlKey || e.metaKey)) {
    e.preventDefault();
    table.selectAllRows();
  }
});

Respecting Filters

// Apply a filter first
await table.applyFilter('department', { 
  type: 'value', 
  values: ['Engineering'] 
});

// Select all filtered rows (only Engineering employees)
const count = table.selectAllRows();
console.log(`Selected ${count} Engineering employees`);

Error Handling

The method includes built-in warnings for common issues:

Compatibility

Migration Notes

If you were previously using a custom selectAllRows() implementation like:

// Old custom implementation
function selectAllRows() {
  const allData = table.getData();
  const allIds = allData.map(row => row.id.toString());
  table.selectRows(allIds);
}

You can now replace it with the built-in method:

// New built-in API
const count = table.selectAllRows();

The built-in method provides better error handling, event triggering, and return value for improved developer experience.