Overview
You may render a “summary” section below your table content. This is great for displaying the results of calculations such as averages, sums, counts, and ranges of the data in your table. By default, there will be a single summary line for the current page of data, and an additional summary line for the totals for all data if multiple pages are available. You may also add summaries for groups of records, see “Summarising groups of rows”. “Summarizer” objects can be added to any table column using thesummarize() method:
The first column in a table may not use summarizers. That column is used to render the heading and subheading/s of the summary section.
Available summarizers
Filament ships with four types of summarizer: You may also create your own custom summarizers to display data in whatever way you wish.Average
Average can be used to calculate the average of all values in the dataset:Count
Count can be used to find the total number of values in the dataset. Unless you just want to calculate the number of rows, you will probably want to scope the dataset as well:Counting the occurrence of icons
Using a count on an icon column allows you to use theicons() method, which gives the user a visual representation of how many of each icon are in the table:
Range
Range can be used to calculate the minimum and maximum value in the dataset:Date range
You may format the range as dates using theminimalDateTimeDifference() method:
- If the minimum and maximum dates are different days, only the dates will be displayed.
- If the minimum and maximum dates are on the same day at different times, both the date and time will be displayed.
- If the minimum and maximum dates and times are identical, they will only appear once.
Text range
You may format the range as text using theminimalTextualDifference() method:
- If the minimum and maximum start with different letters, only the first letters will be displayed.
- If the minimum and maximum start with the same letter, more of the text will be rendered until a difference is found.
- If the minimum and maximum are identical, they will only appear once.
Including null values in the range
By default, we will exclude null values from the range. If you would like to include them, you may use theexcludeNull(false) method:
Sum
Sum can be used to calculate the total of all values in the dataset:Setting a label
You may set a summarizer’s label using thelabel() method:
Scoping the dataset
You may apply a database query scope to a summarizer’s dataset using thequery() method:
is_published is set to true will be used to calculate the average.
This feature is especially useful with the count summarizer, as it can count how many records in the dataset pass a test:
Formatting
Number formatting
Thenumeric() method allows you to format an entry as a number:
decimalPlaces argument:
locale argument:
Table::$defaultNumberLocale method in the boot() method of a service provider:
Currency formatting
Themoney() method allows you to easily format monetary values, in any currency:
divideBy argument for money() that allows you to divide the original value by a number before formatting it. This could be useful if your database stores the price in cents, for example:
locale argument:
Table::$defaultNumberLocale method in the boot() method of a service provider:
Limiting text length
You maylimit() the length of the summary’s value:
Adding a prefix or suffix
You may add a prefix or suffix to the summary’s value:Custom summaries
You may create a custom summary by returning the value from theusing() method:
$query builder instance to perform calculations with. It should return the value to display in the table.
Conditionally hiding the summary
To hide a summary, you may pass a boolean, or a function that returns a boolean, to thehidden() method. If you need it, you can access the Eloquent query builder instance for that summarizer via the $query argument of the function:
visible() method to achieve the opposite effect:
Summarising groups of rows
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 beneficial in many reporting scenarios.