|
| 1 | +# ListItemPicker control |
| 2 | + |
| 3 | +This control allows you to select one or more items from a list. The item selection is based from a column value. The control will suggest items based on the inserted value. |
| 4 | + |
| 5 | +Here is an example of the control: |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | +## How to use this control in your solutions |
| 14 | + |
| 15 | +- 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. |
| 16 | +- Import the control into your component: |
| 17 | + |
| 18 | +```TypeScript |
| 19 | +import { ListItemPicker } from '@pnp/spfx-controls-react/listItemPicker'; |
| 20 | +``` |
| 21 | +- Use the `ListItemPicker` control in your code as follows: |
| 22 | + |
| 23 | +```TypeScript |
| 24 | +<ListItemPicker listId='da8daf15-d84f-4ab1-9800-7568f82fed3f' |
| 25 | + columnInternalName='Title' |
| 26 | + itemLimit={2} |
| 27 | + onSelectedItem={this.onSelectedItem} |
| 28 | + context={this.props.context} /> |
| 29 | +``` |
| 30 | + |
| 31 | +- The `onSelectedItem` change event returns the list items selected and can be implemented as follows: |
| 32 | + |
| 33 | +```TypeScript |
| 34 | +private onSelectedItem(data: { key: string; name: string }[]) { |
| 35 | + for (const item of data) { |
| 36 | + console.log(`Item value: ${item.name}`); |
| 37 | + } |
| 38 | +} |
| 39 | +``` |
| 40 | +## Implementation |
| 41 | + |
| 42 | +The `ListItemPicker` control can be configured with the following properties: |
| 43 | + |
| 44 | + |
| 45 | +| Property | Type | Required | Description | |
| 46 | +| ---- | ---- | ---- | ---- | |
| 47 | +| columnInternalName | string | yes | InternalName of column to search and get values. | |
| 48 | +| context | WebPartContext \| ApplicationCustomizerContext | yes | SPFx web part or extention context | |
| 49 | +| listId | string | yes | Guid of the list. | |
| 50 | +| itemLimit | number | yes | Number of items which can be selected | |
| 51 | +| onSelectItem | (items: any[]) => void | yes | Callback function which returns the selected items. | |
| 52 | +| className | string | no | ClassName for the picker. | |
| 53 | +| webUrl | string | no | URL of the site. By default it uses the current site URL. | |
| 54 | +| defaultSelectedItems | any[] | no | Initial items that have already been selected and should appear in the people picker. | |
| 55 | +| suggestionsHeaderText | string | no | The text that should appear at the top of the suggestion box. | |
| 56 | +| noResultsFoundText | string | no | The text that should appear when no results are returned. | |
| 57 | +| disabled | boolean | no | Specifies if the control is disabled or not. | |
| 58 | + |
| 59 | + |
0 commit comments