Introduction
Filament’s table system is highly extensible, allowing you to create custom column types that integrate seamlessly with sorting, searching, and all other table features. Custom columns extend the baseColumn class and can display data in any format you need.
Understanding the Column base class
All table columns extend theColumn class at packages/tables/src/Columns/Column.php. This base class provides:
- State retrieval and formatting
- Sorting and searching capabilities
- Alignment and width configuration
- Action and URL integration
- Tooltip support
- Record access and manipulation
Creating a basic custom column
use Filament\Tables\Columns\Column;
class RatingColumn extends Column
{
protected string $view = 'filament.tables.columns.rating-column';
}
<div class="flex items-center gap-x-1">
@for ($i = 1; $i <= 5; $i++)
<svg
class="h-5 w-5 {{ $i <= $getState() ? 'text-warning-500' : 'text-gray-300' }}"
fill="currentColor"
viewBox="0 0 20 20"
>
<path d="M9.049 2.927c.3-.921 1.603-.921 1.902 0l1.07 3.292a1 1 0 00.95.69h3.462c.969 0 1.371 1.24.588 1.81l-2.8 2.034a1 1 0 00-.364 1.118l1.07 3.292c.3.921-.755 1.688-1.54 1.118l-2.8-2.034a1 1 0 00-1.175 0l-2.8 2.034c-.784.57-1.838-.197-1.539-1.118l1.07-3.292a1 1 0 00-.364-1.118L2.98 8.72c-.783-.57-.38-1.81.588-1.81h3.461a1 1 0 00.951-.69l1.07-3.292z" />
</svg>
@endfor
</div>
Adding custom configuration methods
Extend your column with custom methods following Filament’s fluent API pattern:Using embedded HTML views
For better performance, you can implementHasEmbeddedView to render HTML directly without Blade:
Implementing sortable columns
Make your column sortable by implementing custom sorting logic:Implementing searchable columns
Add search functionality to your custom column:Accessing state and formatting
You can format column state before display:Using concerns for reusable functionality
Filament columns use traits to add common functionality:Advanced example: Chart column
Here’s a complex example that renders a mini chart using Chart.js:Working with actions
Columns can trigger actions when clicked:Accessing the table and Livewire component
You can access the parent table and Livewire component:Column summarization
Add summary calculations to your custom column:Best practices
- Always extend the
Columnbase class - Use the
evaluate()method for closure support in all configuration methods - Implement
HasEmbeddedViewfor simple columns to improve performance - Use concerns (traits) for reusable functionality like
CanBeCopied,HasColor, etc. - Access state via
$getState()in Blade views or$this->getState()in the class - Use the
setUp()method for default configuration - Follow naming conventions:
getprefix for getters, nullable setters - Never use abbreviated variable names - use descriptive names
- Use static closures (
static fn) when the closure doesn’t use$this - Use
app()instead ofnewfor dependency injection