ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
## 数量获取(必须) > 图片演示: ![](https://img.kancloud.cn/da/41/da415faca05ea4d1a962ba2928731925_1594x469.png) ![](https://img.kancloud.cn/a9/fe/a9fe043fd48e8c41bed5a4d69a477d37_1615x316.png) > 说明: 返回表格状态数量,及对应状态和筛选条件下的数据总条数。 方法:`count($callable)` * 参数 **callable** (必须),为 callable 闭包。 ```php count(function($filter){...}); ``` * 参数 * **filter** array 类型 筛选条件集合,固定元素包含如下元素: // 当前表格状态栏key $state=$filter['state']; // 当前选中数据行id集合数组 $ids=$filter['ids']; * 返回值 int 类型 > 示例: | 状态 | 筛选表单 | 表头| | --- | --- | --- | | 正常(11) | `姓名` | `姓名`、`添加时间`| | 回收站(22) | `姓名` | `姓名`、`添加时间`| 构建上述表单。方法如下: ```php $builder=YT('general_example')->state([ 11=>'正常', 22=>'回收站' ]) ->filter(function($state){ $filter = [ 'name'=>['title'=>'姓名'] ]; return $filter; }) ->cols(function($state){ $cols = [ 'id'=>['type'=>'checkbox'], 'name'=>['title'=>'姓名'], 'create_time'=>['title'=>'添加时间', 'align'=>'center', 'hide'=>'mobile_hide_hide','templet'=>'datetime'], ]; return $cols; }) ->count(function($filter){ // 固定参数 $state=$filter['state']; $ids=$filter['ids']; // 筛选表单参数 $name=$filter['name']; $whereArr=[]; $whereArr[]=$state?['state','eq',$state]:['state','neq',DbRowState::REMOVED]; if($ids) $whereArr[]=['id','in',$ids]; if($name) $whereArr[]=['name','like','%'.$name_cn.'%']; return Db::name('test')->where($whereArr)->count(); }) ```