|
| 1 | +# ComboBoxListItemPicker control |
| 2 | + |
| 3 | +This control allows you to select one or more items from a list. The List can be filtered to allow select items from a subset of items 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 | + |
| 14 | + |
| 15 | +## How to use this control in your solutions |
| 16 | + |
| 17 | +- 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. |
| 18 | +- Import the control into your component: |
| 19 | + |
| 20 | +```TypeScript |
| 21 | +import { ComboBoxListItemPicker } from '@pnp/spfx-controls-react/lib/ComboBoxListItemPicker'; |
| 22 | +``` |
| 23 | +- Use the `ComboBoxListItemPicker` control in your code as follows: |
| 24 | + |
| 25 | +```TypeScript |
| 26 | +<ComboBoxListItemPicker listId='da8daf15-d84f-4ab1-9800-7568f82fed3f' |
| 27 | + columnInternalName='Title' |
| 28 | + keyColumnInternalName='Id' |
| 29 | + filter="Title eq 'SPFx'" |
| 30 | + itemLimit={10} |
| 31 | + onSelectedItem={this.onSelectedItem} |
| 32 | + webUrl: this.context.pageContext.web.absoluteUrl, |
| 33 | + spHttpClient: new SPHttpClient() /> |
| 34 | +``` |
| 35 | + |
| 36 | +- Use the `ComboBoxListItemPicker` with objects passed in defaultSelectedItems |
| 37 | +```TypeScript |
| 38 | +<ComboBoxListItemPicker listId='da8daf15-d84f-4ab1-9800-7568f82fed3f' |
| 39 | + columnInternalName='Title' |
| 40 | + keyColumnInternalName='Id' |
| 41 | + filter="Title eq 'SPFx'" |
| 42 | + itemLimit={10} |
| 43 | + defaultSelectedItems: [{Id: 2, Title:"Test"}] |
| 44 | + onSelectedItem={this.onSelectedItem} |
| 45 | + webUrl: this.context.pageContext.web.absoluteUrl, |
| 46 | + spHttpClient: new SPHttpClient() /> |
| 47 | +``` |
| 48 | +- Or only ids |
| 49 | +```TypeScript |
| 50 | +<ComboBoxListItemPicker listId='da8daf15-d84f-4ab1-9800-7568f82fed3f' |
| 51 | + columnInternalName='Title' |
| 52 | + keyColumnInternalName='Id' |
| 53 | + filter="Title eq 'SPFx'" |
| 54 | + itemLimit={10} |
| 55 | + defaultSelectedItems: [2] |
| 56 | + onSelectedItem={this.onSelectedItem} |
| 57 | + webUrl: this.context.pageContext.web.absoluteUrl, |
| 58 | + spHttpClient: new SPHttpClient() /> |
| 59 | +``` |
| 60 | + |
| 61 | +- The `onSelectedItem` change event returns the list items selected and can be implemented as follows: |
| 62 | + |
| 63 | +```TypeScript |
| 64 | +private onSelectedItem(data: { key: string; name: string }[]) { |
| 65 | + for (const item of data) { |
| 66 | + console.log(`Item value: ${item.key}`); |
| 67 | + console.log(`Item text: ${item.name}`); |
| 68 | + } |
| 69 | +} |
| 70 | +``` |
| 71 | +## Implementation |
| 72 | + |
| 73 | +The `ComboBoxListItemPicker` control can be configured with the following properties: |
| 74 | + |
| 75 | + |
| 76 | +| Property | Type | Required | Description | |
| 77 | +| ---- | ---- | ---- | ---- | |
| 78 | +| columnInternalName | string | yes | InternalName of column to search and get values. | |
| 79 | +| keyColumnInternalName | string | no | InternalName of column to use as the key for the selection. Must be a column with unique values. Default: Id | |
| 80 | +| webUrl | string | yes | Url to web hosting list | |
| 81 | +| spHttpClient | RequestClient | yes | Any implementation of PnPJS RequestClient | |
| 82 | +| listId | string | yes | Guid of the list. | |
| 83 | +| itemLimit | number | yes | Number of items which can be selected | |
| 84 | +| onSelectItem | (items: any[]) => void | yes | Callback function which returns the selected items. | |
| 85 | +| className | string | no | ClassName for the picker. | |
| 86 | +| webUrl | string | no | URL of the site. By default it uses the current site URL. | |
| 87 | +| defaultSelectedItems | any[] | no | Initial items that have already been selected and should appear in the people picker. Support objects and Ids only | |
| 88 | +| suggestionsHeaderText | string | no | The text that should appear at the top of the suggestion box. | |
| 89 | +| noResultsFoundText | string | no | The text that should appear when no results are returned. | |
| 90 | +| disabled | boolean | no | Specifies if the control is disabled or not. | |
| 91 | +| filter | string | no | Condition to filter list Item, same as $filter ODATA parameter| |
| 92 | +| multiSelect | boolean | no | Allows multiple selection| |
| 93 | +| onInitialized | () => void | no | Calls when component is ready| |
| 94 | + |
| 95 | + |
0 commit comments