Skip to content

Conversation

@mmuqiitf
Copy link
Contributor

@mmuqiitf mmuqiitf commented Jan 25, 2026

Description

This PR introduces the ability to define deferred filter schemas for ChartWidget using the standard Filament Schema builder. Previously, chart widgets only supported automatically filter.

Changelog:

  • Optional Deferred Filtering: A new $hasDeferredFilters toggle (default false). When enabled, the chart only updates when an "Apply" button is clicked, improving performance for complex queries.
  • Reset Logic: A "Reset" link that restores all filter values to their schema-defined defaults.
  • Customizable Actions: Methods to customize labels, colors, and behavior of the Apply and Reset actions.
  • Count Filters: Display count active filters in a badge

Example Usage:

class MyChart extends ChartWidget
{
    use HasFiltersSchema;

    protected bool $hasDeferredFilters = true;

    protected function getType(): string
    {
        return 'line';
    }

    public function filtersSchema(Schema $schema): Schema
    {
        return $schema
            ->components([
                Select::make('period')
                    ->options([
                        '7' => 'Last 7 days',
                        '14' => 'Last 14 days',
                        '30' => 'Last 30 days',
                        '60' => 'Last 60 days',
                        '90' => 'Last 90 days',
                    ])
                    ->default('30')
                    ->native(false),

                Select::make('status')
                    ->options([
                        'all' => 'All Statuses',
                        'pending' => 'Pending',
                        'in_progress' => 'In Progress',
                        'completed' => 'Completed',
                        'cancelled' => 'Cancelled',
                    ])
                    ->default('all')
                    ->native(false),

                Select::make('priority')
                    ->options([
                        'all' => 'All Priorities',
                        'low' => 'Low',
                        'medium' => 'Medium',
                        'high' => 'High',
                        'urgent' => 'Urgent',
                    ])
                    ->default('all')
                    ->native(false),

                Select::make('group_by')
                    ->label('Group By')
                    ->options([
                        'day' => 'Day',
                        'week' => 'Week',
                        'month' => 'Month',
                    ])
                    ->default('day')
                    ->native(false),

                DatePicker::make('date_from')
                    ->label('Custom From Date')
                    ->maxDate(fn () => $this->filters['date_to'] ?? now())
                    ->native(false),

                DatePicker::make('date_to')
                    ->label('Custom To Date')
                    ->minDate(fn () => $this->filters['date_from'] ?? null)
                    ->maxDate(now())
                    ->native(false),
            ]);
    }

    protected function getData(): array
    {
        $status = $this->filters['status'] ?? 'all';
        $priority = $this->filters['priority'] ?? 'all';
        $period = (int) ($this->filters['period'] ?? 30);
        $dateFrom = $this->filters['date_from'] ?? null;
        $dateTo = $this->filters['date_to'] ?? null;
        $groupBy = $this->filters['group_by'] ?? 'day';
         
        // ......
     }
}

Visual changes

Implemented additional button "Apply" & "Reset" at footer.
image

Functional changes

  • Code style has been fixed by running the composer cs command.
  • Changes have been tested to not break existing functionality.
  • Documentation is up-to-date.

- Implemented deferred filter updates to improve user experience by allowing users to apply multiple filters before updating the chart.
- Added "Apply" and "Reset" actions for deferred filters with customizable labels.
- Enhanced the chart widget's CSS for better filter layout and styling.
- Updated the chart widget's Blade view to accommodate new filter actions and structure.
- Introduced tests for deferred filters functionality, ensuring correct behavior for applying and resetting filters.
@mmuqiitf mmuqiitf changed the title Add Deferred Filters Support for Chart Widget [4.x] Add Deferred Filters Support for Chart Widget Jan 27, 2026
@danharrin danharrin added the enhancement New feature or request label Jan 27, 2026
@danharrin danharrin added this to the v4 milestone Jan 27, 2026
@github-project-automation github-project-automation bot moved this from Todo to In Progress in Roadmap Jan 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

2 participants