首页 > 解决方案 > CRUD 背包 Laravel 。图表更新,当 Ajax 过滤器改变时

问题描述

请避免给我负面评价谢谢

在 Laravel Backpack 管理员中,当我们单击 Date Range filters 时,它正在过滤我们的表格数据,这工作正常,但我希望 Graph 在我们更改 ajax 过滤器时也得到更改。

在此处输入图像描述

据我所知, CrudConTroller 中的 ajax 日期范围过滤器代码:

 $this->crud->addFilter([
        'type'  => 'date_range',
        'name'  => 'created_at',
        'label' => 'Date range'
    ],
        false,
        function ($value) { // if the filter is active, apply these constraints
             $dates = json_decode($value);
             $this->crud->addClause('where', 'created_at', '>=', $dates->from);
             $this->crud->addClause('where', 'created_at', '<=', $dates->to . ' 23:59:59');
    });

并且图形出现在小部件中,刀片模板文件:list.blade.php。

 $widgets['before_content'][] = [
            'type' => 'div',
            'class' => 'row',
            'content' => [ // widgets
                [
                    'type' => 'chart',
                    'wrapperClass' => 'mt-4 col-md-12',
                    // 'class' => 'col-md-12',
                    'controller' => \App\Http\Controllers\Admin\Charts\UserChartController::class,
                    'content' => [
                        'header' => 'New Users', // optional
                         'body' => 'This chart should make it obvious', // optional
                    ]
                ],
            ],
        ]

标签: phplaravelgraphadminlaravel-backpack

解决方案


有很多解决方案可以使用 php 来生成图表而不是模板。请参阅中的相关部分。文档。

然后使用请求参数来过滤图表的数据。我将尝试发布一个示例。


推荐阅读