ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
## 方法 普通列实例: ```php $field = $treeTableHead->field('user'); ``` 列样式: ```php $field->style(['color' => 'brown']); ``` 头标题: ```php $field->title('用户'); ``` 列最小宽度: ```php $field->minWidth(300); ``` 列最大宽度: ```php $field->maxWidth(300); ``` 列文本居右: ```php $field->alignRight(); ``` 列文本居中: ```php $field->alignCenter(); ``` 静态排序: ```php $field->sort(); ``` 开启列统计: ```php $field->totalRow(); ``` 开启文本编辑: ```php $field->editText(); ``` 开启文本域编辑: ```php $field->editTextarea(); ``` ## 链式调用 ~~~ $treeTable->setTreeTableHead([ $this->treeTableHead->checkbox(), $this->treeTableHead->field('id')->title('ID')->totalRow(), $this->treeTableHead->field('name')->title('账号')->editText('admin/edit'), $this->treeTableHead->field('pid')->title('PID'), $this->treeTableHead->toolbar()->title('操作项'), ]) ~~~ ## 完整示例 ~~~ /** * demo * @return string * @throws \Throwable * @throws \builder\base\InvalidInstanceException * @throws \builder\base\NotFoundParamsException */ public function actionIndex() { $viewBuilder = $this->viewBuilder; $treeTable = $viewBuilder->treeTable; $treeTable->setId('_tree_table_list'); if ($this->isAjax) { // AJAX $treeTable->setQuery(function () { $params = $this->filteredGet; $query = Test::query()->where([ 'pid' => 0, ]); $query->filterWhere([ 'like', 'name', isset($params['keyword']) ? $params['keyword'] : null, ]); return $query; }) ->setOrderBy(['id' => SORT_DESC]) ->setTtColumns([ 'id', 'name', 'pid', 'isParent' => function ($row) { return 1; }, 'ro_delete3' => function ($row) { return $row['id'] % 2; }, ])->setExtraData(function (Query $query) { return [ 'tol' => $query->count(), 'a' => 100000, ]; }); $render = $viewBuilder->render(); //return $treeTable->data; return $render; } else { // HTML $treeTable->setTitle('管理员列表') ->setExtraDataTpl([ 'tol' => '当前总数量', 'a' => '所在院校', ]) ->setOpenTotalRow() ->registerPointcut(H5::alert('测试一下', 'success')) ->registerPointcut(H5::alert('测试一下'), TreeTableBuilder::POS_END) ->setAjaxRoute('tree-table/index') ->setTreeTableHead([ $this->treeTableHead->checkbox(), $this->treeTableHead->field('id')->title('ID')->totalRow(), $this->treeTableHead->field('name')->title('账号')->editText('admin/edit'), $this->treeTableHead->field('pid')->title('PID'), $this->treeTableHead->toolbar()->title('操作项'), ]) ->setTreeAsyncOption('tree-table/children') ->setTreeCustomNameOption([]) ->setTreeViewOption([]) ->setTreeDataOption([]) ->setTtRowOperation([ // 详情 $this->ttRowOperation->modal()->title('详情')->icon('bi bi-plus-lg f15')->route('admin/detail')->closeBtn(), $this->ttRowOperation->ajax()->title('删除')->icon('bi bi-x-lg')->route('admin/delete')->method('POST')->group(), $this->ttRowOperation->ajax()->title('我要删除1')->icon('bi bi-x-lg')->route('admin/delete')->method('POST')->group(), $this->ttRowOperation->ajax()->title('我要删除2')->icon('bi bi-x-lg')->route('admin/delete')->method('POST')->group(), $this->ttRowOperation->ajax()->title('我要删除3')->id('ro_delete3')->icon('bi bi-x-lg')->route('admin/delete')->method('POST')->group(), ]) ->setTtToolbarExpandAll() ->setTtToolbarCustom([ // 表单 $this->ttToolbarCustom->modal()->btnClass('layui-btn-primary layui-border')->title('表单')->icon('bi bi-plus-lg f15')->route('admin/add'), // 列表 $this->ttToolbarCustom->modal()->btnClass('layui-btn-primary layui-border-green')->title('列表')->params(['id'])->icon('bi bi-plus-lg f15')->route('admin/detail')->closeBtn(), // 选项卡 $this->ttToolbarCustom->modal()->btnClass('layui-btn-primary layui-border-blue')->title('选项卡')->icon('bi bi-pencil-square f13')->route('admin/edit')->closeBtn(), // AJAX $this->ttToolbarCustom->page()->btnClass('layui-btn-primary layui-border-orange')->title('AJAX')->icon('bi bi-lock')->targetBlank()->params(['id'])->route('admin/add'), ]) ->setTtToolbarFilter([ 'keyword' => $this->ttToolbarFilter->text()->label('关键词')->placeholder('请输入账号/姓名')->defaultValue()->attribute(['test' => 1]), //'username' => $this->ttToolbarFilter->datetime()->style(['width' => '800px'])->label('注册时间')->placeholder('请选择注册时间'), //'username' => $this->ttToolbarFilter->datetime()->label('注册时间')->placeholder('请选择注册时间'), 'status' => $this->ttToolbarFilter->select()->label('用户状态')->placeholder('请选择用户状态')->options([ '测试' => [ 'normal' => '正常', 'deny' => '禁用', ], '测试2' => [ 'normal1' => '正常1', 'deny1' => '禁用1', ], ])->disabled(['normal']), 'link1' => $this->ttToolbarFilter->selectLink()->label('联动1')->placeholder('请选择')->route('admin/link')->initOptions([ 'AAA' => [ 'a' => 'A', 'b' => 'B' ], 'BBB' => [ 'c' => 'C', 'd' => 'D' ], ])->disabled(['c'])->targetLink('link2')->start(), 'link2' => $this->ttToolbarFilter->selectLink()->label('联动2')->placeholder('请选择')->route('admin/link')->targetLink('link3')->through(), 'link3' => $this->ttToolbarFilter->selectLink()->label('联动3')->placeholder('请选择')->route('admin/link')->targetLink('link4')->through(), 'link4' => $this->ttToolbarFilter->selectLink()->label('联动2')->placeholder('请选择')->end(), ]) ->setAutoRequest(true); return $viewBuilder->render(); } } ~~~