Skip to content

Commit 8e0472c

Browse files
Merge branch 'NishkalankBezawada-issue-1439-viewpicker' into dev
2 parents 02af8a3 + 1dd585e commit 8e0472c

File tree

15 files changed

+483
-6
lines changed

15 files changed

+483
-6
lines changed
30.2 KB
Loading
14.8 KB
Loading
31.5 KB
Loading
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# ViewPicker control
2+
3+
This control allows you to select available views from lists/libraries of the current site.
4+
5+
Here is an example of the control:
6+
7+
![ViewPicker initial](../assets/ViewPicker1.PNG)
8+
9+
`ViewPicker` single selection mode:
10+
11+
![ViewPicker single selection](../assets/ViewPicker2.png)
12+
13+
`ViewPicker` multi selection mode:
14+
15+
![ViewPicker multi selection](../assets/ViewPicker-multi.png)
16+
17+
18+
## How to use this control in your solutions
19+
20+
- Check that you installed the `@pnp/spfx-controls-react` dependency. Check out the [getting started](../../#getting-started) page for more information about installing the dependency.
21+
- Import the control into your component:
22+
23+
24+
```TypeScript
25+
import { ViewPicker } from "@pnp/spfx-controls-react/lib/ViewPicker";
26+
```
27+
28+
- Use the `ViewPicker` control in your code as follows:
29+
30+
```TypeScript
31+
<ViewPicker context={this.props.context}
32+
listId={"9f3908cd-1e88-4ab3-ac42-08efbbd64ec9"}
33+
placeholder={'Select list view(s)'}
34+
orderBy={orderBy.Title}
35+
multiSelect={true}
36+
onSelectionChanged={this.onViewPickerChange} />
37+
```
38+
39+
- The `onSelectionChanged` change event returns the selected view(s) and can be implemented as follows in your webpart:
40+
41+
```TypeScript
42+
private onViewPickerChange = (views: string | string[]) => {
43+
console.log("Views:", views);
44+
}
45+
```
46+
47+
48+
## Implementation
49+
50+
The `ViewPicker` control can be configured with the following properties
51+
52+
| Property | Type | Required | Description |
53+
| ---- | ---- | ---- | ---- |
54+
| context | BaseComponentContext | yes | The context object of the SPFx loaded webpart or customizer. |
55+
| className | string | no | If provided, additional class name to provide on the dropdown element. |
56+
| disabled | boolean | no | Whether or not the view picker control is disabled. |
57+
| filter | string | no | Filter views from Odata query. |
58+
| label | string | no | Label to use for the control. |
59+
| listId | string | no | The List Id of the list. |
60+
| placeholder | string | no | Placeholder label to show in the dropdown. |
61+
| orderBy | Enum | no | How to order the set of views (By ID or Title). |
62+
| selectedView | string OR string[] | no | Keys(View Ids) of the selected item(s). If you provide this, you must maintain selection state by observing onSelectionChanged events and passing a new value in when changed. |
63+
| multiSelect | boolean | no | Optional mode indicates if multi-choice selections is allowed. Default to `false`. |
64+
| showBlankOption | boolean | no | Whether or not to show a blank option. Default to `false`. |
65+
| viewsToExclude | string[] | no | Defines view titles which should be excluded from the view picker control. |
66+
| webAbsoulteUrl | string | no | Absolute Web Url of target site (user requires permissions) |
67+
| onSelectionChanged | (newValue: string OR string[]): void | no | Callback function when the selected option changes. |
68+
69+
Enum `orderBy`
70+
71+
| Value |
72+
| ---- |
73+
| Id |
74+
| Title |

src/ViewPicker.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './controls/viewPicker/index';

src/common/SPEntities.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,15 @@ export interface IUploadImageResult {
206206
ServerRelativeUrl: string;
207207
UniqueId: string;
208208
}
209+
210+
export interface ISPView {
211+
Id: string;
212+
Title: string;
213+
}
214+
215+
/**
216+
* Defines a collection of SharePoint list views
217+
*/
218+
export interface ISPViews {
219+
value: ISPView[];
220+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import { BaseComponentContext } from '@microsoft/sp-component-base';
2+
import { ISPView } from '../../../src/common/SPEntities';
3+
import { IDropdownOption } from 'office-ui-fabric-react/lib/Dropdown';
4+
5+
6+
/**
7+
* Enum for specifying how the views should be sorted
8+
*/
9+
export enum orderBy {
10+
Id = 1,
11+
Title
12+
}
13+
14+
export interface IViewPickerProps {
15+
/**
16+
* Context of the current web part
17+
*/
18+
context: BaseComponentContext;
19+
20+
/**
21+
* If provided, additional class name to provide on the dropdown element.
22+
*/
23+
className?: string;
24+
25+
/**
26+
* Whether the view control is enabled or not.
27+
*/
28+
disabled?: boolean;
29+
30+
/**
31+
* Filter views from Odata query
32+
*/
33+
filter?: string;
34+
35+
/**
36+
* Specifies the text describing the ViewPicker
37+
*/
38+
label?: string;
39+
40+
/**
41+
* The List Id of the list
42+
*/
43+
listId?: string;
44+
45+
/**
46+
* Input placeholder text. Displayed until option is selected.
47+
*/
48+
placeholder?: string;
49+
50+
/**
51+
* How to order the set of views (By ID or Title).
52+
*/
53+
orderBy?: orderBy;
54+
55+
/**
56+
* Initial selected view(s) of the control
57+
*/
58+
selectedView?: string | string[];
59+
60+
/**
61+
* Indicates if multi-choice selections is allowed. Default to false.
62+
*/
63+
multiSelect?: boolean;
64+
65+
/**
66+
* Whether or not to show a blank option. Default false.
67+
*/
68+
showBlankOption?: boolean;
69+
70+
/**
71+
* Defines view titles which should be excluded from the view picker control
72+
*/
73+
viewsToExclude?: string[];
74+
75+
/**
76+
* Absolute Web Url of target site (user requires permissions)
77+
*/
78+
webAbsoluteUrl?: string;
79+
80+
81+
/**
82+
* Callback issued when the selected option changes.
83+
*/
84+
onSelectionChanged?: (newValue: string | string[]) => void;
85+
}
86+
87+
export interface IViewPickerState {
88+
/**
89+
* The results fetched to the viewPicker
90+
*/
91+
results: IDropdownOption[];
92+
/**
93+
* Keys of the currently selected item(s).
94+
*/
95+
selectedView?: string | string[];
96+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.viewPicker {
2+
.spinner {
3+
float: right;
4+
margin-top: 10px;
5+
margin-right: -20px;
6+
}
7+
}

0 commit comments

Comments
 (0)