2

I am using the following JQuery to get the current name of the View for External SharePoint list.

var ctx = GetCurrentCtx();
var listName =ctx.ListTitle; 
var currentView =  $('[id*=\'ListTitleViewSelectorMenu\'] span:first').text();

My issue is, If the name of the current view is too long, it gets cut off while displaying in breadcrumb. Now when I am passing the value of my current view using Request.Querystring, the value gets trimmed.

How can I resolve this issue in order to get the complete name of my view?

2

SharePoint 2013

For determining current List View the following properties of ContextInfo structure could be used:

  • view - returns the current View Id

  • viewTitle - returns the current View title

viewTitle is not available in SharePoint 2010

Example:

_spBodyOnLoadFunctionNames.push("PrintContextInfo");   
function PrintContextInfo()   
{   
   var ctx = GetCurrentCtx();
   console.log(ctx.viewTitle); 
}   
  • I happened to need this as well, I tried running GetCurrentCtx() but I am getting a null. I currently have it in a $(document).ready function... Am i on the right track? – BlueBird Nov 25 '13 at 21:33
  • Since SharePoint provides its own mechanism for page loading via _spBodyOnLoadFunctionNames array, it is recommended to place the call for that code inside specified array. – Vadim Gremyachev Nov 25 '13 at 21:53
  • I still get a null context, when I change it to "new SP.ClientContext.get_current();" it will return a context however there is no viewTitle property. – BlueBird Nov 26 '13 at 15:59
  • The answer has been updated,indeed, viewTitle property does not exists in SharePoint 2010 – Vadim Gremyachev Nov 26 '13 at 21:36
0

I got the view name passing the GUID of my view as following,

var listName =ctx.ListTitle;   
var currentViewGuid = ctx.view;
var url = $(location).attr('href');
var customurl = L_Menu_BaseUrl + '/_layouts/CustomRibbon/ExportList.aspx?list=' + listName + '&url=' + url + '&viewguid=' + currentViewGuid;

In my page load,

 public string viewguid;
 public string url;
 public string list;

 list = Request.QueryString["list"];              
 url = Request.QueryString["url"];
 viewguid = Request.QueryString["viewguid"];

 currentSPSite = new SPSite(url);
 SPWeb currentSPWeb = currentSPSite.OpenWeb();
 SPList currentList = currentSPWeb.Lists[list];
 SPView custView = currentList.GetView(new Guid(viewguid));
 view = custView.Title;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.