🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
### 配置项`columns` > 定义表格列 参数 1. `array $columns` 数组元素定义 > 第一种:`键值对` > + 键: 数据库表列字段 > + 值:需调用`table_column_helper`函数,参数1:列标题、参数2:选项,支持的配置项有`style`、`attribute` 、参数3::自定义回调,用来自定义字段值 > 第二种: `列字段` 示例代码: ~~~ return ViewBuilder::table() ->setPage(true) ->setHideCheckbox(false) ->setColumns([ 'password', 'username' => table_column_helper('用户名', ['style' => ['min-width' => '100px']]), 'email' => table_column_helper('邮箱', ['style' => ['min-width' => '200px']]), ]) ->setQuery(function () { $query = AdminUser::find()->select(['id', 'username', 'password', 'email']); return $query; }) ->render($this); ~~~ > `columns` 值要求是一个一维数组,数组元素可以是`键值对`也可以是列的字段。 自定义字段值: 回调参数`$item`是当前列的数据集合 ~~~ return ViewBuilder::table() ->setPage(true) ->setHideCheckbox(false) ->setColumns([ 'password', 'username' => table_column_helper('用户名', ['style' => ['min-width' => '100px']]), 'an_mobile' => table_column_helper('电话', ['style' => ['min-width' => '100px']], function($item){ return '+' . $item['an'] . ' ' . $item['mobile']; }), 'email' => table_column_helper('邮箱', ['style' => ['min-width' => '200px']]), ]) ->setQuery(function () { $query = AdminUser::find()->select(['id', 'username', 'password', 'email', 'an', 'mobile']); return $query; }) ->render($this); ~~~ 示例图示: ![](https://img.kancloud.cn/3c/fd/3cfd20fce8d3551e463ee08029c2d9ec_1060x845.png)