From 9848dae928470f3a4235622f87b9b22cbab9f40f Mon Sep 17 00:00:00 2001 From: minlovehua <321512939@qq.com> Date: Wed, 18 Dec 2024 10:51:41 +0800 Subject: [PATCH] feat(grid): support sort by link field --- packages/state/src/utils/field/model/link.ts | 22 ++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/packages/state/src/utils/field/model/link.ts b/packages/state/src/utils/field/model/link.ts index f3b1766e..735049d3 100644 --- a/packages/state/src/utils/field/model/link.ts +++ b/packages/state/src/utils/field/model/link.ts @@ -1,7 +1,8 @@ import { isEmpty } from '../../common'; import { AITableFilterCondition, AITableFilterOperation } from '../../../types'; import { Field } from './field'; -import { FieldValue, LinkFieldValue } from '@ai-table/grid'; +import { AITableField, FieldValue, LinkFieldValue } from '@ai-table/grid'; +import { isObject, isString } from 'ngx-tethys/util'; export class LinkField extends Field { override isMeetFilter(condition: AITableFilterCondition, cellValue: FieldValue) { @@ -18,11 +19,24 @@ export class LinkField extends Field { } } - override eq(cv1: LinkFieldValue | null, cv2: LinkFieldValue | null): boolean { + override eq(cv1: LinkFieldValue | string | null, cv2: LinkFieldValue | string | null): boolean { return this.cellValueToString(cv1) === this.cellValueToString(cv2); } - cellValueToString(cellValue: LinkFieldValue | null): string { - return cellValue?.text || ''; + override compare(cellValue1: FieldValue, cellValue2: FieldValue, field: AITableField): number { + const cellTextValue1 = this.cellValueToString(cellValue1); + const cellTextValue2 = this.cellValueToString(cellValue2); + + return super.compare(cellTextValue1, cellTextValue2, field); + } + + cellValueToString(cellValue: LinkFieldValue | string | null): string { + if (isString(cellValue)) { + return cellValue; + } + if (isObject(cellValue)) { + return cellValue.text; + } + return ''; } }