ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
## 拖拽排序 提供列表的排序操作,将触发后端的`sort`事件。 > 图片示例: ![](https://img.kancloud.cn/2f/2f/2f2fde6dbd33306347f40945a4d8e15e_1920x902.png) > 配置项 | key | 类型 | 是否必须 | 说明 | | --- | --- | --- | --- | | templet | string | 是 | 固定值:`dragSort` | | 通用配置... | | iconClass | string | 否 | 图标的class,默认值:`yunj-icon yunj-icon-sort-circle` | > 代码示例: ```php $builder=YT('general_example')->state([...]) ->cols(function($state){ $cols=[ 'id'=>['title'=>'ID','align'=>'center'], // 拖拽排序 'title'=>['title'=>'标题,可拖拽排序','templet'=>'dragSort'], 'dragSortAction'=>['title'=>'排序','align'=>'center','templet'=>'dragSort'], ]; return $cols; }) ->event(function ($event,$ids){ if ($event == TableEvent::SORT) { $caseSql = ""; $idsSql = ""; for ($i = 0, $l = count($ids); $i < $l; $i++) { $id = $ids[$i]; $caseSql .= sprintf(" WHEN %d THEN %d ", $id, $i); $idsSql .= ",{$id}"; } $idsSql = substr($idsSql, 1); $sql = sprintf("UPDATE %s SET sort = CASE id %s END WHERE state <> %d and id in(%s)", $this->getModel()->getTable(), $caseSql, State::DELETED, $idsSql); Db::execute($sql); return success_json(); } return error_json(); }) ```