Beartropy Tables
Laravel Excel Integration
Beartropy Tables integrates seamlessly with Laravel Excel. If installed, the component automatically detects it and adds "Export to Excel" and "Export to CSV" options to your table's settings dropdown.
To install Laravel Excel, run:
Once installed, the export features work out-of-the-box using the Data trait's methods. You can customize the export logic by overriding the exportToExcel or exportToCsv methods in your component if needed.
Data Trait Methods
The Data trait provides comprehensive methods for accessing your table's dataset in various states—raw, filtered, or selected.
Data Accessors
All Data
getAllOriginalData()- Returns the complete dataset with raw values from the database.getAllData()- Returns the complete dataset including any partial modifications or formatting.
Filtered Data
getAfterFiltersOriginalData()- Returns data matching active filters (search, custom filters) with raw values.getAfterFiltersData()- Returns data matching active filters with formatting applied.
Selected Data
getSelectedOriginalData()- Returns only the user-selected rows with raw values.getSelectedData()- Returns only the user-selected rows with formatting applied.
Row Retrieval
getRowByID($id)- Retrieves a single row object matching the given ID.
Export Utilities
exportToClipboard($collection, $tabs = true)- Copies the given collection to the clipboard as CSV/TSV. Set$tabsto false for CSV format.
1// Original Data (Raw Values) 2$this->getAllOriginalData(); 3$this->getAfterFiltersOriginalData(); 4$this->getSelectedOriginalData(); 5 6// Formatted Data (With Accessors/Mutators) 7$this->getAllData(); 8$this->getAfterFiltersData(); 9$this->getSelectedData();10 11// Single Row12$this->getRowByID($id);13 14// Export15$this->exportToClipboard($collection, $tabs = true);
Bulk Trait Methods
The Bulk trait manages checkbox selection states.
Bulk Selection
getSelectedRows()
Returns an array containing the IDs of all currently selected rows. This is useful for performing bulk actions on a specific set of records.
1// Get ID array of selected rows2$this->getSelectedRows();