@visactor/vtable
Version:
canvas table width high performance
51 lines (46 loc) • 3.45 kB
JavaScript
import { TABLE_EVENT_TYPE } from "../../core/TABLE_EVENT_TYPE";
import { defaultOrderFn } from "../../tools/util";
export function dealSort(col, row, table, event) {
var _a;
let tableState, range1 = null, isTargetCell = !1;
if (Array.isArray(table.sortState)) for (let i = 0; i < table.sortState.length && (tableState = table.sortState[i],
tableState && (range1 = table._getHeaderCellBySortState(tableState)), range1 && (isTargetCell = isTarget(col, row, range1.col, range1.row, table)),
!isTargetCell); i++) ; else tableState = table.sortState, tableState && (range1 = table._getHeaderCellBySortState(tableState)),
range1 && (isTargetCell = isTarget(col, row, range1.col, range1.row, table));
const headerC = table.getHeaderDefine(col, row);
tableState && isTargetCell && (null == headerC ? void 0 : headerC.sort) ? tableState.order = "asc" === tableState.order ? "desc" : "desc" === tableState.order ? "normal" : "asc" : (null == headerC ? void 0 : headerC.sort) ? tableState = {
field: table.getHeaderField(col, row),
order: "asc"
} : isTargetCell && (null == headerC ? void 0 : headerC.showSort) || (tableState = {
field: table.getHeaderField(col, row),
order: "normal"
}), tableState.event = event;
if (table.fireListeners(TABLE_EVENT_TYPE.SORT_CLICK, tableState).includes(!1)) return;
let isArraySortState = !1, sortState = table.internalProps.sortState ? Array.isArray(table.internalProps.sortState) && (isArraySortState = !0) ? table.internalProps.sortState : [ table.internalProps.sortState ] : [];
if (Array.isArray(sortState)) {
const index = sortState.findIndex((item => item.field === tableState.field));
index >= 0 ? sortState[index] = tableState : sortState.push(tableState);
}
sortState = sortState.filter((item => "normal" !== item.order)), sortState = table.internalProps.multipleSort && (isArraySortState = !0) ? sortState : sortState.splice(-1),
sortState = isArraySortState && sortState.length ? sortState : sortState[0], table.internalProps.sortState = sortState,
table.stateManager.setSortState(sortState), (null == headerC ? void 0 : headerC.sort) && executeSort(sortState, table, headerC),
table.internalProps.useOneRowHeightFillAll = !1, table.internalProps.layoutMap.clearCellRangeMap(),
table.scenegraph.sortCell();
const isHasSelected = !!(null === (_a = table.stateManager.select.ranges) || void 0 === _a ? void 0 : _a.length);
table.stateManager.updateSelectPos(-1, -1), table.stateManager.endSelectCells(!0, isHasSelected);
}
function executeSort(newState, table, headerDefine) {
newState = Array.isArray(newState) || !newState ? newState : [ newState ], table.dataSource.sort((newState || []).map((item => {
var _a, _b;
const hd = table.internalProps.layoutMap.headerObjects.find((col => col && col.field === item.field));
return {
field: item.field,
order: item.order || "asc",
orderFn: "function" == typeof (null === (_a = null == hd ? void 0 : hd.define) || void 0 === _a ? void 0 : _a.sort) ? null === (_b = null == hd ? void 0 : hd.define) || void 0 === _b ? void 0 : _b.sort : defaultOrderFn
};
})));
}
function isTarget(col, row, range1Col, range1Row, table) {
return table._getLayoutCellId(col, row) === table._getLayoutCellId(range1Col, range1Row);
}
//# sourceMappingURL=index.js.map