Skip to content

CatchTable 表单栏目类文档

概述

Column 类是 CatchTable 构建器中的一个核心组件,用于定义表格中的列。该类实现了 JsonSerializable 接口,允许将列的配置转换为 JSON 格式。

类定义

php
namespace CatchForm\Table;

use JsonSerializable;

class Column implements JsonSerializable
{
    protected array $column = [];

    public function __construct(string $label, string $props = '')
    {
        $this->column['label'] = $label;

        if ($props) {
            $this->column['props'] = $props;
        }
    }
}

构造函数

__construct(string $label, string $props = '')

  • 参数:
    • label: 列的标签。
    • props: 列的属性(可选)。

可用方法

方法描述
selection(): static设置列为选择列。
type(string $type): static设置列的类型。
expand(): static设置列为扩展列。
id(): static设置 ID 列
width(int string $width): static设置列的宽度。
slot(string $slot): static设置列的插槽名称。
header(string $header): static设置列的表头。
align(string $align): static设置列的对齐方式。
fixed(string $fixed): static设置列的固定位置(如:'fixed'、'right'、'left')。
sortable(bool $sortable = true): static设置列是否可排序。
resizable(bool $resizable): static设置列是否可调整大小。
headerAlign(string $align): static设置表头的对齐方式
show(bool $show): static设置列是否显示。
children(array $columns): static设置子列。
index($index): static设置列的索引。
switch(bool $switch = true): static设置列是否为开关。
ellipsis(bool $ellipsis = true): static设置列是否使用省略文字。
image(bool $image = true): static设置列是否为图片预览。
preview(bool $preview = true): static设置列是否为预览。
tags( array $tag): static设置列的标签
link(bool $isLink, string $linkText): static设置列为链接。
update(bool $update = true): static设置列是否可更新。
destroy(bool $destroy = true): static设置列是否可删除。
column(string $key, mixed $value): static设置列的属性。
operate(): static设置 操作列
filter(): static设置 filter 方法

filter 方法

filter 目前支持字符串方法,前端会自动渲染成方法处理

php
$table->column('status', '状态')->filter(<<<FUNC
   (value) => {
      return value === 1 ? '轮播图' : value === 2 ? '友情链接' : '广告'
    }
FUNC)

示例

以下是使用 Column 类的示例:

php
use CatchForm\Table\Column;

$column = new Column('姓名', 'name');
$column->width(150) // 设置列宽度
       ->sortable(true) // 使列可排序
       ->align('center') // 设置列内容居中
       ->show(true) // 显示该列
       ->tags(['重要', '用户']); // 添加标签

$json = json_encode($column); // 将列配置转换为 JSON 格式