degecko/nova-filters-summary
最新稳定版本:2.1.0
Composer 安装命令:
composer require degecko/nova-filters-summary
包简介
A Laravel Nova card which displays a summary of the active filters of a resource or lens.
README 文档
README
A custom Card component for Laravel Nova which displays a summary of the active filters for a specific resource or lens.
Default Preview:
Stacked Preview:
Installation
Using Composer:
For Nova 4, use the current version. For older ones, use v1 of this package.
Nova v4:
composer require degecko/nova-filters-summary
Nova v1-3:
composer require degecko/nova-filters-summary:^1.1.0
Usage
Add it to the array returned by the cards method inside a Nova Resource or Lens.
<?php
namespace App\Nova;
use Degecko\NovaFiltersSummary\FiltersSummary;
use Illuminate\Http\Request;
class Product extends Resource
{
// Your setup.
public function cards(Request $request)
{
return [
FiltersSummary::make(),
];
}
}
Stacked
To use the stacked template, use FiltersSummary::make()->stacked().
Translation
To translate the three used words: active, filter, and filters, simply translate them using Laravel $lang.json file.
Custom Filter Summary Resolvers
The plugin knows how to display the information of the default Nova filters, but you might need to use custom filters. In that case, you'll probably need to create a custom template for the filter summary.
E.g.: I had a custom filter that allows a user to pick a numeric range of a specific column. You could use it to select products that have prices between 5 and 20 USD.
Now, because the filter maps to an object like this:
{ from: 5, to: 20 }
The summary would simply list that as its value, which isn't very pretty.
Therefore, if you want to customize that, you need to create a custom summary resolver for that filter.
The setup is pretty straight forward:
- Define a function inside
Nova.filtersSummaryResolversusing the same name as your filter component - The function will be fed the filter itself as a parameter
- Return the filter summary
I usually create the definition inside the filter's index.js file and it looks like this:
Nova.booting((Vue, router, store) => {
Vue.component('numeric-range-filter', require('./NumericFilter').default)
Nova.filtersSummaryResolvers['numeric-range-filter'] = filter => {
return [filter.currentValue.from || '<em>•</em>', filter.currentValue.to || '<em>•</em>'].join(' — ')
}
})
Author
统计信息
- 总下载量: 127.28k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 20
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-02-26