Skip to content

Commit

Permalink
#319 - Added OData list filter
Browse files Browse the repository at this point in the history
  • Loading branch information
estruyf committed Jul 9, 2019
1 parent c555d1d commit 02b1ddf
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 9 deletions.
1 change: 1 addition & 0 deletions docs/documentation/docs/controls/ListPicker.md
Expand Up @@ -53,6 +53,7 @@ The `ListPicker` control can be configured with the following properties:
| className | string | no | If provided, additional class name to provide on the dropdown element. |
| disabled | boolean | no | Whether or not the control is disabled. |
| baseTemplate | number | no | The SharePoint BaseTemplate ID to filter the list options by. |
| filter | string | no | Filter list from OData query (takes precendents over Hidden and BaseTemplate Filters). |
| includeHidden | boolean | no | Whether or not to include hidden lists. Default is `true`. |
| orderBy | LibsOrderBy | no | How to order the lists retrieved from SharePoint. |
| selectedList | string OR string[] | no | Keys of the selected item(s). If you provide this, you must maintain selection state by observing onSelectionChanged events and passing a new value in when changed. |
Expand Down
4 changes: 4 additions & 0 deletions src/controls/listPicker/IListPicker.ts
Expand Up @@ -26,6 +26,10 @@ export interface IListPickerProps {
* Whether or not to include hidden lists. Default is true
*/
includeHidden?: boolean;
/**
* Filter list from OData query (takes precendents over Hidden and BaseTemplate Filters)
*/
filter?: string;
/**
* How to order the lists retrieved from SharePoint
*/
Expand Down
5 changes: 3 additions & 2 deletions src/controls/listPicker/ListPicker.tsx
Expand Up @@ -63,7 +63,7 @@ export class ListPicker extends React.Component<IListPickerProps, IListPickerSta
* Loads the list from SharePoint current web site
*/
private loadLists() {
const { context, baseTemplate, includeHidden, orderBy, multiSelect, selectedList } = this.props;
const { context, baseTemplate, includeHidden, orderBy, multiSelect, filter, selectedList } = this.props;

// Show the loading indicator and disable the dropdown
this.setState({ loading: true });
Expand All @@ -72,7 +72,8 @@ export class ListPicker extends React.Component<IListPickerProps, IListPickerSta
service.getLibs({
baseTemplate: baseTemplate,
includeHidden: includeHidden,
orderBy: orderBy
orderBy: orderBy,
filter: filter
}).then((results) => {
// Start mapping the lists to the dropdown option
results.value.map(list => {
Expand Down
1 change: 1 addition & 0 deletions src/services/ISPService.ts
Expand Up @@ -12,6 +12,7 @@ export interface ILibsOptions {
orderBy?: LibsOrderBy;
baseTemplate?: number;
includeHidden?: boolean;
filter?: string;
}

export interface ISPService {
Expand Down
18 changes: 11 additions & 7 deletions src/services/SPService.ts
Expand Up @@ -22,14 +22,18 @@ export default class SPService implements ISPService {
queryUrl += `&$orderby=${options.orderBy === LibsOrderBy.Id ? 'Id' : 'Title'}`;
}

if (options.baseTemplate) {
queryUrl += `&$filter=BaseTemplate eq ${options.baseTemplate}`;
filtered = true;
}
if (options.filter) {
queryUrl += `&$filter=${encodeURIComponent(options.filter)}`;
} else {
if (options.baseTemplate) {
queryUrl += `&$filter=BaseTemplate eq ${options.baseTemplate}`;
filtered = true;
}

if (options.includeHidden === false) {
queryUrl += filtered ? ' and Hidden eq false' : '&$filter=Hidden eq false';
filtered = true;
if (options.includeHidden === false) {
queryUrl += filtered ? ' and Hidden eq false' : '&$filter=Hidden eq false';
filtered = true;
}
}

const data = await this._context.spHttpClient.get(queryUrl, SPHttpClient.configurations.v1);
Expand Down
1 change: 1 addition & 0 deletions src/webparts/controlsTest/components/ControlsTest.tsx
Expand Up @@ -549,6 +549,7 @@ export default class ControlsTest extends React.Component<IControlsTestProps, IC
baseTemplate={100}
includeHidden={false}
multiSelect={true}
// filter="Title eq 'Test List'"
onSelectionChanged={this.onListPickerChange} />
</div>

Expand Down

0 comments on commit 02b1ddf

Please sign in to comment.