Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change on single filter doesnt update #39

Closed
sairiz opened this issue Aug 20, 2023 · 2 comments
Closed

Change on single filter doesnt update #39

sairiz opened this issue Aug 20, 2023 · 2 comments

Comments

@sairiz
Copy link

sairiz commented Aug 20, 2023

Hi,

I copied a working graph from v2 in filament v2 to current version 3.0.1 in Filament 3.027

Upon selecting single filter, there is no update request.

public ?string $filter = '2023';

/**
 * Filter Options
 */
protected function getFilters(): ?array
{
    $years = range(now()->year, 2015);

    foreach ($years as $year) {
        $newYears[$year] = $year;
    }

    return $newYears;
}

/**
 * Chart options (series, labels, types, size, animations...)
 * https://apexcharts.com/docs/options
 *
 * @return array
 */
protected function getOptions(): array
{
    $activeFilter = $this->filter;

    $data = Trend::query(Stat::where('type', 'sales')->where('system', 'MY'))
        ->between(
            start: Carbon::create($activeFilter)->startOfYear(),
            end: Carbon::create($activeFilter)->endOfYear(),
        )
        ->perMonth()
        ->sum('data');

    return [

        'chart' => [
            'type' => 'line',
            'height' => 300,
            'toolbar' => [
                'show' => false,
            ],
        ],
        'series' => [
            [
                'name' => 'RM',
                'data' => $data->map(fn (TrendValue $value) => $value->aggregate),
                'type' => 'column',
            ],
        ],
        'stroke' => [
            'width' => [0, 4],
            'curve' => 'smooth',
        ],
        'xaxis' => [
            'categories' => $data->map(fn (TrendValue $value) => Carbon::parse($value->date)->format('M')),
            'labels' => [
                'style' => [
                    'colors' => '#9ca3af',
                    'fontWeight' => 600,
                ],
            ],
        ],
        'yaxis' => [
            'labels' => [
                'style' => [
                    'colors' => '#9ca3af',
                    'fontWeight' => 600,
                ],
            ],
        ],
        'legend' => [
            'labels' => [
                'colors' => '#9ca3af',
                'fontWeight' => 600,
            ],
        ],
        'colors' => ['#6366f1', '#38bdf8'],
        'fill' => [
            'type' => 'gradient',
            'gradient' => [
                'shade' => 'dark',
                'type' => 'vertical',
                'shadeIntensity' => 0.5,
                'gradientToColors' => ['#d946ef'],
                'inverseColors' => true,
                'opacityFrom' => 1,
                'opacityTo' => 1,
                'stops' => [0, 100],
            ],
        ],
        'plotOptions' => [
            'bar' => [
                'borderRadius' => 10,
            ],
        ],
    ];
}

public function data($i)
{
    $stat = new stat;

    return $stat->select('data')
        ->whereBetween('created_at', [now()->firstOfYear()->addMonths($i - 1)->toDateString(), now()->firstOfYear()->addMonths($i - 1)->endOfMonth()->toDateString()])
        ->sum('data');
}

The documentation were just being updated with adding reactive if using getFormSchema().

Is this a bug or something i am missing when using getFilters()

@margarizaldi
Copy link

margarizaldi commented Nov 5, 2023

Since it was too long for this issue to be fixed, I'm afraid that my PR #48 will also take a long time to be reviewed. I suggest you or everyone to publish the view and modify like the PR until it is fixed in the future release.

@leandrocfe
Copy link
Owner

Please check the new version and open a new issue if it was necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants