Skip to content

Commit

Permalink
Updates to PR #355
Browse files Browse the repository at this point in the history
  • Loading branch information
AJIXuMuK committed Oct 8, 2019
1 parent 5a499d8 commit 8c126c7
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/documentation/docs/controls/ListItemPicker.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ The `ListItemPicker` control can be configured with the following properties:
| Property | Type | Required | Description |
| ---- | ---- | ---- | ---- |
| columnInternalName | string | yes | InternalName of column to search and get values. |
| valueColumnInternalName | string | no | InternalName of column to use as the value or key for the selection. Must be a column with unique values. |
| keyColumnInternalName | string | no | InternalName of column to use as the key for the selection. Must be a column with unique values. Default: Id |
| context | WebPartContext \| ApplicationCustomizerContext | yes | SPFx web part or extention context |
| listId | string | yes | Guid of the list. |
| itemLimit | number | yes | Number of items which can be selected |
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/controls/listItemPicker/IListItemPickerProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ApplicationCustomizerContext } from "@microsoft/sp-application-base";

export interface IListItemPickerProps {
columnInternalName: string;
valueColumnInternalName?: string;
keyColumnInternalName?: string;
context: WebPartContext | ApplicationCustomizerContext;
listId: string;
itemLimit: number;
Expand Down
8 changes: 4 additions & 4 deletions src/controls/listItemPicker/ListItemPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,16 @@ export class ListItemPicker extends React.Component<IListItemPickerProps, IListI
* Function to load List Items
*/
private loadListItems = async (filterText: string): Promise<{ key: string; name: string }[]> => {
let { listId, columnInternalName, webUrl } = this.props;
let { listId, columnInternalName, keyColumnInternalName, webUrl } = this.props;
let arrayItems: { key: string; name: string }[] = [];
let valueColumn: string = columnInternalName || 'Id';
let keyColumn: string = keyColumnInternalName || 'Id';

try {
let listItems = await this._spservice.getListItems(filterText, listId, columnInternalName, webUrl);
let listItems = await this._spservice.getListItems(filterText, listId, columnInternalName, keyColumn, webUrl);
// Check if the list had items
if (listItems.length > 0) {
for (const item of listItems) {
arrayItems.push({ key: item[valueColumn], name: item[columnInternalName] });
arrayItems.push({ key: item[keyColumn], name: item[columnInternalName] });
}
}
return arrayItems;
Expand Down
2 changes: 1 addition & 1 deletion src/services/ISPService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ export interface ISPService {
* @param options Options used to order and filter during the API query
*/
getLibs(options?: ILibsOptions): Promise<ISPLists>;
getListItems?(filterText: string, listId: string, internalColumnName: string, webUrl?: string) : Promise<any[]>;
getListItems?(filterText: string, listId: string, internalColumnName: string, keyInternalColumnName?: string, webUrl?: string) : Promise<any[]>;
}
4 changes: 2 additions & 2 deletions src/services/SPService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ export default class SPService implements ISPService {
/**
* Get List Items
*/
public async getListItems(filterText: string, listId: string, internalColumnName: string, valueInternalColumnName?: string, webUrl?: string): Promise<any[]> {
public async getListItems(filterText: string, listId: string, internalColumnName: string, keyInternalColumnName?: string, webUrl?: string): Promise<any[]> {
let returnItems: any[];

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

0 comments on commit 8c126c7

Please sign in to comment.