Refresh SharePoint ListView without refreshing the page

Of course you have once updated a SharePoint listitem out of the list view. To display the results you've updated the whole page. But you do not need to.
With this simple statement you can update the view without any redirect or refreshing of the page:


1
__doPostBack($("[id^='ctl00_'][id$='_ctl02'][id!='ctl00_SiteActionsMenuMain_ctl00_ctl02']")[0].id, "cancel");

For this version you need to use jQuery, because of the selector. The selector I added made this code work for every list.
It select DOM elements where the id begins with "ct100_" and ends with "_ct102". All lists are named like this. There is just one exception you need to keep an eye on: the actions menu. just exclude it with the last statement and you're fine.

1
$("[id^='ctl00_'][id$='_ctl02'][id!='ctl00_SiteActionsMenuMain_ctl00_ctl02']")[0].id

The selector picks the table DOM element that is representing a list and gets the id of it. You can pick the id out of the DOM explorer by your own and do it without jQuery, but when the GUID of the list changes you need to change the code.

By the way: this methods also works with Client Side Rendering. The CSR code you wrote will be executed again as part of the refresh.

Comments

Popular posts from this blog

How to support multiple languages in WPF