Skip to content

Commit 74f27fb

Browse files
committed
#880 - ability to provide custom sorting function to the ListView
1 parent 751aff9 commit 74f27fb

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

docs/documentation/docs/controls/ListView.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ The ListView control can be configured with the following properties:
9797
| dragDropFiles | boolean | no | Specify the drag and drop files area option. Default false. |
9898
| onDrop | file | no | Event handler returns files from drag and drop. |
9999
| stickyHeader | boolean | no | Specifies if the header of the `ListView`, including search box, is sticky |
100+
| sortItems | (items: any[], columnName: string, descending: boolean) => any[] | no | Custom sorting function to handle sorting by column |
100101

101102
The `IViewField` has the following implementation:
102103

src/controls/listView/IListView.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ export interface IListViewProps {
6868
* Set to false by default
6969
*/
7070
stickyHeader?: boolean;
71+
/**
72+
* Custom sorting function.
73+
* @returns sorted collection of items
74+
*/
75+
sortItems?: (items: any[], columnName: string, descending: boolean) => any[];
7176
}
7277

7378
export interface IListViewState {

src/controls/listView/ListView.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,9 @@ export class ListView extends React.Component<IListViewProps, IListViewState> {
459459
* @param descending
460460
*/
461461
private _sortItems(items: any[], columnName: string, descending = false): any[] {
462+
if (this.props.sortItems) {
463+
return this.props.sortItems(items, columnName, descending);
464+
}
462465
// Sort the items
463466
const ascItems = sortBy(items, [columnName]);
464467
const sortedItems = descending ? ascItems.reverse() : ascItems;

0 commit comments

Comments
 (0)