|
| 1 | +# ListItemPicker control |
| 2 | + |
| 3 | +This control allows you to select one or more list item from a site |
| 4 | + |
| 5 | +Here is an example of the control: |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | +`ListPicker` single selection mode: |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | +`ListPicker` multi-selection mode |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | +## How to use this control in your solutions |
| 18 | + |
| 19 | +- 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. |
| 20 | +- Import the control into your component: |
| 21 | + |
| 22 | +```TypeScript |
| 23 | +import { ListPicker } from "@pnp/spfx-controls-react/lib/ListPicker"; |
| 24 | +``` |
| 25 | + |
| 26 | +- Use the `ListPicker` control in your code as follows: |
| 27 | + |
| 28 | +```TypeScript |
| 29 | +<ListPicker context={this.props.context} |
| 30 | + label="Select your list(s)" |
| 31 | + placeHolder="Select your list(s)" |
| 32 | + baseTemplate={100} |
| 33 | + includeHidden={false} |
| 34 | + multiSelect={false} |
| 35 | + onSelectionChanged={this.onListPickerChange} /> |
| 36 | +``` |
| 37 | + |
| 38 | +- The `onSelectionChanged` change event returns the list(s) and can be implemented as follows: |
| 39 | + |
| 40 | +```TypeScript |
| 41 | +private onListPickerChange (lists: string | string[]) { |
| 42 | + console.log("Lists:", lists); |
| 43 | +} |
| 44 | +``` |
| 45 | + |
| 46 | +## Implementation |
| 47 | + |
| 48 | +The `ListPicker` control can be configured with the following properties: |
| 49 | + |
| 50 | +| Property | Type | Required | Description | |
| 51 | +| ---- | ---- | ---- | ---- | |
| 52 | +| context | WebPartContext OR ApplicationCustomizerContext | yes | The context object of the SPFx loaded webpart or customizer. | |
| 53 | +| className | string | no | If provided, additional class name to provide on the dropdown element. | |
| 54 | +| disabled | boolean | no | Whether or not the control is disabled. | |
| 55 | +| baseTemplate | number | no | The SharePoint BaseTemplate ID to filter the list options by. | |
| 56 | +| includeHidden | boolean | no | Whether or not to include hidden lists. Default is `true`. | |
| 57 | +| orderBy | LibsOrderBy | no | How to order the lists retrieved from SharePoint. | |
| 58 | +| selectedList | string OR string[] | no | Keys 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. | |
| 59 | +| multiSelect | boolean | no | Optional mode indicates if multi-choice selections is allowed. Default to `false`. | |
| 60 | +| label | string | no | Label to use for the control. | |
| 61 | +| placeholder | string | no | Placeholder label to show in the dropdown. | |
| 62 | +| onSelectionChanged | (newValue: string OR string[]): void | no | Callback function when the selected option changes. | |
| 63 | + |
| 64 | +Enum `LibsOrderBy` |
| 65 | + |
| 66 | +| Value | |
| 67 | +| ---- | |
| 68 | +| Id | |
| 69 | +| Title | |
| 70 | + |
| 71 | + |
0 commit comments