kibatic/datagrid-bundle
Composer 安装命令:
composer require kibatic/datagrid-bundle
包简介
Datagrid for Symfony
关键字:
README 文档
README
Datagrid bundle for Symfony with the following design philosophy : less magic for more flexibility.
It's not the usual one line datagrid generator, it's a more verbose one but we think it's worth it.
Features
- Your entities in a table
- Pagination
- Sortable
- Filterable
- Actions (single & batch)
- Customizable templates
- Only supports Doctrine ORM
- Theme support (Bootstrap 5 included)
Quick start
Install the bundle
composer require kibatic/datagrid-bundle
Add this to your assets/controllers.json :
{
"controllers": {
"@kibatic/datagrid-bundle": {
"checker": {
"enabled": true,
"fetch": "eager"
}
}
}
You'll most likely also need to enable this twig function : https://twig.symfony.com/doc/2.x/functions/template_from_string.html
It's not a hard dependency but some features shown here also requires you to install kibatic/ux-bundle :
composer require kibatic/ux-bundle
If you want to use the default templates styles and you don't have bootstrap css loaded yet, you will need to.
If you're using AssetMapper, you can simply add this to your assets/app.js :
import 'bootstrap/dist/css/bootstrap.min.css';
Basic usage
You can simply generate a specialized datagrid builder class skeleton using the make command :
bin/console make:datagrid
Or do everything manually, for example in your controller :
<?php namespace App\Controller; use App\Entity\Project; use App\Repository\ProjectRepository; use Kibatic\DatagridBundle\Grid\GridBuilder; use Kibatic\DatagridBundle\Grid\Template; use Kibatic\DatagridBundle\Grid\Theme; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; class ProjectController extends AbstractController { #[Route('/', name: 'app_project_index', methods: ['GET'])] public function index( ProjectRepository $projectRepository, GridBuilder $gridBuilder, ): Response { // get current user $user = $this->getUser(); // create query builder filtered by current user $queryBuilder = $projectRepository->createQueryBuilder('p') ->where('p.owner = :user') ->setParameter('user', $user) ->orderBy('p.createdAt', 'DESC'); ; $grid = $gridBuilder ->initialize(queryBuilder: $queryBuilder) ->addColumn('Name', 'name') ->addColumn( 'Created at', 'createdAt', Template::DATETIME, sortable: 'createdAt' ) ->getGrid() ; return $this->render('project/index.html.twig', [ 'grid' => $grid ]); } }
Then with Symfony UX handy twig components :
{% extends 'base.html.twig' %}
{% block body %}
<h1>Project list</h1>
<twig:datagrid :grid="grid" />
{% endblock %}
Or a more classic twig approach :
{% extends 'base.html.twig' %}
{% block body %}
<h1>Project list</h1>
{% include grid.theme ~ '/datagrid.html.twig' %}
{% endblock %}
Documentation
You can find a more advanced example on how to generate your datagrid.
If you want to customize the pagination, use the knp paginator configuration.
# config/packages/knp_paginator.yaml
knp_paginator:
page_limit: 20
If you're using a datagrid inside a live component (symfony ux), you'll need to do this.
Requirements
- Symfony 6
- PHP 8.2
- Doctrine ORM
Roadmap
- Adding a Flex recipe
kibatic/datagrid-bundle 适用场景与选型建议
kibatic/datagrid-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 19.23k 次下载、GitHub Stars 达 14, 最近一次更新时间为 2022 年 05 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「datagrid」 「symfony-ux」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 kibatic/datagrid-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 kibatic/datagrid-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 kibatic/datagrid-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
FSi DataIndexer Component - Component created to provide one simple object indexing strategy for FSi DataSource and DataGrid components.
FSi DataGrid Component
Sylius eCommerce administration panel component.
Doctrine Block management made easy
Symfony DataGridBundle
Symfony bundle for the Rekapager library
统计信息
- 总下载量: 19.23k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 14
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-05-25