企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
### 方法 普通列实例: ```php $field = $tableHead->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(); ``` ### 链式调用 ```php $tableBuilder->setTableHead([ $this->tableHead->field('password_hash')->title('密码')->minWidth(300)->style([])->maxWidth()->alignRight()->alignCenter()->sort()->totalRow()->editText()->editTextarea() ]) ``` ### 表格构建示例 ~~~ $viewBuilder = $this->viewBuilder; $table = $viewBuilder->table; $table->setId('_admin_list'); if ($this->isAjax) { // AJAX $table->setQuery(function () { $params = $this->filteredGet; $query = Admin::find(); $query->filterWhere([ 'like', 'username', isset($params['keyword']) ? $params['keyword'] : null, ]); return $query; }) ->setOrderBy(['id' => SORT_DESC]) ->setColumns([ 'id', 'username', 'password_hash' => function($row) { return $row['password_hash']; }, 'email', 'mobile', 'status', 'group', 'created_at', 'updated_at', 'ro_delete3' => function ($row) { return $row['id'] % 2; }, ]) ->setExtraData(function (Query $query) { return [ 'tol' => $query->count(), 'a' => 100000, ]; }); $render = $viewBuilder->render(); //return $table->data; return $render; } else { // HTML $table->setTitle('管理员列表') ->setExtraDataTpl([ 'tol' => '当前总数量', 'a' => '所在院校', ]) //->registerPointcut(H5::alert('测试一下', 'success')) //->registerPointcut(H5::alert('测试一下'), TableBuilder::POS_END) ->setAjaxRoute('admin/index') // ->setLineStyle([ // 'height' => '350px', // ]) ->setTableHead([ $this->tableHead->checkbox()->style([]), $this->tableHead->field('password_hash')->title('密码')->minWidth(300), $this->tableHead->field('username')->title('账号')->editText('admin/edit'), $this->tableHead->field('email')->title('邮箱')->maxWidth(220), $this->tableHead->field('mobile')->title('手机号'), $this->tableHead->field('created_at')->title('添加时间'), $this->tableHead->field('updated_at')->title('更新时间'), $this->tableHead->toolbar()->title('操作项')->maxWidth(180), ]) ->setRowOperation([ // 详情 $this->rowOperation->modal()->title('详情')->icon('bi bi-plus-lg f15')->route('admin/detail')->closeBtn(), $this->rowOperation->ajax()->title('删除')->icon('bi bi-x-lg')->route('admin/delete')->method('POST')->group(), $this->rowOperation->ajax()->title('我要删除1')->icon('bi bi-x-lg')->route('admin/delete')->method('POST')->group(), $this->rowOperation->ajax()->title('我要删除2')->icon('bi bi-x-lg')->route('admin/delete')->method('POST')->group(), $this->rowOperation->ajax()->title('我要删除3')->id('ro_delete3')->icon('bi bi-x-lg')->route('admin/delete')->method('POST')->group(), ]) ->setToolbarCustom([ // 表单 $this->toolbarCustom->modal()->btnClass('layui-btn-primary layui-border')->title('表单')->icon('bi bi-plus-lg f15')->route('__upload/index')->width(916)->height(655), // 列表 $this->toolbarCustom->modal()->btnClass('layui-btn-primary layui-border-green')->title('列表')->icon('bi bi-plus-lg f15')->route('admin/detail')->closeBtn(), // 选项卡 $this->toolbarCustom->modal()->btnClass('layui-btn-primary layui-border-blue')->title('选项卡')->icon('bi bi-pencil-square f13')->route('admin/edit')->closeBtn(), // AJAX $this->toolbarCustom->page()->btnClass('layui-btn-primary layui-border-orange')->title('AJAX')->icon('bi bi-lock')->targetBlank()->params(['id'])->route('admin/add'), ]) ->setToolbarFilter([ 'keyword' => $this->toolbarFilter->text()->label('关键词')->placeholder('请输入账号/姓名')->defaultValue()->attribute(['test' => 1])->uiClass('w-330 mr-3'), //'username' => $this->toolbarFilter->datetime()->style(['width' => '800px'])->label('注册时间')->placeholder('请选择注册时间'), //'username' => $this->toolbarFilter->datetime()->label('注册时间')->placeholder('请选择注册时间'), /*'status' => $this->toolbarFilter->select()->label('用户状态')->uiClass(['layui-col-sm12'])->placeholder('请选择用户状态')->options([ '分组1' => [ 'normal' => '正常', 'deny' => '禁用', ], '分组2' => [ 'A' => '不可以', 'B' => '可以', ], ])->disabled(['deny'])->uiClass('w-330 mr-3'),*/ 'link1' => $this->toolbarFilter->selectLink()->label('联动1')->placeholder('请选择')->route('admin/link')->initOptions([ '测试1' => [ 'a' => 'A', 'b' => 'B' ], '测试2' => [ 'c' => 'C', 'd' => 'D' ], ])->disabled(['d'])->targetLink('link2')->start()->uiClass('w-330'), 'link2' => $this->toolbarFilter->selectLink()->label('')->placeholder('请选择')->route('admin/link')->targetLink('link3')->through()->uiClass('w-330'), 'link3' => $this->toolbarFilter->selectLink()->label('')->placeholder('请选择')->end()->uiClass('w-330'), ]) ->setAutoRequest(true); return $viewBuilder->render(); } ~~~