fazzinipierluigi/laraexpress_datasource
Composer 安装命令:
composer require fazzinipierluigi/laraexpress_datasource
包简介
A laravel library that generates a data source for DevExpress frontend libraries
README 文档
README
This library provides a helper for generating datasources for widgets in the DevExpress javascript library.
Advancement
- Load
- Filters
- Sorting
- Pagination
- Grouping
- Insert
- Update
- Delete
Usage
Inside the method in your controller:
public function index(Request $request) { if($request->ajax()) { $users = \App\Model\User::where('is_admin', '=', 0); $data_source = new EloquentSource(); // Remember that you have to add the "use" directive first. $data_source->apply($users, $request); return $data_source->getResponse(); } else { return view('user.index') } }
You can pass the frontend timezone to the constructor (the default is 'Euurope/Rome'), alternatively you can set it later with the setTimezone method
$my_data_source = new EloquentSource(); // This has as its timezone "Europe/Rome" // These two options are equivalent $data_source = new EloquentSource("America/Chicago"); $data_source->setTimezone("America/Chicago");
In the frontend we first include the library for the data store (go to documentation), in my case:
<script src="https://unpkg.com/devextreme-aspnet-data/js/dx.aspnet.data.js"></script>
after that:
$("#dataGridContainer").dxDataGrid({ dataSource: DevExpress.data.AspNet.createStore({ loadUrl: '{{ URL::current() }}', }), remoteOperations: { filtering: true, sorting: true, paging: true, grouping: true, groupPaging: true, }, // ... })
The apply method accepts a third optional parameter, namely "field_map", this parameter is used to map the database fields in case fields are renamed in the generation of the response or if more than one database column corresponds to a datagrid column:
public function index(Request $request) { if($request->ajax()) { $users = \App\Model\User::select('users.*'); $data_source = new EloquentSource(); $field_map = [ // I create the array that contains the mapping field name => column name 'fiscal_reference' => ['users.tax_code', 'users.vat'], 'creation_date' => 'created_at' ]; $data_source->apply($users, $request, $field_map); return $data_source->getResponse(function($data) { // Optionally you can pass a Clojure function // to the "getResponse" function to format the // data or perform operations. If it is not // provided the toArray() method will be used. return [ 'username' => $data->username; 'fiscal_reference' => ($data->is_company())? $data->vat : $data->tax_code; 'creation_date' => $data->created_at->format('d/m/Y'); // ... and so on ]; }); } else { return view('user.index') } }
The "apply" method also accepts an optional fourth parameter; this is used to override the sorting behavior:
public function index(Request $request) { if($request->ajax()) { $contracts = \App\Model\Contracts::select('contracts.*') ->join('customers', 'customers.id', '=', 'contracts.customer_id'); $data_source = new EloquentSource(); $field_map = [ // I create the array that contains the mapping field name => column name 'customer' => 'customers.id' ]; $field_sorting = [ 'customer' => 'customers.company_name' ]; $data_source->apply($contracts, $request, $field_map, $field_sorting); return $data_source->getResponse(function($data) { // .... }); } else { return view('customer.index') } }
In this case if we had passed only the "field_map" array to apply the sorting would have been done based on the customer id, instead by overriding it we can force the sorting by company name while still maintaining the search by id.
fazzinipierluigi/laraexpress_datasource 适用场景与选型建议
fazzinipierluigi/laraexpress_datasource 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 226 次下载、GitHub Stars 达 4, 最近一次更新时间为 2023 年 06 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「library」 「laravel」 「datasource」 「eloquent」 「devexpress」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 fazzinipierluigi/laraexpress_datasource 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 fazzinipierluigi/laraexpress_datasource 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 fazzinipierluigi/laraexpress_datasource 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
FSi DataSource Component
FSi DataSource Bundle
MongoDB Datasource for CakePHP
AWS S3 datasource in CakePHP3
Inbox pattern process implementation for your Laravel Applications
A library providing abstract implementations of various persistence layers based on JSON API relational resource concepts.
统计信息
- 总下载量: 226
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-or-later
- 更新时间: 2023-06-13