Pages

Wednesday, October 30, 2013

Alternative for Connectable Webparts [Filter SharePoint list with Partial Postback to page]


Problem:-
The other day, I wanted to filter a list view web part, triggered from some action in the same page.
Every time I do action, I wanted to automatically filter the sharepoint list with that value, without
doing a full postback/refreshing the page.

Solution
Generally as SharePoint developer will get an idea to develop a connectable webparts, but this is
difficult and takes time. The alternative is from SharePoint 2013, we have a new page added in
layouts folder inplview.aspx. This generates the "inplviewhash" tag when we do filtering/sorting and
mainly it appends with "#" in url. As we know when we have # url, the page doesn’t gets reload[postback].

For Example:- If we have two webparts in the Page containing one action performed and second
showing respective filtered data. The approach is when we do action in the above webpart through
javascript frame below way of url.

Function createFilterURL() {
var filterstring += //Frame query string which contains the formatted of filterfield1,filtervalue1 [if multiple values filterfields1,filtervalues1].
var wpqschema = ctx.View;
var querystring +=  '#InplviewHash' + wpqschema.slice(1, -1).toLowerCase() + '=' + filterstring ;
window.location.hash = querystring;
}

2 comments: