jiangxy/react-antd-admin

请问dataSchema中的sort和filter功能有吗

whyuan1976 opened this issue · 3 comments

sample里没有相关例子,看代码有sorter的设定,不知道怎么用?能否提示一下。

关于sorter,参考这个例子,其实就是antd中Table组件的sorter

filter暂时还不支持

楼主的实现是静态数据的方式展现的,但实际上真实开发中遇到的都是使用需要远程访问。

我的实现如下:
DBTable新增
state = {
sortedInfo: { order:null, columnKey:null},
}

handleTableChange = async(pagination, filters, sorter) => {
this.state.sortedInfo= sorter;
const res = await this.select(this.state.queryObj, this.state.currentPage, this.state.pageSize);
if (res.success) {
this.setState({
data: res.data,
tableLoading: false,
});
} else {
this.error(res.message);
}
}

修改select函数
async select(queryObj, page, pageSize) {
// 为啥这个方法不用箭头函数, 但也不会有this的问题呢? 我猜测是因为这个方法都是被其他箭头函数调用的, 所以也会自动bind this
// 同理上面的error函数似乎也不需要是箭头函数
const tmpObj = Object.assign({}, queryObj); // 创建一个新的临时对象, 其实直接修改queryObj也可以
tmpObj.page = page;
tmpObj.pageSize = pageSize;
tmpObj.sortField = this.state.sortedInfo.columnKey;
tmpObj.sortOrder = this.state.sortedInfo.order;

再把sortedInfo通过props往子组件传递。

data schema的sorter只需要设置为true。render时,需要设置column中的sortOrder。

是的 由服务端控制排序是更常见的
这样将排序条件作为DBTable的state挺好的,用户操作上会更友好

我们为了图省事,一般会在InnerForm中新增两个输入项,表示排序条件,然后让用户去手动选择。。。