- Creating Columns
- Relationships
- Available Methods
- Other Column Types
- Column Selection
- Secondary Header
- Footer
- Reusable Columns
- Anonymous Columns
- Styling
- Standard Column
- Array Columns (beta)
- Avg Columns (beta)
- Boolean Columns
- Button Group Columns
- Color Columns
- Component Columns
- Count Columns (beta)
- Date Columns
- Icon Columns (beta)
- Image Columns
- Link Columns
- Livewire Component (beta)
- Sum Columns (beta)
- View Component Columns
- Wire Link Column (beta)
- Introduction
- Boolean Filters (beta)
- Date Filters
- DateRange Filters
- DateTime Filters
- Multi-Select Dropdown Filters
- Multi-Select Filters
- NumberRange Filters
- Number Filters
- Select Filters
- Text Filters
- Livewire Custom Filter (Beta)
- Refreshing
- Loading Placeholder
- Multiple Tables Same Page
- Actions (beta)
- Adding Custom Markup
- Debugging
- Saving Table State
- Lifecycle Hooks
- Hiding The Table (beta)
- One Of Many Example
- Tools
Getting Started
Usage
DataTable
Columns
Column Types
Rows
Sorting
Pagination
Search
Bulk Actions
Filters
Filter Types
Reordering
Secondary Header
Footer
Examples
Misc.
Sponsored
Advanced Usage
Examples
🎉 Enjoying this package? Consider sponsoring me on GitHub or buying me a beer.
This is the documentation for v3. You can switch versions in the menu on the left/at the top. Check your current version with the following command:
composer show rappasoft/laravel-livewire-tables
Saving
When you click the "Save" button, your ordered elements will be returned as an array, to the function you have configured.
You will receive a multi-dimensional array, containing an array item per record, with the primary key, and order field.
It is recommended that you perform some validation before bulk updating data, but it is in the correct format to perform upserts.
1public function reorder(array $items): void 2{ 3 // $item[$this->getPrimaryKey()] ensures that the Primary Key is used to find the User 4 // 'sort' is the name of your "sort" field in your database 5 // $item[$this->getDefaultReorderColumn()] retrieves the field, as defined in setDefaultReorderSort('FIELD', 'ORDER') 6 7 foreach ($items as $item) { 8 User::find($item[$this->getPrimaryKey()])->update(['sort' => (int)$item[$this->getDefaultReorderColumn()]]); 9 }10}
If you have defined both the Primary Key, and the Order Column, and the fields match your database, then you could use an upsert(). Keep in mind that an upsert does not go through validation, and you should exercise caution with this approach
1public function reorder(array $items): void2{3 // First value is the array of items4 // Second value should be the unique id (set in setPrimaryKey())5 // Third value should be the field set in setDefaultReorderSort('FIELD', 'ORDER')6 User::upsert($items, [$this->getPrimaryKey()], [$this->getDefaultReorderColumn()]);7}