1
1
import * as React from 'react' ;
2
2
import { DetailsList , DetailsListLayoutMode , Selection , SelectionMode , IGroup } from 'office-ui-fabric-react/lib/DetailsList' ;
3
- import { IListViewProps , IListViewState , IViewField } from './IListView' ;
3
+ import { IListViewProps , IListViewState , IViewField , IGrouping , GroupOrder } from './IListView' ;
4
4
import { IColumn } from 'office-ui-fabric-react/lib/components/DetailsList' ;
5
5
import { findIndex , has , sortBy , isEqual , cloneDeep } from '@microsoft/sp-lodash-subset' ;
6
6
import { FileTypeIcon , IconType } from '../fileTypeIcon/index' ;
7
7
import * as strings from 'ControlStrings' ;
8
+ import { IGroupsItems } from '../../../lib/ListView' ;
8
9
9
10
/**
10
11
* File type icon component
@@ -55,7 +56,7 @@ export class ListView extends React.Component<IListViewProps, IListViewState> {
55
56
* @param items
56
57
* @param groupByFields
57
58
*/
58
- private _getGroups ( items : any [ ] , groupByFields : string [ ] , level : number = 0 , startIndex : number = 0 ) : { items : any [ ] , groups : IGroup [ ] } {
59
+ private _getGroups ( items : any [ ] , groupByFields : IGrouping [ ] , level : number = 0 , startIndex : number = 0 ) : IGroupsItems {
59
60
// Group array which stores the configured grouping
60
61
let groups : IGroup [ ] = [ ] ;
61
62
let updatedItemsOrder : any [ ] = [ ] ;
@@ -67,7 +68,7 @@ export class ListView extends React.Component<IListViewProps, IListViewState> {
67
68
// Create grouped items object
68
69
const groupedItems = { } ;
69
70
items . forEach ( ( item : any ) => {
70
- let groupName = item [ groupField ] ;
71
+ let groupName = item [ groupField . name ] ;
71
72
// Check if the group name exists
72
73
if ( typeof groupName === "undefined" ) {
73
74
// Set the default empty label for the field
@@ -86,8 +87,16 @@ export class ListView extends React.Component<IListViewProps, IListViewState> {
86
87
groupedItems [ groupName ] . push ( item ) ;
87
88
} ) ;
88
89
90
+ // Sort the grouped items object by its key
91
+ const sortedGroups = { } ;
92
+ let groupNames = Object . keys ( groupedItems ) ;
93
+ groupNames = groupField . order === GroupOrder . ascending ? groupNames . sort ( ) : groupNames . sort ( ) . reverse ( ) ;
94
+ groupNames . forEach ( ( key : string ) => {
95
+ sortedGroups [ key ] = groupedItems [ key ] ;
96
+ } ) ;
97
+
89
98
// Loop over all the groups
90
- for ( const groupItems in groupedItems ) {
99
+ for ( const groupItems in sortedGroups ) {
91
100
// Retrieve the total number of items per group
92
101
const totalItems = groupedItems [ groupItems ] . length ;
93
102
// Create the new group
0 commit comments