🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
# 当前平台已停止维护,请尽快迁移至[云静Admin TP6](https://gitee.com/worklz/yunj-admin-tp6) [https://gitee.com/worklz/yunj-admin-tp6](https://gitee.com/worklz/yunj-admin-tp6) ***** ## 构建表格构建器对象 通过公共方法`YT('general_example')`返回一个id为`general_example`的表格构建器对象。 * 方式一:链式操作 ```php $builder=YT('general_example') ->state([...]) ->filter(function($state){...}) ->toolbar(function($state){...}) ->defaultToolbar(function($state){...}) ->import(function($state){...}) ->cols(function($state){...}) ->count(function($filter){...}) ->items(function ($limit_start,$limit_length,$filter,$sort){...}) ->event(function ($event,$ids){...}); ``` * 方式二:数组配置 ```php $args = [ "state"=>[11=>'正常',22=>'回收站'], "filter"=>function($state){...}, "toolbar"=>function($state){...}, "defaultToolbar"=>function($state){...}, "import"=>function($state){...}, "cols"=>function($state){...}, "count"=>function($filter){...}, "items"=>function($limit_start,$limit_length,$filter,$sort){...}, "event"=>function($event,$ids){...} ]; $builder=YT('general_example',$args); ``` ## 渲染输出 详见:[表格数据渲染输出](https://www.kancloud.cn/worklz/yunj_admin_tp51/2526465) * 方法一:页面内只有单一表格时,可参考如下方法: 注意!此方法仅支持渲染一个表格构建器,不需要写视图文件 ```php // 控制器方法中调用如下方法 $builder = ...; return view_table($builder); ``` * 方法二:自定义页面内容时,可调用如下方法: 注意!此方法支持一个页面渲染多个表格构建器,需要写视图文件 ```php // 控制器方法中调用如下方法 $builder->assign(\yunj\Controller $this); // 视图渲染 return $this->fetch(); ``` ## 视图页面 ```html {extend name="$adminPage"} {block name="content"} <table type="yunj" id="demo"></table> {/block} ```