Forum Discussion

Marc-Etienne_Tremblay's avatar
Marc-Etienne_Tremblay
Brass Contributor
Jun 21, 2022

Work with sharepoint webparts view in javascript.

Hi, 

 

I try to find a solution to apply a particular view on webparts when I load the webpage. 

 

Actually I have 2 webparts on my page and if I go in edit mode I could manually select my custom view. 

 

But i would like change this view during the page loading. 

If I go in edit mode and I start the chrome inspector to find GUID of each view availaible in the pick list. 

So now i have  this information. 

 

{4119D054-3BAB-43CF-BD48-B2298C1D373B}  ->view listed in webparts #1 edit mode.

 

{0D95646B-C194-467C-A2BF-C50785D0C871} -> view listed in webparts #2 edit mode. 

 

I have already a javascript who run on page loading. 

 

I search to add some code line or function to this javascript. 

 

Where i could make 2 things: 

 

1. Catch the ID of each view availaible for a  webparts.

2. I want to the webparts and apply this view each time I load the page. 

 

Some people could say, easy without code, just put the view by default for the webparts !

 

That's true,  if I go in edit mode and select the right view in the pick list and save the page. 

I return on it and the selected view is always load. 

 

But this make than I need to ask at my user to go in edit mode and change the view  because this section is a page where user could fill forms to create auto subsite. For that, I use a site template and each time I test the site generation, the info section present only title column as default view. 

I need to go in edit mode and select the right view and save the change. 

After that my view stay OK and my javascript work well to present only the info associate to this subsite. 

 

If i could find a way to push the right view at my webparts during the page load, the user not have to edit the info page anymore. 

Thank you. 

 

 

 

 

 

 

  • cherbst's avatar
    cherbst
    Copper Contributor
    Hi Marc-Etienne,
    Have you gotten any feedback or come up with any solutions for this? Based on your description, I am looking for a similar solution.
    • Marc-Etienne_Tremblay's avatar
      Marc-Etienne_Tremblay
      Brass Contributor

      cherbst 

       

      Hello Cherbst, 

       

      I have put this sharepoint section on old for now. 

      I dont found solution to this.

      So when I generate my subsite with all my list and webparts I always need to switch the view manually. 

      If you have any idea about a solution Iet me know. 

       

       

Resources