You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20 lines
799 B
TypeScript

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import type { ColumnsState } from '../container'
export const columnSort = (columnsMap: Record<string, ColumnsState>) => (a: any, b: any) => {
const { fixed: aFixed, index: aIndex } = a
const { fixed: bFixed, index: bIndex } = b
if ((aFixed === 'left' && bFixed !== 'left') || (bFixed === 'right' && aFixed !== 'right')) {
return -2
}
if ((bFixed === 'left' && aFixed !== 'left') || (aFixed === 'right' && bFixed !== 'right')) {
return 2
}
// 如果没有index在 dataIndex 或者 key 不存在的时候他会报错
const aKey = a.key || `${aIndex}`
const bKey = b.key || `${bIndex}`
if (columnsMap[aKey]?.order || columnsMap[bKey]?.order) {
return (columnsMap[aKey]?.order || 0) - (columnsMap[bKey]?.order || 0)
}
return (a.index || 0) - (b.index || 0)
}