Skip to content

Commit 02b1ddf

Browse files
committed
#319 - Added OData list filter
1 parent c555d1d commit 02b1ddf

File tree

6 files changed

+21
-9
lines changed

6 files changed

+21
-9
lines changed

docs/documentation/docs/controls/ListPicker.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ The `ListPicker` control can be configured with the following properties:
5353
| className | string | no | If provided, additional class name to provide on the dropdown element. |
5454
| disabled | boolean | no | Whether or not the control is disabled. |
5555
| baseTemplate | number | no | The SharePoint BaseTemplate ID to filter the list options by. |
56+
| filter | string | no | Filter list from OData query (takes precendents over Hidden and BaseTemplate Filters). |
5657
| includeHidden | boolean | no | Whether or not to include hidden lists. Default is `true`. |
5758
| orderBy | LibsOrderBy | no | How to order the lists retrieved from SharePoint. |
5859
| 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. |

src/controls/listPicker/IListPicker.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ export interface IListPickerProps {
2626
* Whether or not to include hidden lists. Default is true
2727
*/
2828
includeHidden?: boolean;
29+
/**
30+
* Filter list from OData query (takes precendents over Hidden and BaseTemplate Filters)
31+
*/
32+
filter?: string;
2933
/**
3034
* How to order the lists retrieved from SharePoint
3135
*/

src/controls/listPicker/ListPicker.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export class ListPicker extends React.Component<IListPickerProps, IListPickerSta
6363
* Loads the list from SharePoint current web site
6464
*/
6565
private loadLists() {
66-
const { context, baseTemplate, includeHidden, orderBy, multiSelect, selectedList } = this.props;
66+
const { context, baseTemplate, includeHidden, orderBy, multiSelect, filter, selectedList } = this.props;
6767

6868
// Show the loading indicator and disable the dropdown
6969
this.setState({ loading: true });
@@ -72,7 +72,8 @@ export class ListPicker extends React.Component<IListPickerProps, IListPickerSta
7272
service.getLibs({
7373
baseTemplate: baseTemplate,
7474
includeHidden: includeHidden,
75-
orderBy: orderBy
75+
orderBy: orderBy,
76+
filter: filter
7677
}).then((results) => {
7778
// Start mapping the lists to the dropdown option
7879
results.value.map(list => {

src/services/ISPService.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export interface ILibsOptions {
1212
orderBy?: LibsOrderBy;
1313
baseTemplate?: number;
1414
includeHidden?: boolean;
15+
filter?: string;
1516
}
1617

1718
export interface ISPService {

src/services/SPService.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,18 @@ export default class SPService implements ISPService {
2222
queryUrl += `&$orderby=${options.orderBy === LibsOrderBy.Id ? 'Id' : 'Title'}`;
2323
}
2424

25-
if (options.baseTemplate) {
26-
queryUrl += `&$filter=BaseTemplate eq ${options.baseTemplate}`;
27-
filtered = true;
28-
}
25+
if (options.filter) {
26+
queryUrl += `&$filter=${encodeURIComponent(options.filter)}`;
27+
} else {
28+
if (options.baseTemplate) {
29+
queryUrl += `&$filter=BaseTemplate eq ${options.baseTemplate}`;
30+
filtered = true;
31+
}
2932

30-
if (options.includeHidden === false) {
31-
queryUrl += filtered ? ' and Hidden eq false' : '&$filter=Hidden eq false';
32-
filtered = true;
33+
if (options.includeHidden === false) {
34+
queryUrl += filtered ? ' and Hidden eq false' : '&$filter=Hidden eq false';
35+
filtered = true;
36+
}
3337
}
3438

3539
const data = await this._context.spHttpClient.get(queryUrl, SPHttpClient.configurations.v1);

src/webparts/controlsTest/components/ControlsTest.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ export default class ControlsTest extends React.Component<IControlsTestProps, IC
549549
baseTemplate={100}
550550
includeHidden={false}
551551
multiSelect={true}
552+
// filter="Title eq 'Test List'"
552553
onSelectionChanged={this.onListPickerChange} />
553554
</div>
554555

0 commit comments

Comments
 (0)