Skip to content

Commit 028062f

Browse files
committed
Merge branch 'select-default-items' of https://github.com/joelfmrodrigues/sp-dev-fx-controls-react into joelfmrodrigues-select-default-items
2 parents 4c85de1 + aedf228 commit 028062f

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

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 if items to be select by default.
45+
*/
46+
defaultSelection?: number[];
4347
}
4448

4549
export interface IListViewState {

src/controls/listView/ListView.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,27 @@ 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 && this.props.items.length > 0 && this.props.defaultSelection && this.props.defaultSelection.length > 0) {
62+
for (const index of this.props.defaultSelection) {
63+
if (index > -1) {
64+
this._selection.setIndexSelected(index, true, false);
65+
}
66+
}
67+
}
68+
}
69+
5470
/**
5571
* Specify result grouping for the list rendering
5672
* @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)