sharepoint 2019 webpart js

Copper Contributor

Is it possible to modify a list web part on a page using a JavaScript script? By modification, I mean changing the view, for example, by retrieving a parameter from the URL and applying it to the view.

1 Reply

Hi @eboulard,

Certainly! You can modify a list web part on a page in SharePoint 2019 using JavaScript. JavaScript allows you to customize the behavior and properties of the web part, such as changing the view based on a parameter from the URL. Here's a simple approach you can follow:

1. Identify the list web part: Use JavaScript to find the specific list web part on the page. You can do this by targeting its HTML element or using other identifying attributes.

How to: Retrieve List Items Using JavaScript | Microsoft Learn

2. Retrieve the parameter from the URL: Use JavaScript to extract the parameter value from the URL. You can use the `window.location` object and techniques like URL parsing or regular expressions to get the parameter value.

3. Modify the view: Once you have the parameter value, you can use JavaScript to adjust the view of the list web part accordingly. For example, you can change the list view, apply filters, or modify other display settings based on the retrieved parameter.

Customize your SharePoint site UI by using JavaScript | Microsoft Learn

4. Apply the changes: Apply the modifications to the list web part by updating its properties or triggering the necessary actions. This could involve setting the desired view, refreshing the web part, or making the content reflect the changes you've made.

Please click Mark as Best Response & Like if my post helped you to solve your issue.
This will help others to find the correct solution easily. It also closes the item.

If the post was useful in other ways, please consider giving it Like.

Kindest regards,

Leon Pavesic