Skip to content

Commit 2f606bc

Browse files
committed
Merge branch 'joelfmrodrigues-select-default-items' into dev
2 parents 4c85de1 + 0d864d3 commit 2f606bc

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

docs/documentation/docs/controls/ListView.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ The Placeholder component can be configured with the following properties:
6767
| selectionMode | SelectionMode | no | Specify if the items in the list view can be selected and how. Options are: none, single, multi. |
6868
| selection | function | no | Selection event that passes the selected item(s) from the list view. |
6969
| groupByFields | IGrouping[] | no | Defines the field on which you want to group the items in the list view. |
70+
| defaultSelection | number[] | no | The index of the items to be select by default |
7071

7172
The `IViewField` has the following implementation:
7273

src/controls/listView/IListView.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Selection, SelectionMode } from 'office-ui-fabric-react/lib/DetailsList';
2-
import { IColumn ,IGroup} from 'office-ui-fabric-react/lib/components/DetailsList';
2+
import { IColumn, IGroup } from 'office-ui-fabric-react/lib/components/DetailsList';
33

44
export { SelectionMode };
55

@@ -40,6 +40,10 @@ export interface IListViewProps {
4040
* Selection event that passes the selected item(s)
4141
*/
4242
selection?: (items: any[]) => void;
43+
/**
44+
* The index of the items to be select by default
45+
*/
46+
defaultSelection?: number[];
4347
}
4448

4549
export interface IListViewState {

src/controls/listView/ListView.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,30 @@ export class ListView extends React.Component<IListViewProps, IListViewState> {
4646
* @param prevState
4747
*/
4848
public componentDidUpdate(prevProps: IListViewProps, prevState: IListViewState): void {
49+
// select default items
50+
this._setSelectedItems();
51+
4952
if (!isEqual(prevProps, this.props)) {
5053
this._processProperties();
5154
}
5255
}
5356

57+
/**
58+
* Select all the items that should be selected by default
59+
*/
60+
private _setSelectedItems(): void {
61+
if (this.props.items &&
62+
this.props.items.length > 0 &&
63+
this.props.defaultSelection &&
64+
this.props.defaultSelection.length > 0) {
65+
for (const index of this.props.defaultSelection) {
66+
if (index > -1) {
67+
this._selection.setIndexSelected(index, true, false);
68+
}
69+
}
70+
}
71+
}
72+
5473
/**
5574
* Specify result grouping for the list rendering
5675
* @param items

tslint.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"rulesDirectory": "./config"
3+
}

0 commit comments

Comments
 (0)