rafwell / laravel-simplegrid
一个用于使用 Laravel 生成强大网格的简单组件。
Requires
- php: >=8.0
- barryvdh/laravel-snappy: ^1.0
- box/spout: ^3.3
- tgalopin/html-sanitizer: ^1.4
- dev-master
- 3.0.2
- 3.0.1
- 3.0.0
- 2.25.2
- 2.25.1
- 2.25.0
- 2.24.1
- 2.24.0
- 2.23.5
- 2.23.4
- 2.23.3
- 2.23.2
- 2.23.1
- 2.23.0
- 2.22.1
- 2.22.0
- 2.21.2
- 2.21.1
- 2.21.0
- 2.20.0
- 2.19.0
- 2.18.1
- 2.1.3
- 2.1.2
- 2.1.1
- 2.1.0
- 2.0.0
- 1.19.2
- 1.19.1
- 1.19.0
- 1.18.0
- 1.17.4
- 1.17.3
- 1.17.2
- 1.17.1
- 1.17.0
- 1.16.0
- 1.15.9
- 1.15.8
- 1.15.7
- 1.15.6
- 1.15.5
- 1.15.4
- 1.15.3
- 1.15.2
- 1.15.1
- 1.15.0
- 1.14.0
- 1.13.0
- 1.12.1
- 1.12.0
- 1.11.5
- 1.11.4
- 1.11.3
- 1.11.2
- 1.11.1
- 1.11.0
- 1.10.0
- 1.9.2
- 1.9.1
- 1.9.0
- 1.8.2
- 1.8.1
- 1.8.0
- 1.7.3
- 1.7.2
- 1.7.1
- 1.7.0
- 1.6.1
- 1.6.0
- 1.5.6
- 1.5.5
- 1.5.4
- 1.5.3
- 1.5.2
- 1.5.1
- 1.5.0
- 1.4.1
- 1.4.0
- 1.3.0
- 1.2.4
- 1.2.3
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.3
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.0
- 0.0.2
- 0.0.1
- dev-laravel9
This package is auto-updated.
Last update: 2024-08-31 00:35:29 UTC
README
rafwell/laravel-simplegrid 是一个用于构建强大网格的组件,代码量少。该组件与 Bootstrap 3 兼容,具有导出为 xls、csv 和 pdf、简单/高级搜索、排序、行内或批量操作等功能。
兼容性
rafwell/laravel-simplegrid 兼容 Laravel 5.2 及以上版本。
安装
- 将依赖添加到您的 composer.json 文件中
composer require "rafwell/laravel-simplegrid"或"rafwell/laravel-simplegrid": "^2.0"。 - 执行
composer update。 - 将我们的服务提供者
Rafwell\Simplegrid\SimplegridServiceProvider::class添加到您的config/app.php文件中。 - 执行
php artisan vendor:publish --provider="Rafwell\Simplegrid\SimplegridServiceProvider"。 - 在您的 HTML 中包含 js 和 css 依赖项。
依赖项
本包是为了与 Bootstrap 3 和 jQuery 一起使用而编写的。我们需要以下依赖项
- Datetimepicker,用于在日期和日期时间字段中进行高级搜索。
- Moment,用于 Datetimepicker 的功能。
我们已将以下依赖项添加到我们的包中。您可以从 public/vendor/rafwell/simple-grid 中添加此依赖项,如下所示
CSS 文件
<!-- ONLY INCLUDE IF YOU NOT HAVE THOSE DEPENDENCIES --> <link rel="stylesheet" href="vendor/rafwell/simple-grid/eonasdan-bootstrap-datetimepicker/build/css/bootstrap-datetimepicker.min.css" /> <!-- CSS LARAVEL SIMPLEGRID --> <link rel="stylesheet" href="vendor/rafwell/simple-grid/css/simplegrid.css">
JS 文件
<!-- ONLY INCLUDE IF YOU NOT HAVE THOSE DEPENDENCIES --> <script src="vendor/rafwell/simple-grid/moment/moment.js"></script> <script type="text/javascript" src="vendor/rafwell/simple-grid/eonasdan-bootstrap-datetimepicker/build/js/bootstrap-datetimepicker.min.js"></script> <!-- JS LARAVEL SIMPLEGRID --> <script src="vendor/rafwell/simple-grid/js/simplegrid.js"></script>
一个简单示例
在您的控制器中
use Rafwell\Simplegrid\Grid;
在您的函数中
$Grid = new Grid(Employe::query(), 'Employes'); $Grid->fields([ 'birth_date'=>'Birthday', 'first_name'=>'First Name', 'last_name'=>'Last Name', 'gender'=>[ 'label'=>'Gender', 'field'=>"case when gender = 'M' then 'Male' else 'Female' end" ] ]); return view('yourview', ['grid'=>$Grid]);
在您的视图中
{!!$grid->make()!!}
一个更复杂的示例
将您的控制器代码更改为
$Grid->fields([ 'birth_date'=>'Birthday', 'first_name'=>'First Name', 'last_name'=>'Last Name', 'gender'=>[ 'label'=>'Gender', 'field'=>"case when gender = 'M' then 'Male' else 'Female' end" ] ]) ->actionFields([ 'emp_no' //The fields used for process actions. those not are showed ]) ->advancedSearch([ 'birth_date'=>['type'=>'date','label'=>'Birthday'], 'first_name'=>'First Name', // It's a shortcut for ['type'=>'text', 'label'=>'First Name'], 'last_name'=>[ //omiting the label. I'ts a shortcut, like above 'type'=>'text', 'sanitize'=>false //This field will not be sanitized ], 'gender'=>[ 'type'=>'select', 'label'=>'Gender', 'options'=>['Male'=>'Male', 'Female'=>'Female'] //The key is the value of option ] ]); $Grid->action('Edit', 'test/edit/{emp_no}') ->action('Delete', 'test/{emp_no}', [ 'confirm'=>'Do you with so continue?', 'method'=>'DELETE', ]); $Grid->checkbox(true, 'emp_no'); $Grid->bulkAction('Delete selected itens', '/test/bulk-delete');
您的模型有关系吗?试试看
//Make your query using eloquent orm normally $Employe = Employe::join('supervisors', 'supervisors.id','=','employees.supervisor_id'); $Grid = new Grid($Employe, 'Employes'); //Here, the key or array of fields is the name of the field. so, you can concatenate with the table name //You can make sub queries too $Grid->fields([ 'birth_date'=>'Birthday', //If you not explicit the name of table, we use the principal table of query builded. in this case, employees's 'first_name'=>'First Name', 'last_name'=>'Last Name', 'gender'=>[ 'label'=>'Gender', 'field'=>"case when gender = 'M' then 'Male' else 'Female' end" //This is a calculated field too ], 'supervisors.name'=>'Supervisor Name', //There the example with relationship 'virtual_field'=>[ 'label'=>'My first virtual field', 'field'=>'(select column from table where...)' //Obviously, this subquery must return only 1 row ] ]); //Continue code... //Easier than that? :)
转换器
当渲染器被调用时,主表的所有 get 转换器都将正常工作。为了在显示之前个性化或特性化一行,为了创建可视化的连接或格式化器,您可以使用 processLine 方法
$Grid->fields([ 'birth_date'=>'Birthday', 'first_name'=>'First Name', 'last_name'=>'Last Name', 'gender'=>'Gender' ]) ->processLine(function($row){ //This function will be called for each row $row['gender'] = $row['gender'] == 'M' ? 'Male' : 'Female'; //Do more you need on this row return $row; //Do not forget to return the row });
在某些情况下,某些操作可能无法调用。例如,如果状态等于 2,则不允许编辑按钮
$Grid->fields([ 'birth_date'=>'Birthday', 'first_name'=>'First Name', 'last_name'=>'Last Name', 'gender'=>'Gender', 'status'=>'Status'//It's a integer on database. If 2 not allowed edit ]) >action('Edit', 'test/edit/{emp_no}') ->processLine(function($row){ //This function will be called for each row if($row['status']==2) unset($row['gridActions']['edit']); //Do more you need on this row return $row; //Do not forget to return the row }); //Awesome!
额外配置
发布我们的服务提供者后,将在您的配置文件夹中生成一个名为 rafwell-simplegrid.php 的文件。在其中,您可以更改高级搜索中日期和日期时间字段的格式,'每页显示 x 行' 的初始值等等!
语言
本包支持多语言。我们使用您Laravel安装的位置,配置在您的config/app.php文件中。如果有翻译,它将自动加载。您可以在我们的lang文件夹中查看当前支持的语言。
免责声明
此存储库是新创建的,'forked'自rafwell/laravel-grid。原始存储库没有考虑多语言功能。为了支持多语言功能,它已被终止。
贡献
如果您想贡献,可以打开问题进行讨论。
许可证
MIT许可证(MIT)。有关更多信息,请参阅许可证文件。
重大变更日志
- 自2.0版本以来,我们默认添加了html-sanitizer。如果您在网格中显示一些特定的HTML实体,这可能会破坏您的代码。请注意,在1版本中,防止这种情况是您的责任。如果您在渲染之前没有清理数据,它们可能是不安全的,您可能容易受到XSS攻击。我们强烈建议您升级到2.0版本,默认允许的标签非常常见,很少会影响您的代码。