willsprod/ux-datatables 问题修复 & 功能扩展

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

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

willsprod/ux-datatables

Composer 安装命令:

composer require willsprod/ux-datatables

包简介

DataTables.net integration for Symfony

README 文档

README

Packagist Version License Symfony UX

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 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-07-23