BeartropyTable
class BeartropyTable extends Component
Base Table Component.
This component serves as the foundation for all Beartropy Tables. It integrates various traits to provide functionality such as sorting, filtering, pagination, and bulk actions.
Traits
Properties
| bool | $has_bulk | Indicates if the table has bulk actions enabled. |
from Bulk |
| array<int|string> | $yat_selected_checkbox | Array of selected row IDs for bulk actions. |
from Bulk |
| bool | $selectAll | Controls the "Select All" checkbox state. |
from Bulk |
| bool | $pageSelected | Indicates if the current page is selected. |
from Bulk |
| bool | $allSelected | Indicates if all data (across all pages) is selected. |
from Bulk |
| string | $cachePrefix | Cache prefix used in the Data trait scope. |
from Data |
| int|null | $cacheTimeStamp | Timestamp of the cached data. |
from Cache |
| string | $column_id | The unique identifier column for rows. |
from Columns |
| string | $custom_column_id | A custom column ID override. |
from Columns |
| Collection|null | $columns | Collection of defined columns. |
from Columns |
| bool | $show_column_toggle | Whether to show the column toggle dropdown. |
from Columns |
| bool | $column_toggle_dd_status | Status of the column toggle dropdown (open/closed). |
from Columns |
| bool | $hasMobileCollapsedColumns | Indicates if there are columns collapsed on mobile view. |
from Columns |
| array | $mobileCollapsedColumns | Array of columns that are collapsed on mobile. |
from Columns |
| int|null | $all_data_count | Total count of all data records (before filtering). |
from Data |
| int|null | $filtered_data_count | Count of data records after filtering. |
from Data |
| Collection|array | $filters | Collection of defined filters. |
from Filters |
| bool | $has_filters | from Filters | |
| bool | $show_filters | from Filters | |
| array|null | $options | Options available for the table (e.g. for select filters or other UI elements). |
from Options |
| string | $paginationTheme | The pagination theme to use (e.g. 'tailwind', 'bootstrap'). |
from Pagination |
| int|string | $perPage | Number of items per page. |
from Pagination |
| int|string | $perPageDisplay | Display value for per page selector. |
from Pagination |
| string[] | $perPageOptions | Available options for items per page. |
from Pagination |
| bool | $with_pagination | Indicates if pagination is enabled. |
|
| int|null | $currentPageNumber | Current page number. |
from Pagination |
| int|bool | $forcePageNumber | Force a specific page number. |
from Pagination |
| array | $yatable_expanded_rows | from RowManipulators | |
| bool | $yatable_expanded_rows_is_component | from RowManipulators | |
| array | $yatable_expanded_rows_content | from RowManipulators | |
| string | $yat_global_search | from Search | |
| string|null | $yat_global_search_label | from Search | |
| bool | $useGlobalSearch | from Search | |
| string|null | $sortColumn | from Sort | |
| string | $sortDirection | from Sort | |
| string | $trigger_spinner | Actions that trigger the loading spinner. |
from Spinner |
| bool | $loading_table_spinner | from Spinner | |
| string|null | $loading_table_spinner_custom_view | from Spinner | |
| bool | $handle_state | from StateHandler | |
| string | $handler_prefix | from StateHandler | |
| string|null | $title | from View | |
| string|null | $titleClasses | from View | |
| string|null | $customHeader | from View | |
| string|null | $main_wrapper_classes | from View | |
| string|null | $table_classes | from View | |
| bool | $override_table_classes | from View | |
| bool | $sticky_header | from View | |
| bool | $has_counter | from View | |
| string|null | $modals_view | from View | |
| string|null | $yat_most_left_view | from View | |
| string|null | $yat_less_left_view | from View | |
| string|null | $yat_most_right_view | from View | |
| string|null | $yat_less_right_view | from View | |
| bool | $showCardsOnMobile | from View | |
| bool | $useCards | from View | |
| bool | $yat_is_mobile | from View | |
| array | $yat_custom_buttons | from View | |
| string | $yat_button_variant | from View | |
| string | $theme | from View | |
| string|null | $bulkThemeOverride | from View | |
| string|null | $buttonThemeOverride | from View | |
| string|null | $inputThemeOverride | from View | |
| string|null | $componentSizeOverride | from View | |
| array | $themeConfig | from View | |
| array | $yat_card_modal_buttons | from View | |
| bool | $mobileDetailsModalOpen | from View | |
| array | $mobileDetailsRow | from View | |
| bool | $showOptionsOnlyOnRowSelect | from View | |
| string|null | $layout | The layout to be used for rendering the table. |
|
| bool | $stripRows | from View | |
| mixed | $model | The model or builder instance used for the table data. |
|
| array | $with | An array of relationships to eager load. |
Methods
Get a fresh collection of column instances with closures intact.
Resolve secondary header values by calling each column's callback with the current rows.
Set CSS classes for the column's header wrapper element.
Set a closure that determines when the toggle should be disabled.
Open the link in a popup window with the given dimensions.
Conditionally hide the column and remove it from the column selector.
Set an alternative column key to use when sorting this column.
Strip modified row internal keys from the collection.
Transform a single row.
Get all column metadata in a single pass over getFreshColumns().
Export the current table data to clipboard (CSV/TSV).
Authorize a field update before persisting.
Update a specific field for a row.
Apply filters to the data collection (Array/Collection mode).
Get a fresh instance of filters with current state merged.
Get paginated data for a specific page number.
Remove a row from the table data (and cache).
Toggle the expansion state of a row.
Update a row's data in the table (and cache).
Toggle a boolean column value for a row.
Add more triggers (methods/properties) to the spinner.
Enable or disable persisting column visibility to the database.
Set a prefix for the state handler key to differentiate tables.
Override the size of all beartropy-ui components in the table header.
Open the mobile details modal for a specific row.
Configure options visibility based on row selection specific logic.
Get the CSS classes for row striping based on configuration.
Base query for model-based tables.
Build a new query with eager loading applied.
Refresh the table component.
Initialize the component.
Configure the table display mode.
Render the component.
Details
in
Bulk at line 41
void
emptySelection()
Clear the current selection.
Resets the selected checkboxes and the "select all" state.
in
Bulk at line 52
void
hasBulk(bool $bool)
Enable or disable bulk actions.
in
Bulk at line 65
void
updatedSelectAll(bool $value)
Handle updates to the "Select All" checkbox.
This method is triggered by Livewire when $selectAll property changes.
in
Bulk at line 76
void
selectCurrentPage(bool $value)
Select all rows on the current page.
in
Bulk at line 91
void
select_all_data(bool $value)
Select all rows across all pages (after filters).
in
Bulk at line 105
array<int|string>
getSelectedRows()
Get the list of selected row IDs.
in
Cache at line 26
void
setCachePrefix(string $string)
Set the cache prefix.
in
Cache at line 36
protected string
getCacheKey()
Generate a unique cache key for the current user and table.
in
Cache at line 50
void
cacheData()
Cache the current user data.
Stores the data in the cache for 60 minutes and updates the timestamp.
in
Cache at line 64
void
clearData()
Clear the cached data for this table.
in
Cache at line 76
mixed
getCachedData()
Retrieve cached data.
If cache is missing, it attempts to re-initialize the component (mount).
in
Cache at line 93
void
updateCacheData(mixed $data)
Update the cached data with new data.
Clears current selection and updates the cache with the new data set.
in
Columns at line 53
void
setColumns()
Initialize and process column definitions.
Handles mobile visibility, collapse behavior, and strips closures for Livewire serialization.
in
Columns at line 99
Collection
getFreshColumns()
Get a fresh collection of column instances with closures intact.
in
Columns at line 114
array
resolveSecondaryHeaders(mixed $paginatedData)
Resolve secondary header values by calling each column's callback with the current rows.
in
Columns at line 136
void
showColumnToggle(bool $bool)
Show or hide the column toggle dropdown.
in
Columns at line 146
void
setColumnID(string $column_id)
Set the primary key column used to identify rows.
in
Columns at line 164
Columns
showOnMobile(bool $bool = true)
Show this column only on mobile devices.
in
Columns at line 176
Columns
view(string $view)
Set a custom Blade view for rendering the column cell.
in
Columns at line 187
Columns
styling(string $classes)
Set CSS classes for the column's table cell (td).
in
Columns at line 197
Columns
thStyling(string $classes)
Set CSS classes for the column's table header (th).
in
Columns at line 207
Columns
thWrapperStyling(string $classes)
Set CSS classes for the column's header wrapper element.
in
Columns at line 217
Columns
disableToggleWhen(Closure $function)
Set a closure that determines when the toggle should be disabled.
in
Columns at line 227
Columns
hideToggleWhen(Closure $function)
Set a closure that determines when the toggle should be hidden.
in
Columns at line 237
Columns
trigger(string $trigger)
Set the method name to call when a toggle column is toggled.
in
Columns at line 259
Columns
trueIs(mixed $true)
Set the value that represents "true" for boolean columns.
in
Columns at line 271
Columns
trueLabel(string $string)
Set the display label/icon for the "true" state.
in
Columns at line 283
Columns
falseLabel(string $string)
Set the display label/icon for the "false" state.
in
Columns at line 317
Columns
href(Closure $function)
Set a closure that resolves the URL for a link column.
in
Columns at line 329
Columns
target(string $target)
Set the target attribute for a link column (e.g. '_blank').
in
Columns at line 343
Columns
popup(array $array = ['width' => 750, 'height' => 800])
Open the link in a popup window with the given dimensions.
in
Columns at line 357
Columns
classes(string $classes)
Set CSS classes for a link column's anchor tag.
in
Columns at line 369
Columns
customData(Closure $function)
Set a closure to transform the column's display value.
in
Columns at line 379
Columns
hideWhen(bool $bool)
Conditionally hide the column and remove it from the column selector.
in
Columns at line 392
Columns
hideFromSelector(bool $bool)
Hide this column from the column toggle selector.
in
Columns at line 412
Columns
sortColumnBy(string $column)
Set an alternative column key to use when sorting this column.
in
Data at line 32
Collection
stripModifiedRows(Collection $collection)
Strip modified row internal keys from the collection.
Removes keys ending with '_original' and potentially restores original values.
in
Data at line 55
Collection
getAllOriginalData()
Get all original data without modifications.
in
Data at line 67
Collection
getAllData()
Get all data available to the table.
Fetches from model/database if configured, or returns cached data.
in
Data at line 83
Collection
getAfterFiltersOriginalData()
Get original data after filters are applied.
in
Data at line 93
Collection
getAfterFiltersData()
Get data after applying search, filters, and sorting.
in
Data at line 133
Collection
getSelectedOriginalData()
Get selected original data without modifications.
in
Data at line 143
Collection
getSelectedData()
Get selected rows data.
in
Data at line 166
mixed|null
getRowByID(mixed $id)
Get a single row by its ID.
in
Data at line 188
Collection
getCurrentPageData()
Get data for the current page.
in
Data at line 210
void
parseData()
Parse and cache the initial data.
Clears existing cache, resets pagination, and re-processes data from source. Dispatches events based on data availability.
in
Data at line 236
Collection
processCollection(Collection $collection)
Process a collection of rows.
Applies transformations (custom data, links, toggles) to each row.
in
Data at line 274
array
transformRow(mixed $row, array $customData, array $linkColumns, array $toggleColumns, array $cardTitleCallbacks = [])
Transform a single row.
in
Data at line 375
array
getColumnMetadata()
Get all column metadata in a single pass over getFreshColumns().
Consolidates custom data, link columns, toggle columns, and card title callbacks to avoid iterating the column definitions multiple times.
in
Data at line 428
void
exportToClipboard(Collection $collection, bool $tabs = true)
Export the current table data to clipboard (CSV/TSV).
in
Editable at line 19
bool
authorizeFieldUpdate(Model $record, string $field, mixed $value)
Authorize a field update before persisting.
Override this method in your table component to add policy checks or custom authorization logic.
in
Editable at line 35
bool|void
updateField(mixed $id, string $field, mixed $value)
Update a specific field for a row.
Handles inline editing updates. Supports callbacks, Eloquent models, and array data. Dispatches 'table-field-updated' event.
in
Filters at line 28
void
setFilters()
Initialize filters.
Processes defined filters, resolving keys, options (for magic-select), and serializing them for Livewire.
in
Filters at line 141
string
getColumnKey(string $filter_label)
Identify the column key from a filter label.
in
Filters at line 161
void
updatedFilters(string $key, mixed $value)
Handle updates to filter inputs.
Triggered by Livewire when filter properties change.
in
Filters at line 210
Collection
applyFilters(Collection $data)
Apply filters to the data collection (Array/Collection mode).
in
Filters at line 270
Collection
getFreshFilters()
Get a fresh instance of filters with current state merged.
Re-initializes filters (e.g. to get closures back) and merges the Livewire state (inputs).
in
Filters at line 316
Builder
applyFiltersToQuery(Builder $query)
Apply filters to the Eloquent query.
in
Filters at line 419
void
clearAllFilters(bool $selectAll = false)
Clear all active filters and search.
in
Options at line 19
void
setOptions()
Initialize and normalize options.
Converts string options to ['label' => '...', 'icon' => null] format.
in
Pagination at line 53
void
updatedPerPageDisplay(string|int $value)
Update the per-page display value.
Handles the 'Total' option to show all records. Resets selection when page size changes.
in
Pagination at line 74
void
usePagination(bool $bool)
Enable or disable pagination.
in
Pagination at line 85
void
setPerPageDefault(int $number)
Set the default items per page.
in
Pagination at line 101
void
setPerPageOptions(array $array)
Set available per-page options.
in
Pagination at line 114
LengthAwarePaginator
paginateData()
specific method to handle pagination logic.
Applies search, filters, and sort logic to the query or collection, then paginates the result.
in
Pagination at line 182
LengthAwarePaginator
getPageData(int $currentPage)
Get paginated data for a specific page number.
Used for array-based data sources where we slice the collection manually.
in
RowManipulators at line 22
void
removeRowFromTable(mixed $id, bool $resetSelected = true)
Remove a row from the table data (and cache).
in
RowManipulators at line 40
void
addRowToTable(array $row)
Add a new row to the table data (and cache).
in
RowManipulators at line 64
void
toggleExpandedRow(mixed $rowId, mixed $content, bool $is_component = false)
Toggle the expansion state of a row.
in
RowManipulators at line 90
void
updateRowOnTable(mixed $id, array $newData)
Update a row's data in the table (and cache).
in
RowManipulators at line 109
void
expandMobileRow(mixed $rowId)
Expand the mobile details view for a row.
in
RowManipulators at line 137
void
toggleBoolean(mixed $id, string $column)
Toggle a boolean column value for a row.
Dispatches trigger method if defined on the column.
in
Search at line 18
void
useGlobalSearch(bool $status = true)
Enable or disable global search.
in
Search at line 28
void
setSearchLabel(string $label)
Set the label for the global search input.
in
Search at line 40
void
updatingSearch()
Handle updates to the global search input.
Resets pagination when search query changes.
in
Search at line 50
Collection
filteredData()
Filter the data based on global search (Array mode).
in
Search at line 91
Builder
applySearchToQuery(Builder $query)
Apply global search to the Eloquent query.
in
Sort at line 16
void
setSortDirectionAsc(bool $bool)
Set sort direction to ascending.
in
Sort at line 28
void
setSortDirectionDesc(bool $bool)
Set sort direction to descending.
in
Sort at line 40
void
setSortColumn(string $column)
Set the column to sort by.
in
Sort at line 51
void
sortBy(string $column)
Toggle sorting for a specific column.
in
Sort at line 78
Collection
sortData(Collection $data)
Sort the data collection (Array mode).
in
Sort at line 125
Builder
applySortToQuery(Builder $query)
Apply sorting to the Eloquent query.
Handles relationship sorting and custom callbacks.
in
Spinner at line 21
void
useTableSpinner(bool $bool)
Enable or disable the table loading spinner.
in
Spinner at line 31
void
setTableSpinnerView(string $view)
Set a custom view for the loading spinner.
in
Spinner at line 41
void
addTargetsToSpinner(array $targets)
Add more triggers (methods/properties) to the spinner.
in
StateHandler at line 19
void
useStateHandler(bool $bool)
Enable or disable persisting column visibility to the database.
in
StateHandler at line 29
void
setHandlerPrefix(string $string)
Set a prefix for the state handler key to differentiate tables.
in
StateHandler at line 39
void
saveTableState()
Save the current column visibility state to the database.
in
StateHandler at line 60
void
setTableState()
Restore column visibility state from the database.
in
View at line 60
void
setTheme(string $theme)
Set the table theme.
in
View at line 71
array
getThemeConfig(string $theme)
Get configuration for a specific theme from presets.
in
View at line 83
void
setBulkThemeOverride(string|null $theme)
Override the bulk actions theme.
in
View at line 93
void
setButtonThemeOverride(string|null $theme)
Override the button theme.
in
View at line 103
void
setInputThemeOverride(string|null $theme)
Override specific theme settings.
in
View at line 113
void
setComponentSize(string|null $size)
Override the size of all beartropy-ui components in the table header.
in
View at line 123
void
mountView()
Initialize view settings.
in
View at line 135
void
gatherEnvData()
Detect environmental data (e.g. mobile device).
in
View at line 148
void
addButtons(array $buttons)
Add custom buttons to the table header.
in
View at line 160
void
addCardModalButtons(array $buttons)
Add buttons to the card modal view.
in
View at line 170
void
showCounter(bool $bool)
Toggle the record counter display.
in
View at line 180
void
showCardsOnMobile(bool $bool = true)
Enable or disable card view on mobile devices.
in
View at line 190
void
useCards(bool $bool = true)
Enable or disable card layout for all devices.
in
View at line 205
void
openMobileCardDetails(mixed $rowId)
Open the mobile details modal for a specific row.
in
View at line 216
void
closeMobileCardDetails()
Close the mobile details modal.
in
View at line 228
void
setTitle(string $title)
Set the table title.
in
View at line 239
void
overrideTitleClasses(string $classes)
Override default title classes.
in
View at line 250
void
setCustomHeader(string $html)
Set custom HTML content for the header.
in
View at line 260
void
setComponentClasses(string $classes)
Set CSS classes for the main component wrapper.
in
View at line 270
void
addTableClasses(string $classes)
Add CSS classes to the table element.
in
View at line 280
void
setTableClasses(string $classes)
Set (overwrite) CSS classes for the table element.
in
View at line 291
void
setStickyHeader()
Enable sticky header for the table.
in
View at line 301
void
setModalsView(string $view)
Set the view for modals.
in
View at line 311
void
setMostLeftView(string $view)
Set the view for the leftmost header area.
in
View at line 321
void
setLessLeftView(string $view)
Set the view for the inner left header area.
in
View at line 331
void
setMostRightView(string $view)
Set the view for the rightmost header area.
in
View at line 341
void
setLessRightView(string $view)
Set the view for the inner right header area.
in
View at line 351
void
setButtonVariant(string $variant)
Set the button variant style.
in
View at line 363
void
showOptionsOnlyOnRowSelect(bool $value = true)
Configure options visibility based on row selection specific logic.
in
View at line 376
void
setLayout(mixed $layout)
Set the main layout view.
in
View at line 388
void
stripRows(bool $strip = true)
Enable or disable striped rows.
in
View at line 398
string
getRowStripingClasses()
Get the CSS classes for row striping based on configuration.
at line 81
Builder
query()
Base query for model-based tables.
Override this method to scope the base query (e.g., by tenant, permissions, etc.). The $with eager loading is applied automatically via newQuery() — no need to add it here.
at line 94
protected Builder
newQuery()
Build a new query with eager loading applied.
Internal method — wraps query() and applies $this->with. All internal data-fetching code should call this instead of query() directly.
at line 111
void
refresh()
Refresh the table component.
This method acts as a listener for the 'refresh' event. It re-initializes the component by calling the mount method.
at line 126
void
mount()
Initialize the component.
This method prepares the environment, settings, columns, options, filters, and view configurations. If no model is provided, it attempts to parse and cache data.
at line 150
void
showOnlyTable(bool $status = true)
Configure the table display mode.
Helper to quickly enable or disable table-only view. Disabling "only table" enables global search, pagination, and column toggle.
at line 165
View
render()
Render the component.
Calculates the data to be displayed, applying sorting and filtering if pagination is not used. Returns the view with the row data.