1

I have a simple document library web part added to my SharePoint aspx page.

I'm wondering if I can change the View inside a Document Library WebPart from JavaScript dynamically?

For Example:

http://SiteURL?viewName=Test 

Here Test is my current View

And the Document Library is having default All Documents View. I want that the document library web part should change the View from All Documents to Test View.

Is something like this possible using JavaScript?

6
  • Please explain which can of page and add an image if you can. Commented Jul 19, 2017 at 10:06
  • The given edit for the question is what one would expect the requirement to be. However, the initial question could be altered to different requirements, which is why I'd hope the OP @kolek to confirm whether the question is now addressing the original requirement.
    – moe
    Commented Jul 19, 2017 at 10:14
  • yes it still meets the requirements
    – kolek
    Commented Jul 19, 2017 at 10:16
  • Do you want to change the view to Test permanently? Or it should be changed according to query string? Commented Jul 19, 2017 at 11:16
  • It should change according to query string
    – kolek
    Commented Jul 19, 2017 at 11:35

1 Answer 1

2

ListView WebPart's added on a page, its source view cannnot be changed dynamically using client side code ( JavaScript ).

However, here are work arounds:

Method #1

  1. Insert an IFrame on your page and set the source to View page URL with passing URL parameter IsDlg=1. Example: AllItems.aspx?IsDlg=1

  2. Use JavaScript to update IFrame source URL

Method # 2

You can pass filter parameters to your page.

YourPage.aspx?FilterField1=Title&FilterValue1=SomeValue

You can also extend it to pass more paraters like this: YourPage.aspx?FilterField1=Title&FilterValue1=SomeValue&FilterField2=OtherField&FilterValue2=OtherValue

So, using JavaScript you need to reload page with required URL parameters.

The downside of this solution is that filter applies to all ListView WebParts on that page. enter image description here

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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