Last week I published my fourth CodePlex project, called SharePoint LiveListData. It is an “assembly-free” solution which means that it contains no server side code. It is implemented as a jQuery plugin.
So what does it do? It uses AJAX to automatically reload any list-based Web Parts as soon as a change in the underlying list data is detected. You can also have your custom web parts refreshed, as long as they have a web part property that contains the ID of the list they depend on!
I have put online a screencast that demonstrates the the user experience.
Want to know how it works? Allow me to describe using some pseudo code..
- OnDocumentLoaded
- Make a single call to WebParts.asmx web service using AJAX to return an xml document with all web parts on the current page
- Parse returned xml and find all web part nodes that contain a ListID element (which holds the value for the ListID web part property)
- Create and populate a javascript object that contains a list of all ListIDs that we found in the returned xml, plus a list of all WebPartIDs per ListID, also retrieved from the xml (more or less creating a hashtable with the key being the ListID and the value being an array or WebPartIDs).
- LOOP with interval = $configured_interval
- Make a single call to Lists.asmx web service using AJAX to retrieve “LastDeleted” and “Modified” properties for each ListID in the hashtable that was created earlier.
- For each ListID in hashtable
- compare values for LastDeleted and Modified with those values retrieved as part of the previous loop iteration for this ListID (unless it’s the first iteration).
- If a change in one of the two property values has been detected (indicating that someone inserted, updated or deleted an item) mark this ListID as “UpdatePending”, storing it on our javascript object that holds our ListIDs and WebPartIDs.
- If any of the ListIDs are marked as UpdatePending
- Make an AJAX request to page that is currently loaded in the browser (allowing us to get a fresh copy of the current page containing the new list data)
- For each ListID marked as UpdatePending
- For each WebPartID associated with ListID in our javascript hashtable object thingy
- Replace div with matching WebPartID attribute in current document with “same” div in AJAX response (which contains the new list data).
- For each WebPartID associated with ListID in our javascript hashtable object thingy
This is basically how it works in a nutshell.
For examples on usage, check out the downloads tab on the SharePoint LiveListData CodePlex site, where you can also download the script!
Hi,
any chance to make it work with grouped views?
Cheers
Comment by Wiktor — November 18, 2009 @ 4:50 pm
Using SharePoint LiveListData on AJAX enabled WSS 3.0. Dropped the jquery.sharepoint.livelistdata.cewp.txt on a page that also contains the OOB Tasks list WebPart. WebPart is not updating…. Do I need to alter the text before inserting into the CEWP? Thanks for the work on this.
Bill
Comment by Bill Burke — November 21, 2009 @ 11:48 pm
After further testing your solution works as advertised (really well)… I have found that it will not work after converting to xslt. It did however, as a web part, work with grouped and filtered views.
Comment by Bill Burke — November 22, 2009 @ 6:29 am
If the view used in the LVWP is group and collapsed, after refreshing the data it expands all items.
Is there something I can do to prevent that from happening?
Thanks, Bill
Comment by Bill Burke — November 22, 2009 @ 9:18 pm
Hi Bill,
unfortunately, because of the way it reloads a web part (it does a web request to the current page in the background), it will not remember the state of the webpart before it was refreshed (there is no postback).
I would be interested to hear more about your xslt scenario you descried in your comment from 21 November. Would like to find out why that isn’t working. Could you let me know how created your webpart?
Comment by Jaap Vossers — November 22, 2009 @ 11:05 pm
@Wiktor, it should work just fine with grouped views.
Comment by Jaap Vossers — November 22, 2009 @ 11:05 pm