定制 jmf/grid-bundle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

jmf/grid-bundle

Composer 安装命令:

composer require jmf/grid-bundle

包简介

Grid bundle for Symfony

README 文档

README

A Symfony bundle for rendering HTML table grids from declarative YAML configuration and runtime data.

Requirements

  • PHP >= 8.3
  • Symfony 7 or 8

Installation

composer require jmf/grid-bundle

Register the bundle in config/bundles.php:

return [
    // ...
    Jmf\Grid\JmfGridBundle::class => ['all' => true],
];

Configuration

Create config/packages/jmf_grid.yaml:

jmf_grid:
    # template_path: '@JmfGrid/grid.html.twig'   # default
    # twig_functions_prefix: ''                  # default (e.g. set to 'jmf_' → jmf_grid())

    grids:
        articles:
            grid:
                variables:
                    entityType: 'article'
            rows:
                link: '{{ path("article.read", {"id": _item.id}) }}'
                variables:
                    entityId: '{{ _item.id }}'
            columns:
                -
                    label:  'Title'
                    source: 'title'
                -
                    preset: 'date'
                    source: 'publishedAt'
                -
                    preset: 'button_show'

Grid options

Key Description
grid.variables Key-value pairs available in all column/footer templates
grid.arguments Required runtime arguments (passed when calling grid())
rows.link Twig template for the row link URL. _item refers to the current data item
rows.variables Key-value Twig templates evaluated per row. _item is available
columns List of column definitions (see below)
footer List of footer cell definitions

Column options

Key Description
source Property path on the data item (uses Symfony PropertyAccess)
label Column header label
align Cell alignment (left, center, right, start, end)
template Twig template for cell content. _value holds the extracted value
preset Preset ID from jmf/rendering-preset-bundle (provides defaults for the above)

Column-level settings override preset values when both are defined.

Usage

In a Twig template:

{{ grid('articles', articles) }}

{# With runtime arguments: #}
{{ grid('articles', articles, {someArgument: 'value'}) }}

{# With extra template parameters: #}
{{ grid('articles', articles, {}, {class: 'table-striped'}) }}

The grid() function signature:

grid(gridId, items, arguments = [], parameters = [])
  • gridId — key from your jmf_grid.grids config
  • items — array of objects or associative arrays
  • arguments — runtime values for argument-gated grids
  • parameters — extra variables passed to the grid template

Presets

Columns and footer cells support a preset key that references a named preset from jmf/rendering-preset-bundle. Presets define reusable defaults for align, label, source, and template.

Example preset configuration (config/packages/jmf_preset_rendering.yaml):

jmf_preset_rendering:
    properties:
        align:
            choices: [center, left, right, start, end]
            default: left
            required: false
        label:
            required: false

    presets:
        date:
            align:    'center'
            template: '{% if (_value is not null) %}{{ _value.format("Y-m-d") }}{% endif %}'

        button_show:
            align:    'end'
            template: '<a href="{{ path(entityType ~ ".show", {"id": entityId}) }}">Show</a>'

        button_edit:
            align:    'end'
            template: '<a href="{{ path(entityType ~ ".edit", {"id": entityId}) }}">Edit</a>'

License

MIT

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: mit
  • 更新时间: 2023-04-03

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固