Skip to content

Commit

Permalink
closes #225 simple string sort group by
Browse files Browse the repository at this point in the history
  • Loading branch information
sgratzl committed Mar 25, 2020
1 parent d3eec73 commit 99785a5
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/model/StringColumn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Column, {widthChanged, labelChanged, metaDataChanged, dirty, dirtyHeader,
import {defaultGroup, IDataRow, IGroup, ECompareValueType, IValueColumnDesc, othersGroup, ITypeFactory} from './interfaces';
import {missingGroup, isMissingValue} from './missing';
import ValueColumn, {dataLoaded} from './ValueColumn';
import {equal, IEventListener} from '../internal';
import {equal, IEventListener, ISequence, isSeqEmpty} from '../internal';

export enum EAlignment {
left = 'left',
Expand Down Expand Up @@ -61,7 +61,7 @@ export declare function groupingChanged_SC(previous: (RegExp | string)[][], curr
/**
* a string column with optional alignment
*/
@toolbar('search', 'groupBy', 'filterString')
@toolbar('search', 'groupBy', 'sortGroupBy', 'filterString')
@dialogAddons('group', 'groupString')
@Category('string')
export default class StringColumn extends ValueColumn<string> {
Expand Down Expand Up @@ -284,5 +284,23 @@ export default class StringColumn extends ValueColumn<string> {
toCompareValueType() {
return ECompareValueType.STRING;
}

toCompareGroupValue(rows: ISequence<IDataRow>, _group: IGroup, valueCache?: ISequence<any>) {
if (isSeqEmpty(rows)) {
return null;
}
// take the smallest one
if (valueCache) {
return valueCache.reduce((acc, v) => acc == null || v < acc ? v : acc, null as null|string);
}
return rows.reduce((acc, d) => {
const v = this.getValue(d);
return acc == null || (v != null && v < acc) ? v : acc;
}, null as null | string);
}

toCompareGroupValueType() {
return ECompareValueType.STRING;
}
}

0 comments on commit 99785a5

Please sign in to comment.