Skip to content

Commit 8c126c7

Browse files
committed
Updates to PR #355
1 parent 5a499d8 commit 8c126c7

File tree

6 files changed

+10
-10
lines changed

6 files changed

+10
-10
lines changed

docs/documentation/docs/controls/ListItemPicker.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ The `ListItemPicker` control can be configured with the following properties:
4747
| Property | Type | Required | Description |
4848
| ---- | ---- | ---- | ---- |
4949
| columnInternalName | string | yes | InternalName of column to search and get values. |
50-
| valueColumnInternalName | string | no | InternalName of column to use as the value or key for the selection. Must be a column with unique values. |
50+
| keyColumnInternalName | string | no | InternalName of column to use as the key for the selection. Must be a column with unique values. Default: Id |
5151
| context | WebPartContext \| ApplicationCustomizerContext | yes | SPFx web part or extention context |
5252
| listId | string | yes | Guid of the list. |
5353
| itemLimit | number | yes | Number of items which can be selected |

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/controls/listItemPicker/IListItemPickerProps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ApplicationCustomizerContext } from "@microsoft/sp-application-base";
33

44
export interface IListItemPickerProps {
55
columnInternalName: string;
6-
valueColumnInternalName?: string;
6+
keyColumnInternalName?: string;
77
context: WebPartContext | ApplicationCustomizerContext;
88
listId: string;
99
itemLimit: number;

src/controls/listItemPicker/ListItemPicker.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,16 @@ export class ListItemPicker extends React.Component<IListItemPickerProps, IListI
112112
* Function to load List Items
113113
*/
114114
private loadListItems = async (filterText: string): Promise<{ key: string; name: string }[]> => {
115-
let { listId, columnInternalName, webUrl } = this.props;
115+
let { listId, columnInternalName, keyColumnInternalName, webUrl } = this.props;
116116
let arrayItems: { key: string; name: string }[] = [];
117-
let valueColumn: string = columnInternalName || 'Id';
117+
let keyColumn: string = keyColumnInternalName || 'Id';
118118

119119
try {
120-
let listItems = await this._spservice.getListItems(filterText, listId, columnInternalName, webUrl);
120+
let listItems = await this._spservice.getListItems(filterText, listId, columnInternalName, keyColumn, webUrl);
121121
// Check if the list had items
122122
if (listItems.length > 0) {
123123
for (const item of listItems) {
124-
arrayItems.push({ key: item[valueColumn], name: item[columnInternalName] });
124+
arrayItems.push({ key: item[keyColumn], name: item[columnInternalName] });
125125
}
126126
}
127127
return arrayItems;

src/services/ISPService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ export interface ISPService {
2121
* @param options Options used to order and filter during the API query
2222
*/
2323
getLibs(options?: ILibsOptions): Promise<ISPLists>;
24-
getListItems?(filterText: string, listId: string, internalColumnName: string, webUrl?: string) : Promise<any[]>;
24+
getListItems?(filterText: string, listId: string, internalColumnName: string, keyInternalColumnName?: string, webUrl?: string) : Promise<any[]>;
2525
}

src/services/SPService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ export default class SPService implements ISPService {
4747
/**
4848
* Get List Items
4949
*/
50-
public async getListItems(filterText: string, listId: string, internalColumnName: string, valueInternalColumnName?: string, webUrl?: string): Promise<any[]> {
50+
public async getListItems(filterText: string, listId: string, internalColumnName: string, keyInternalColumnName?: string, webUrl?: string): Promise<any[]> {
5151
let returnItems: any[];
5252

5353
try {
5454
const webAbsoluteUrl = !webUrl ? this._context.pageContext.web.absoluteUrl : webUrl;
55-
const apiUrl = `${webAbsoluteUrl}/_api/web/lists('${listId}')/items?$select=${valueInternalColumnName || 'Id'},${internalColumnName}&$filter=startswith(${internalColumnName},'${filterText}')`;
55+
const apiUrl = `${webAbsoluteUrl}/_api/web/lists('${listId}')/items?$select=${keyInternalColumnName || 'Id'},${internalColumnName}&$filter=startswith(${internalColumnName},'${filterText}')`;
5656
const data = await this._context.spHttpClient.get(apiUrl, SPHttpClient.configurations.v1);
5757
if (data.ok) {
5858
const results = await data.json();

0 commit comments

Comments
 (0)