Introduction
You may allow users to group table rows together using a common attribute. This is useful for displaying lots of data in a more organized way. Groups can be set up using the name of the attribute to group by (e.g.'status'), or a Group object which allows you to customize the behavior of that grouping (e.g. Group::make('status')->collapsible()).
Grouping rows by default
You may want to always group posts by a specific attribute. To do this, pass the group to thedefaultGroup() method:
Allowing users to choose between groupings
You may also allow users to pick between different groupings, by passing them in an array to thegroups() method:
groups() and defaultGroup() together to allow users to choose between different groupings, but have a default grouping set:
Grouping by a relationship attribute
You can also group by a relationship attribute using dot-syntax. For example, if you have anauthor relationship which has a name attribute, you can use author.name as the name of the attribute:
Setting a grouping label
By default, the label of the grouping will be generated based on the attribute. You may customize it with aGroup object, using the label() method:
Setting a group title
By default, the title of a group will be the value of the attribute. You may customize it by returning a new title from thegetTitleFromRecordUsing() method of a Group object:
Disabling the title label prefix
By default, the title is prefixed with the label of the group. To disable this prefix, utilize thetitlePrefixedWithLabel(false) method:
Setting a group description
You may also set a description for a group, which will be displayed underneath the group title. To do this, use thegetDescriptionFromRecordUsing() method on a Group object:
Setting a group key
By default, the key of a group will be the value of the attribute. It is used internally as a raw identifier of that group, instead of the title. You may customize it by returning a new key from thegetKeyFromRecordUsing() method of a Group object:
Date groups
When using a date-time column as a group, you may want to group by the date only, and ignore the time. To do this, use thedate() method on a Group object:
Collapsible groups
You can allow rows inside a group to be collapsed underneath their group title. To enable this, use aGroup object with the collapsible() method:
Collapsing groups by default
By default, groups with thecollapsible() method are expanded when the table loads.
If you want all groups to be collapsed by default when the table loads, use $table->collapsedGroupsByDefault():
Summarising groups
You can use summaries with groups to display a summary of the records inside a group. This works automatically if you choose to add a summariser to a column in a grouped table.Hiding the grouped rows and showing the summary only
You may hide the rows inside groups and just show the summary of each group using thegroupsOnly() method. This is very useful in many reporting scenarios.
Customizing the Eloquent query ordering behavior
Some features require the table to be able to order an Eloquent query according to a group. You can customize how we do this using theorderQueryUsing() method on a Group object:
Customizing the Eloquent query scoping behavior
Some features require the table to be able to scope an Eloquent query according to a group. You can customize how we do this using thescopeQueryByKeyUsing() method on a Group object:
Customizing the Eloquent query grouping behavior
Some features require the table to be able to group an Eloquent query according to a group. You can customize how we do this using thegroupQueryUsing() method on a Group object:
Customizing the groups dropdown trigger action
To customize the groups dropdown trigger button, you may use thegroupRecordsTriggerAction() method, passing a closure that returns an action. All methods that are available to customize action trigger buttons can be used:
Using the grouping settings dropdown on desktop
By default, the grouping settings dropdown will only be shown on mobile devices. On desktop devices, the grouping settings are in the header of the table. You can enable the dropdown on desktop devices too by using thegroupingSettingsInDropdownOnDesktop() method:
Hiding the grouping settings
You can hide the grouping settings interface using thegroupingSettingsHidden() method:
Hiding the grouping direction setting only
You can hide the grouping direction select interface using thegroupingDirectionSettingHidden() method: