4

I have a SharePoint 2013 Calendar list view in a page, also I have a filter with some choice values. Now based on the filter value, the SharePoint Calendar list view should be filtered .

I am not aware how to do it. Any help?

2
+75

In essence filtering can only be done according to the metadata you specify for the items in your calendar. There are also automatically available metadata, such as the modified/create properties, but everything depends on how you need to filter the calendar.

Once you have your metadata in place, filtering may begin. Filtering can be done with whichever semi-complex ajax/REST calls you'd imagine, but SharePoint has OOTB fairly well working web parts for the job. I should note that if you still decide to create a filter with e.g. a REST API call, you would need to hardcode the property (i.e. a column) of a calendar list item to your call.

So what I'm saying is you could do this in a REST API call such as

$.ajax({
    url: _spPageContextInfo.webAbsoluteUrl + "/_api/Web/Lists/GetByTitle('Calendar')/items?$select=Title,Column3&$filter=(Column eq '"+customVariable+"')&$top=40",
    type: "GET",
    dataType: "json",
    headers: {
        Accept: "application/json;odata=verbose"
    }
});

but I would suggest you to not rush into a custom code solution.

Instead a more straight-forward implementation can be done by using the OOTB filter web parts namely Choice Filter, Date Filter, Text Filter or another fitting to your needs.

Filter web parts are added to your page where the calendar's view has been added too. The web part connection is done from the filter web part's properties at the Connections-section by defining the Calendar in the Send Filter Values To selection.

Because different filter web parts have different use cases and slightly varying usage, I should forward you to Microsoft's documentation for Connect a Filter Web Part to a List View Web Part on a classic page.


To summarize, (1) make sure you have the metadata for your filtering needs, (2) determine is there a chance you might need to change your filtering behavior - or whether you want it to be more user-driven instead of hardcoded, and finally (3) implement the solution around your need.

The benefits of using a custom code solution are that the filtering when using ajax can be more user-friendly and it supports the "on the fly" behavior. The drawbacka are a more time consuming implementation and maintainability. The benefits of using OOTB web parts are the ease of setup and directly available user-driven inputs. The drawbacks with OOTB web parts are user-experience (e.g. incomplete text-filtering may not function as expected) and lack of support for more complex filter requirements.

0

I don't know where the filter values orginate from, but the no code solution to this challenge would be to use Web Part Filter connections: https://blogs.technet.microsoft.com/rajbugga/2013/04/25/creating-connected-web-parts-in-sharepoint/

Edit


Maybe I misread the question and thought you wanted a no-code solution. If you are using code, there's an option to filter webparts without a page refresh using the InplviewHash paramater. If you have a list on your page and filter it, you see the url changing. It's also a good source to find the relevant Guid to build the url.

You can find an example and explanation here: https://www.codeproject.com/Articles/1055761/Dynamic-Filtering-of-the-Related-Items-List-on-a-S

  • This wont work in my scenario....I need to change the view on customized button click – Dheeraj Jul 24 '18 at 8:49
0

If you have the know-how to use angularjs and the rest API you could roll your own calendar control, and ditch the native calendar altogether.

There are open-source options, or paid ones as well.

Ultimately the native calendar control is pretty terrible, but keeping the UX consistent across calendars is important so ditching it isn't always the best approach. I guess my point is that you can treat SharePoint as nothing more than a data source sometimes, and then you're free to do whatever you want with it!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.