YATBaseTable
class YATBaseTable 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
| string | $cachePrefix | Cache prefix used in the Data trait scope. |
from Data |
| int|null | $cacheTimeStamp | Timestamp of the cached data. |
from Cache |
| 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 |
| 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 |
| bool | $has_bulk | Indicates if the table has bulk actions enabled. |
from Bulk |
| (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 | $yat_global_search | from Search | |
| string|null | $yat_global_search_label | from Search | |
| bool | $useGlobalSearch | from Search | |
| string | $paginationTheme | The pagination theme to use (e.g. 'tailwind', 'bootstrap'). |
from Pagination |
| int|string | $perPage | Number of items per page. |
from Pagination |
| 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|false | $forcePageNumber | Force a specific page number. |
from Pagination |
| string|null | $sortColumn | from Sort | |
| string | $sortDirection | from Sort | |
| array | $options | Options available for the table (e.g. for select filters or other UI elements). |
from Options |
| $handle_state | from StateHandler | ||
| $handler_prefix | from StateHandler | ||
| array | $yatable_expanded_rows | from RowManipulators | |
| bool | $yatable_expanded_rows_is_component | from RowManipulators | |
| array | $yatable_expanded_rows_content | from RowManipulators | |
| 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 | |
| array | $themeConfig | from View | |
| array | $yat_card_modal_buttons | from View | |
| $mobileDetailsModalOpen | from View | ||
| $mobileDetailsRow | from View | ||
| $showOptionsOnlyOnRowSelect | from View | ||
| string|null | $layout | The layout to be used for rendering the table. |
|
| $stripRows | from View | ||
| Collection|array | $filters | Collection of defined filters. |
from Filters |
| bool | $has_filters | from Filters | |
| bool | $show_filters | from Filters | |
| 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 | |
| mixed | $model | The model or builder instance used for the table data. |
|
| array | $with | An array of relationships to eager load. |
Methods
Strip modified row internal keys from the collection.
Transform a single row.
Export the current table data to clipboard (CSV/TSV).
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.
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.
Apply filters to the data collection (Array/Collection mode).
Get a fresh instance of filters with current state merged.
Add more triggers (methods/properties) to the spinner.
Update a specific field for a row.
Refresh the table component.
Initialize the component.
Configure the table display mode.
Render the component.
Details
in
Cache at line 31
void
setCachePrefix(string $string)
Set the cache prefix.
in
Cache at line 41
protected string
getCacheKey()
Generate a unique cache key for the current user and table.
in
Cache at line 54
void
cacheData()
Cache the current user data.
Stores the data in the cache for 60 minutes and updates the timestamp.
in
Cache at line 68
void
clearData()
Clear the cached data for this table.
in
Cache at line 80
mixed
getCachedData()
Retrieve cached data.
If cache is missing, it attempts to re-initialize the component (mount).
in
Cache at line 96
void
updateCacheData(mixed $data)
Update the cached data with new data.
Clears current selection and updates the cache with the new data set.
in
Data at line 64
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 90
Collection
getAllOriginalData()
Get all original data without modifications.
in
Data at line 109
Collection
getAllData()
Get all data available to the table.
Fetches from model/database if configured, or returns cached data.
in
Data at line 132
Collection
getAfterFiltersOriginalData()
Get original data after filters are applied.
in
Data at line 147
Collection
getAfterFiltersData()
Get data after applying search, filters, and sorting.
in
Data at line 189
Collection
getSelectedOriginalData()
Get selected original data without modifications.
in
Data at line 199
Collection
getSelectedData()
Get selected rows data.
in
Data at line 228
mixed|null
getRowByID(mixed $id)
Get a single row by its ID.
in
Data at line 265
Collection
getCurrentPageData()
Get data for the current page.
in
Data at line 285
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 311
Collection
processCollection(Collection $collection)
Process a collection of rows.
Applies transformations (custom data, links, toggles) to each row.
in
Data at line 382
array
transformRow(mixed $row, array $customData, array $linkColumns, array $toggleColumns)
Transform a single row.
in
Data at line 459
array
getCustomData()
Get columns with custom data closure.
in
Data at line 477
array
getLinkColumns()
Get columns configured as links.
in
Data at line 497
array
getToggleColumns()
Get columns with toggle functionality.
in
Data at line 523
void
exportToClipboard(Collection $collection, bool $tabs = true)
Export the current table data to clipboard (CSV/TSV).
in
Columns at line 60
setColumns()
No description
in
Columns at line 99
getFreshColumns()
No description
in
Columns at line 107
showColumnToggle(bool $bool)
No description
in
Columns at line 112
setColumnID(string $column_id)
No description
in
Columns at line 225
Columns
popup(array $array = ["width" => 750, "height" => 800])
No description
in
Bulk at line 49
void
emptySelection()
Clear the current selection.
Resets the selected checkboxes and the "select all" state.
in
Bulk at line 61
void
hasBulk(bool $bool)
Enable or disable bulk actions.
in
Bulk at line 74
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 86
void
selectCurrentPage(bool $value)
Select all rows on the current page.
in
Bulk at line 101
void
select_all_data(bool $value)
Select all rows across all pages (after filters).
in
Bulk at line 126
(int|string)[]
getSelectedRows()
Get the list of selected row IDs.
in
Search at line 29
void
useGlobalSearch(bool $status = true)
Enable or disable global search.
in
Search at line 40
void
setSearchLabel(string $label)
Set the label for the global search input.
in
Search at line 52
void
updatingSearch()
Handle updates to the global search input.
Resets pagination when search query changes.
in
Search at line 62
Collection
filteredData()
Filter the data based on global search (Array mode).
in
Search at line 100
Builder
applySearchToQuery(Builder $query)
Apply global search to the Eloquent query.
in
Pagination at line 66
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 87
void
usePagination(bool $bool)
Enable or disable pagination.
in
Pagination at line 98
void
setPerPageDefault(int $number)
Set the default items per page.
in
Pagination at line 115
void
setPerPageOptions(array $array)
Set available per-page options.
in
Pagination at line 128
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 198
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
Sort at line 24
void
setSortDirectionAsc(bool $bool)
Set sort direction to ascending.
in
Sort at line 37
void
setSortDirectionDesc(bool $bool)
Set sort direction to descending.
in
Sort at line 50
void
setSortColumn(string $column)
Set the column to sort by.
in
Sort at line 61
void
sortBy(string $column)
Toggle sorting for a specific column.
in
Sort at line 88
Collection
sortData(Collection $data)
Sort the data collection (Array mode).
in
Sort at line 142
Builder
applySortToQuery(Builder $query)
Apply sorting to the Eloquent query.
Handles relationship sorting and custom callbacks.
in
Options at line 22
void
setOptions()
Initialize and normalize options.
Converts string options to ['label' => '...', 'icon' => null] format.
in
StateHandler at line 15
useStateHandler(bool $bool)
No description
in
StateHandler at line 19
setHandlerPrefix(string $string)
No description
in
StateHandler at line 23
saveTableState()
No description
in
StateHandler at line 38
setTableState()
No description
in
RowManipulators at line 32
void
removeRowFromTable(mixed $id, bool $resetSelected = true)
Remove a row from the table data (and cache).
in
RowManipulators at line 50
void
addRowToTable(array $row)
Add a new row to the table data (and cache).
in
RowManipulators at line 69
void
toggleExpandedRow(mixed $rowId, mixed $content, bool $is_component = false)
Toggle the expansion state of a row.
in
RowManipulators at line 95
void
updateRowOnTable(mixed $id, array $newData)
Update a row's data in the table (and cache).
in
RowManipulators at line 113
void
expandMobileRow(mixed $rowId)
Expand the mobile details view for a row.
in
RowManipulators at line 139
void
toggleBoolean(mixed $id, string $column)
Toggle a boolean column value for a row.
Dispatches trigger method if defined on the column.
in
View at line 125
void
setTheme(string $theme)
Set the table theme.
in
View at line 137
array
getThemeConfig(string $theme)
Get configuration for a specific theme from presets.
in
View at line 149
void
setBulkThemeOverride(string|null $theme)
Override the bulk actions theme.
in
View at line 160
void
setButtonThemeOverride(string|null $theme)
Override the button theme.
in
View at line 171
void
setInputThemeOverride(string|null $theme)
Override specific theme settings.
in
View at line 181
void
mountView()
Initialize view settings.
in
View at line 193
void
gatherEnvData()
Detect environmental data (e.g. mobile device).
in
View at line 207
void
addButtons(array $buttons)
Add custom buttons to the table header.
in
View at line 223
void
addCardModalButtons(array $buttons)
Add buttons to the card modal view.
in
View at line 234
void
showCounter(bool $bool)
Toggle the record counter display.
in
View at line 239
showCardsOnMobile(bool $bool = true)
No description
in
View at line 244
useCards(bool $bool = true)
No description
in
View at line 258
void
openMobileCardDetails(mixed $rowId)
Open the mobile details modal for a specific row.
in
View at line 269
void
closeMobileCardDetails()
Close the mobile details modal.
in
View at line 281
void
setTitle(string $title)
Set the table title.
in
View at line 292
void
overrideTitleClasses(string $classes)
Override default title classes.
in
View at line 303
void
setCustomHeader(string $html)
Set custom HTML content for the header.
in
View at line 314
void
setComponentClasses(string $classes)
Set CSS classes for the main component wrapper.
in
View at line 325
void
addTableClasses(string $classes)
Add CSS classes to the table element.
in
View at line 336
void
setTableClasses(string $classes)
Set (overwrite) CSS classes for the table element.
in
View at line 347
void
setStickyHeader()
Enable sticky header for the table.
in
View at line 360
void
setModalsView(string $view)
Set the view for modals.
in
View at line 371
void
setMostLeftView(string $view)
Set the view for the leftmost header area.
in
View at line 382
void
setLessLeftView(string $view)
Set the view for the inner left header area.
in
View at line 393
void
setMostRightView(string $view)
Set the view for the rightmost header area.
in
View at line 404
void
setLessRightView(string $view)
Set the view for the inner right header area.
in
View at line 415
void
setButtonVariant(string $variant)
Set the button variant style.
in
View at line 428
void
showOptionsOnlyOnRowSelect(bool $value = true)
Configure options visibility based on row selection specific logic.
in
View at line 441
void
setLayout(mixed $layout)
Set the main layout view.
in
View at line 454
void
stripRows(bool $strip = true)
Enable or disable striped rows.
in
View at line 464
string
getRowStripingClasses()
Get the CSS classes for row striping based on configuration.
in
Filters at line 35
void
setFilters()
Initialize filters.
Processes defined filters, resolving keys, options (for magic-select), and serializing them for Livewire.
in
Filters at line 154
string
getColumnKey(string $filter_label)
Identify the column key from a filter label.
in
Filters at line 174
void
updatedFilters(string $key, mixed $value)
Handle updates to filter inputs.
Triggered by Livewire when filter properties change.
in
Filters at line 219
Collection
applyFilters(Collection $data)
Apply filters to the data collection (Array/Collection mode).
in
Filters at line 276
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 317
Builder
applyFiltersToQuery(Builder $query)
Apply filters to the Eloquent query.
in
Filters at line 416
void
clearAllFilters(bool $selectAll = false)
Clear all active filters and search.
in
Spinner at line 29
void
useTableSpinner(bool $bool)
Enable or disable the table loading spinner.
in
Spinner at line 40
void
setTableSpinnerView(string $view)
Set a custom view for the loading spinner.
in
Spinner at line 51
void
addTargetsToSpinner(array $targets)
Add more triggers (methods/properties) to the spinner.
in
Editable at line 21
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.
at line 90
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 105
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 129
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 143
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.