Skip to content

Commit a88084e

Browse files
committed
Merge branch 'kunj-sangani-master' into dev
2 parents 45bae64 + 0440d50 commit a88084e

File tree

5 files changed

+35
-20
lines changed

5 files changed

+35
-20
lines changed

docs/documentation/docs/controls/ListItemPicker.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { ListItemPicker } from '@pnp/spfx-controls-react/lib/ListItemPicker';
2525
columnInternalName='Title'
2626
keyColumnInternalName='Id'
2727
filter="Title eq 'SPFx'"
28+
orderBy={"Id desc"}
2829
itemLimit={2}
2930
onSelectedItem={this.onSelectedItem}
3031
context={this.props.context} />
@@ -60,6 +61,7 @@ The `ListItemPicker` control can be configured with the following properties:
6061
| noResultsFoundText | string | no | The text that should appear when no results are returned. |
6162
| disabled | boolean | no | Specifies if the control is disabled or not. |
6263
| filter | string | no | condition to filter list Item, same as $filter ODATA parameter|
64+
| orderBy | string | no | condition to order by list Item, same as $orderby ODATA parameter|
6365
| placeholder | string | no | Short text hint to display in empty picker |
6466
| substringSearch | boolean | no | Specifies if substring search should be used |
6567

src/controls/listItemPicker/IListItemPickerProps.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export interface IListItemPickerProps {
88
listId: string;
99
itemLimit: number;
1010
filter?: string;
11+
orderBy?: string;
1112
className?: string;
1213
webUrl?: string;
1314
defaultSelectedItems?: any[];

src/controls/listItemPicker/ListItemPicker.tsx

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,23 +68,23 @@ export class ListItemPicker extends React.Component<IListItemPickerProps, IListI
6868
return (
6969
<div>
7070
<TagPicker onResolveSuggestions={this.onFilterChanged}
71-
// getTextFromItem={(item: any) => { return item.name; }}
72-
getTextFromItem={this.getTextFromItem}
73-
pickerSuggestionsProps={{
74-
suggestionsHeaderText: suggestionsHeaderText,
75-
noResultsFoundText: noresultsFoundText
76-
}}
77-
selectedItems={selectedItems}
78-
onChange={this.onItemChanged}
79-
className={className}
80-
itemLimit={itemLimit}
81-
disabled={disabled}
82-
inputProps={{
83-
placeholder: placeholder
84-
}} />
71+
// getTextFromItem={(item: any) => { return item.name; }}
72+
getTextFromItem={this.getTextFromItem}
73+
pickerSuggestionsProps={{
74+
suggestionsHeaderText: suggestionsHeaderText,
75+
noResultsFoundText: noresultsFoundText
76+
}}
77+
selectedItems={selectedItems}
78+
onChange={this.onItemChanged}
79+
className={className}
80+
itemLimit={itemLimit}
81+
disabled={disabled}
82+
inputProps={{
83+
placeholder: placeholder
84+
}} />
8585

8686
{!!errorMessage &&
87-
(<Label style={{color:'#FF0000'}}> {errorMessage} </Label>)}
87+
(<Label style={{ color: '#FF0000' }}> {errorMessage} </Label>)}
8888
</div>
8989
);
9090
}
@@ -144,15 +144,15 @@ export class ListItemPicker extends React.Component<IListItemPickerProps, IListI
144144
* Function to load List Items
145145
*/
146146
private loadListItems = async (filterText: string): Promise<{ key: string; name: string }[]> => {
147-
let { listId, columnInternalName, keyColumnInternalName, webUrl, filter, substringSearch } = this.props;
147+
let { listId, columnInternalName, keyColumnInternalName, webUrl, filter, orderBy, substringSearch } = this.props;
148148
const {
149149
field
150150
} = this.state;
151151
let arrayItems: { key: string; name: string }[] = [];
152152
let keyColumn: string = keyColumnInternalName || 'Id';
153153

154154
try {
155-
let listItems = await this._spservice.getListItems(filterText, listId, columnInternalName, field, keyColumn, webUrl, filter, substringSearch); // JJ - 20200613 - find by substring as an option
155+
let listItems = await this._spservice.getListItems(filterText, listId, columnInternalName, field, keyColumn, webUrl, filter, substringSearch, orderBy ? orderBy : ''); // JJ - 20200613 - find by substring as an option
156156
// Check if the list had items
157157
if (listItems.length > 0) {
158158
for (const item of listItems) {

src/services/SPService.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,25 @@ export default class SPService implements ISPService {
7575
/**
7676
* Get List Items
7777
*/
78-
public async getListItems(filterText: string, listId: string, internalColumnName: string, field: ISPField | undefined, keyInternalColumnName?: string, webUrl?: string, filter?: string, substringSearch: boolean = false): Promise<any[]> {
78+
public async getListItems(filterText: string, listId: string, internalColumnName: string, field: ISPField | undefined, keyInternalColumnName?: string, webUrl?: string, filter?: string, substringSearch: boolean = false, orderBy?: string): Promise<any[]> {
7979
let returnItems: any[];
8080
const webAbsoluteUrl = !webUrl ? this._webAbsoluteUrl : webUrl;
8181
let apiUrl = '';
8282
let isPost = false;
8383

8484
if (field && field.TypeAsString === 'Calculated') { // for calculated fields we need to use CAML query
85-
const camlQuery = `<View><Query><Where>${substringSearch ? '<Contains>' : '<BeginsWith>'}<FieldRef Name="${internalColumnName}"/><Value Type="${field.ResultType}">${filterText}</Value>${substringSearch ? '</Contains>' : '</BeginsWith>'}</Where></Query></View>`;
85+
let orderByStr = '';
86+
87+
if (orderBy) {
88+
const orderByParts = orderBy.split(' ');
89+
let ascStr = '';
90+
if (orderByParts[1] && orderByParts[1].toLowerCase() === 'desc') {
91+
ascStr = `Ascending="FALSE"`;
92+
}
93+
orderByStr = `<OrderBy><FieldRef Name="${orderByParts[0]}" ${ascStr} />`;
94+
}
95+
96+
const camlQuery = `<View><Query><Where>${substringSearch ? '<Contains>' : '<BeginsWith>'}<FieldRef Name="${internalColumnName}"/><Value Type="${field.ResultType}">${filterText}</Value>${substringSearch ? '</Contains>' : '</BeginsWith>'}</Where>${orderByStr}</Query></View>`;
8697

8798
apiUrl = `${webAbsoluteUrl}/_api/web/lists('${listId}')/GetItems(query=@v1)?$select=${keyInternalColumnName || 'Id'},${internalColumnName}&@v1=${JSON.stringify({ ViewXml: camlQuery })}`;
8899
isPost = true;
@@ -91,7 +102,7 @@ export default class SPService implements ISPService {
91102
const filterStr = substringSearch ? // JJ - 20200613 - find by substring as an option
92103
`substringof('${encodeURIComponent(filterText.replace("'", "''"))}',${internalColumnName})${filter ? ' and ' + filter : ''}`
93104
: `startswith(${internalColumnName},'${encodeURIComponent(filterText.replace("'", "''"))}')${filter ? ' and ' + filter : ''}`; //string = filterList ? `and ${filterList}` : '';
94-
apiUrl = `${webAbsoluteUrl}/_api/web/lists('${listId}')/items?$select=${keyInternalColumnName || 'Id'},${internalColumnName}&$filter=${filterStr}`;
105+
apiUrl = `${webAbsoluteUrl}/_api/web/lists('${listId}')/items?$select=${keyInternalColumnName || 'Id'},${internalColumnName}&$filter=${filterStr}&$orderby=${orderBy}`;
95106
}
96107

97108
try {

src/webparts/controlsTest/components/ControlsTest.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,6 +1298,7 @@ export default class ControlsTest extends React.Component<IControlsTestProps, IC
12981298
columnInternalName="Title"
12991299
keyColumnInternalName="Id"
13001300
filter={"Title eq 'SPFx'"}
1301+
orderBy={'Title desc'}
13011302
itemLimit={5}
13021303
context={this.props.context}
13031304
placeholder={'Select list items'}

0 commit comments

Comments
 (0)