Skip to content

Commit

Permalink
feat(grid): support sort by link field
Browse files Browse the repository at this point in the history
  • Loading branch information
minlovehua committed Dec 18, 2024
1 parent 0315f20 commit 9848dae
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions packages/state/src/utils/field/model/link.ts
Original file line number Diff line number Diff line change
@@ -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<string>, cellValue: FieldValue) {
Expand All @@ -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 '';
}
}

0 comments on commit 9848dae

Please sign in to comment.