Skip to content

Commit

Permalink
fix: sort change ui
Browse files Browse the repository at this point in the history
  • Loading branch information
greper committed May 30, 2021
1 parent 8915732 commit cdd754e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 19 deletions.
1 change: 1 addition & 0 deletions packages/fast-crud/src/ui/ui-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export interface TableCI extends CI {
data;
fixedHeaderNeedComputeBodyHeight;
vLoading;
onSortChange;
}

export interface CheckboxGroupCI extends CI {
Expand Down
24 changes: 7 additions & 17 deletions packages/fast-crud/src/use/use-crud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,25 +185,15 @@ export function useCrud(ctx: UseCrudProps) {
}

function useTable() {
const events = ui.table.onSortChange({
emit({ isServerSort, prop, asc, order }) {
crudBinding.value.sort = isServerSort ? { prop, order, asc } : null;
expose.doRefresh();
}
});
return {
table: {
//监听el-table的服务端排序
onSortChange({ column, prop, order }) {
console.log("sort change", column, prop, order);
crudBinding.value.sort =
prop && column.sortable === "custom" ? { prop, order, asc: order === "ascending" } : null;
expose.doRefresh();
},
// 监听a-table的服务端排序
onChange(pagination, filters, sorter) {
console.log("table change", pagination, filters, sorter);
if (sorter) {
const { column, field, order } = sorter;
crudBinding.value.sort =
order && column.sorter === true ? { prop: field, order, asc: order === "ascend" } : null;
expose.doRefresh();
}
}
...events
}
};
}
Expand Down
19 changes: 18 additions & 1 deletion packages/ui/ui-antdv/src/antdv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,24 @@ export class Antdv implements UiInterface {
name: "a-table",
data: "dataSource",
fixedHeaderNeedComputeBodyHeight: true,
vLoading: false
vLoading: false,
onSortChange({ emit }) {
return {
// 监听a-table的服务端排序
onChange(pagination, filters, sorter) {
console.log("table change", pagination, filters, sorter);
if (sorter) {
const { column, field, order } = sorter;
emit({
isServerSort: order && column.sorter === true,
prop: field,
order,
asc: order === "ascend"
});
}
}
};
}
};

tableColumn: TableColumnCI = {
Expand Down
15 changes: 14 additions & 1 deletion packages/ui/ui-element/src/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,20 @@ export class Element implements UiInterface {
name: "el-table",
data: "data",
fixedHeaderNeedComputeBodyHeight: false,
vLoading: "loading"
vLoading: "loading",
onSortChange({ emit }) {
return {
onSortChange({ column, prop, order }) {
console.log("sort change", column, prop, order);
emit({
isServerSort: prop && column.sortable === "custom",
prop,
order,
asc: order === "ascending"
});
}
};
}
};

textArea: TextAreaCI = {
Expand Down

0 comments on commit cdd754e

Please sign in to comment.