#Custom sorting material table

1 messages · Page 1 of 1 (latest)

karmic compass
#
    sortDataColumns(data, sort) {
        switch (sort.active) {
            case 'Priority': {
                return (this.dataSource.sortData = (data) => {
                    return data.sort((a, b) => {
                        const propertys = this.prioritySortOrder[a.Priority] - this.prioritySortOrder[b.Priority];
                        if (!sort.direction) return;
                        if (sort.direction === 'asc') {
                            return propertys;
                        } else {
                            -propertys;
                        }
                    });
                });
            }
            default:
                return data;
        }
    }```
I have something like this so far
vale charm
karmic compass
#

I thought the use case for this was for nested object properties??

Or would it work with something like this

    ngOnInit(): void {
        this.dataSource.sortingDataAccessor = (item, property) => {
            switch (property) {
                case 'Priority':
                    return this.getComparablePriority(item.Priority);
                default:
                    return item[property];
            }
        };
    }
vale charm
#

You can answer that question by yourself, by testing it.