willsprod/ux-datatables
Composer 安装命令:
composer require willsprod/ux-datatables
包简介
DataTables.net integration for Symfony
README 文档
README
This bundle integrates DataTables.net with Symfony UX using Stimulus.
Features
- Easy integration of DataTables in Symfony projects.
Requirements
- PHP 8.1 or higher
- StimulusBundle
- Composer
Installation
composer require WillsProd/ux-datatables
Make sure StimulusBundle is installed:
composer require symfony/stimulus-bundle
Usage
Build you dataTable in your controller:
$table = new DataTable(); return $this->render('path/to/your/twig', [ 'table' => $table ])
Render the dataTable in your twig template:
render_datatable(table)
Example to show users List in Symfony
//App/Controller/UserController.php #[Route(name: 'app_user_index', methods: ['GET'])] public function index(DataTableBuilderInterface $builder): Response { $table = $builder->createDataTable('userTable'); $table->setOptions([ "columns" => [ ["title" => 'ID'], ["title" => 'Email'], ["title" => 'Roles'], ["title" => 'Actions'], ], "ajax" => [ 'url' => $this->generateUrl("app_user_list"), 'dataSrc' => '' ], 'language' => [ 'url' => 'https://cdn.datatables.net/plug-ins/1.13.7/i18n/fr-FR.json' //use https://datatables.net/plug-ins/i18n/ to find your langage ], "columnDefs" => [ [ "targets" => [0], // ID column "visible" => false, "searchable" => false, ], [ "targets" => [3], // Actions column "className" => "text-base !font-normal text-slate-600 border-b !border-b-slate-100 !p-1 text-right dt-head-right" // Using tailwind classes - you can install tailwind by using composer require symfonycasts/tailwindBundle - Please refer to the official documentation : https://symfony.com/bundles/TailwindBundle/current/index.html ], [ "targets" => [1, 2, 3], "className" => "text-base !font-normal text-slate-600 border-b !border-b-slate-100 !p-1" ], ], "search_input" => [ "className" => "!border-0 shadow rounded-lg" ] ]); return $this->render('user/index.html.twig', [ 'table' => $table ]); }
#[Route("/api/users", name: 'app_user_list', methods: ['GET'])] public function usersList(UserRepository $userRepository): JsonResponse { $showRoute = "app_user_show"; $editRoute = "app_user_edit"; return $this->json($userRepository->findUsers($showRoute, $editRoute)); }
//App/Repository/UserRepository public function findUsers(string $showRoute, string $editRoute): array { $qb = $this->createQueryBuilder('u'); $qb->select('u.id', 'u.email', 'u.roles'); $result = $qb->getQuery()->getScalarResult(); return array_map(function ($row) use ($showRoute, $editRoute) { return [ $row['id'], $row['email'], $row['roles'], sprintf( "<a href='%s' class='text-blue-500'>Details</a> | <a href='%s' class='text-green-500'>Edit</a>", $this->urlGenerator->generate($showRoute, ['id' => $row['id']]), $this->urlGenerator->generate($editRoute, ['id' => $row['id']]) ) ]; }, $result); }
<!-- templates/user/index.html.twig --> {% extends 'base.html.twig' %} {% block title %}Users list{% endblock %} {% block body %} <h1 class="text-lg text-slate-600">Users list</h1> <div class="p-4 rounded-lg bg-white overflow-x-auto flex flex-col space-y-4"> <div class="flex items-center"> <a href="{{ path('app_user_new') }}" class="flex items-center justify-center h-10 rounded-lg px-4 text-white bg-purple-400 duration-150 hover:bg-purple-500">Add user</a> </div> {{ render_datatable(table) }} </div> {% endblock %}
willsprod/ux-datatables 适用场景与选型建议
willsprod/ux-datatables 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 19 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 07 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony」 「datatable」 「stimulus」 「symfony-ux」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 willsprod/ux-datatables 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 willsprod/ux-datatables 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 willsprod/ux-datatables 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
DataTables is a plug-in for the jQuery Javascript library. It is a highly flexible tool, based upon the foundations of progressive enhancement, which will add advanced interaction controls to any HTML table.
Plug-ins for DataTables
Use Stimulus in your Laravel app
The bundle for easy using json-rpc api on your project
Data Table will allow you to easily create Listing, Searching, Sorting and Download CSV.
Bundle Symfony DaplosBundle
统计信息
- 总下载量: 19
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 21
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-07-23