softivo/data-grid-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

softivo/data-grid-bundle

Composer 安装命令:

composer require softivo/data-grid-bundle

包简介

Symfony third party bundle allow to generate paginated, sortable and filterable grids and lists, based on given data provider

README 文档

README

About The Project

Symfony third party bundle allow to generate paginated, sortable and filterable grids and lists, based on given data provider.

Getting Started

Requirements

This bundle is designed for Symfony Framework. To be able to use the bundle, follow the requirements below:

  • php ^8.1
  • Symfony ^5.2 | ^6.0
  • Twig
  • jQuery
  • Webpack Encore & Symfony Stimulus Bridge

Installation

  1. Install the package
    composer require softivo/datagridbundle
    
  2. Install assets.

    Add package and install dependencies

    The bundle uses @symfony/stimulus-bridge to asset management. By your preferred package manager like npm or yarn, simply install required assets. Below sample installation using yarn:

     yarn add link:./vendor/softivo/data-grid-bundle/src/Resources/assets
    

    Configure stimulus controller

    Add previously installed @softivo/data-grid-bundle controller to your application. Third party controllers should be placed in controllers.json file. By default, this file is located in assets/controllers.json. Sample configuration may look like:

     {
       "controllers": {
         "@softivo/data-grid-bundle": {
           "main": {
             "fetch": "eager",
             "enabled": true,
             "autoimport": {
               "@softivo/data-grid/dist/style.min.css": true
             }
           }
         }
       }
     }
    

    Build your assets

    If you're using Webpack Encore for building your project, make the build at this moment.

    // build dev environment 
    encore dev
       
    //build production environment
     encore production --progress
    
  3. Make sure if new bundle was added to your symfony application. Otherwise, do it by yourself in ./config/bunldes.php file.
    Softivo\DataGridBundle\DataGridBundle::class => ['all' => true]
    

Sample Usage

Data Transformer

Firstly you need to create data transformer implements Softivo\DataGridBundle\Interface\DataTransformerInterface interface. Recommended way is to create transformer as a symfony service, to be able easily inject your dependencies. The transformer is responsible for transform given data to the view form.

class SampleTransformer implements Softivo\DataGridBundle\Interface\DataTransformerInterface
{
    // ...

    /**
     * Use column attributes to define their settings, follow by hints
     * Regarding strings values, in most cases value can be the name of callable method of the class 
     * #[Softivo\DataGridBundle\Column\TextColumn()] 
    */
    public $column;

    /**
     * Use the magic function __invoke() to transform source data, into desire view form
     * @param Type $object
     */
    public function __invoke($object): void
    {
        // ...
        
        $this->column = $object->getSampleValue();
    }

{

Create Data Grid

Next, you should inject your transformer into your controller action. Use the Softivo\DataGridBundle\Factory\DataGridProviderInterface symfony service to create as many grids as you want.

class SampleController extends AbstractController 
{

    use App\SampleTransformer;
    use Softivo\DataGridBundle\Factory\DataGridProviderInterface;
    use \Symfony\Component\HttpFoundation\Request;

    // ...
    
    public function action(SampleProvider $sampleProvider, DataGridProviderInterface $provider, Request $request)
    {
        /**
        * Configure data grid passing unique ID, your data transformer and data source.
        * The source may be QueryBuilder instance, or simply array with data.
        */
        $dataGrid = $provider->createDataGrid('uniqueId', $sampleProvider, $query)
            // ...
            // change available settings for this data grid instance only.
            // Make sure handleRequest is called the last one.
            ->handleRequest($request);

        // Pass DataProvider into your template
        return $this->render('template.html.twig', [
            'dataGrid' => $dataGrid
        ]);  
    }

{

Render The View

The last step, using created data grid, you can render the data in html table, or as a list, depends on your needs. Basic function for rendering html table is data_grid_table.

{{ data_grid_table(
dataGrid,
// custom array of html table attributes
) }}

data_grid_list function allow to pass html attributes for main container and all items inside.

{{ data_grid_list(
dataGrid,
'path/to/template.html.twig'
// custom array of html container attributes
// custom array of html rows attributes
) }}

You can also render each component by your own using twig functions, similarly to symfony forms.

{{ data_grid_start(dataGrid) }}
...
{{ data_grid_summary(dataGrid) }}
...
{{ data_grid_pagination(dataGrid) }}
...
{{ data_grid_table(dataGrid) }} OR {{ data_grid_list(dataGrid) }}
...
{{ data_grid_end(dataGrid) }}

Documentation

More detailed documentation can be found at https://softivo.gitlab.io/datagridbundle

License

Distributed under the MIT License.

Contact

Softivo kontakt@softivo.pl

GitLab https://gitlab.com/softivo/datagridbundle.git

softivo/data-grid-bundle 适用场景与选型建议

softivo/data-grid-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 36 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 05 月 16 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「symfony」 「pagination」 「bundle」 「grid」 「table」 「sorting」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 softivo/data-grid-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 softivo/data-grid-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 softivo/data-grid-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 36
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 17
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-05-16