|
| 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 | + |
| 8 | + |
| 9 | +`ViewPicker` single selection mode: |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | +`ViewPicker` multi selection mode: |
| 14 | + |
| 15 | + |
| 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 | |
0 commit comments