当前位置:网站首页>CatchAdmin实战教程(四)Table组件相关功能实现
CatchAdmin实战教程(四)Table组件相关功能实现
2022-07-29 02:09:00 【Jack_num1】
1. 排序功能
1.1 纯页面排序
官方站点仅提供了纯页面当前页数的排序功能:#sortable
1.1.1 示例
public function table()
{
// TODO: Implement table() method.
return $this->getTable('bonds')
->header([
// 1. 开启字段排序的功能
HeaderItem::label('编号')->prop('id')->sortable()->width(80),
HeaderItem::label('更新时间')->prop('updated_at')->sortable()->width(150),
HeaderItem::label('操作')->actions([
Actions::delete()
])
])
->withBind()
->withApiRoute('cms/articles')
->withActions([
Actions::create()->to('/cms/articles/detail/')
])
->render();
}
1.2 自定义排序
自定义排序的功能: 主要是通过在API地址上添加table页面中的字段的升降值请求获取相应的响应数据
1.2.1 添加Method
catch-admin-vue项目
src/components/Catch/Table/mixin/operete.js中添加orderChange方法
1.2.1.1 示例
// 字段排序
orderChange(column) {
// 1. 设置搜索排序字段
const order_filed = column.prop + '_order'
// 2. 判断排序类型
if (column.order === 'ascending') {
// 3. 设置搜索排序字段值
this.queryParams[order_filed] = 'asc'
} else if (column.order === 'descending') {
this.queryParams[order_filed] = 'desc'
} else {
this.queryParams[order_filed] = ''
}
// 4. 重新请求接口
this.getList()
}
1.2.2 添加事件
1.2.2.1 方式一
在CatchAdmin项目
extend/catcher/library/table/Events.php中添加事件orderChange
/** * @note: 排序 * @return mixed * @time: 2022-07-25 14:57 */
public function orderChange()
{
$this->appendEvents([
'sort-change' => 'orderChange'
]);
return $this;
}
1.2.3 使用事件
public function table()
{
// TODO: Implement table() method.
return $this->getTable('bonds')
->header([
// 1. 开启字段排序的功能
HeaderItem::label('编号')->prop('id')->sortable()->width(80),
HeaderItem::label('更新时间')->prop('updated_at')->sortable()->width(150),
HeaderItem::label('操作')->actions([
Actions::delete()
])
])
->withBind()
// 2. 新增排序改变的事件(自定义排序)
// 2.1 方式1
->orderChange()
// 2.2 方式2
->withEvents([
'sort-change' => 'orderChange'
])
->withApiRoute('cms/articles')
->withActions([
Actions::create()->to('/cms/articles/detail/')
])
->render();
}
1.2.3 示例
请求URL示例:
/cms/articles?id_order=desc
这里我们后台可以通过获取请求字段值的_order后缀,判断是否存在排序的字段进行相应的排序处理。
边栏推荐
- HTTP cache
- Master-slave replication and its principle
- 快速掌握Nodejs安装以及入门
- Redis master-slave mode, sentinel cluster, fragment cluster
- How to quickly design a set of cross end components that support rendering rich text content
- Production scheme and advantages of online 3D digital exhibition hall
- What should I do if excel opens a CSV file containing Chinese characters and there is garbled code?
- NVIDIA-VPI(Vision Programming Interface)
- 手把手教你安装VSCode(附带图解步骤)
- Experiment 2: Arduino's tricolor lamp experiment
猜你喜欢

ROCBOSS开源微社区轻论坛类源码

How much is the report development cost in the application system?

Remember error scheduler once Asynceventqueue: dropping event from queue shared causes OOM

以科技传递温度,vivo亮相数字中国建设峰会

详解异步任务:任务的状态及生命周期管理

h. 264 code stream explanation

代码实现 —— 多项式的最大公因式(线性代数)

快速掌握Nodejs安装以及入门

Understand the evolution of redis architecture in one article

MQTT例程
随机推荐
如何把thinkphp5的项目迁移到阿里云函数计算来应对流量洪峰?
[upload picture 2-cropable]
Read the recent trends of okaleido tiger and tap the value and potential behind it
一文读懂Okaleido Tiger近期动态,挖掘背后价值与潜力
Talk about 11 tips for interface performance optimization
Mqtt routine
7/28 高斯消元解线性方程组+高斯消元解异或线性方程组 +求组合数ii
HTTP断点续传以及缓存问题
Production scheme and advantages of online 3D digital exhibition hall
Three expiration strategies
TCP重传机制有哪些?
ES6事件绑定(v-on用法)
Chapter 3 business function development (deletion and modification of clue remarks)
聊聊 Feign 的实现原理
以科技传递温度,vivo亮相数字中国建设峰会
Interprocess communication - detailed explanation of the pipeline (explanation of graphic cases)
MySQL basic operation and comprehensive instance project based on MySQL basic operation
After 4 years of testing experience, I finally entered Alibaba. Two months later, I chose to resign naked
When I look at the source code, what am I thinking?
我被这个浏览了 746000 次的问题惊住了