Dismiss Notice

Register now to be one of the first members of this SharePoint Community! Click here it just takes seconds!

Dismiss Notice
Welcome Guest from Country Flag

Sharepoint API _api/Lists - Get the default view for all lists on the site (no subsites)

Discussion in 'SharePoint Blogs' started by /u/Thriven, Mar 30, 2017.

Thread Status:
Not open for further replies.
  1. /u/Thriven

    /u/Thriven Guest

    Blog Posts:
    0
    So I wanted to add a bunch of menu items that were just a filtered list of site contents to my custom menu.

    The issue is that /_api/lists/ doesn't give you a default view url for each list. I initially made the onclick action hit the lists /DefaultView/ call to get the default URL. I have thought about making this happen asynchronously as the page is loading and on call back update the a tag's href value.

    I feel like there has got to be a better way to pull a list of lists and just get title and default view url. Which is all I really need.

    Here is my code

    $.ajax({ url: _spPageContextInfo.webServerRelativeUrl + '/_api/lists/', type: 'GET', header: {'Accept': 'application/json;odata=verbose'}, dataType: "json", success: function(data) { //adds UL/LI elements to my menu var a = document.createElement("a"); a.onclick = function(){navigateToDefaultView(value.Id,value.ParentWebUrl);}; div.appendChild(a); //yada yada } }) function navigateToDefaultView(guid,root){ $.ajax({ url: root + "/_api/lists(guid'" + guid + "')/DefaultView/", type: 'GET', header: {'Accept': 'application/json;odata=verbose'}, dataType: "json", success: function(data) { window.location = data.ServerRelativeUrl; } }); }
    submitted by /u/Thriven
    [link] [comments]

    Continue reading...
     
Thread Status:
Not open for further replies.

Share This Page

LiveZilla Live Chat Software