0

First of all, my question. How do I make a working modal dialog popup for a document library, that shows details about that document upon clicking the document name in the library list?

Please note that I have a working script for an announcements list, when I click an item in the list it shows me details about that item in the modal dialog popup.

I want to achieve the same action, but with a document library. So far the popup works but instead of showing me details about the document I clicked on, it shows me the complete document library again.
My problem is somewhat urgent as I desire to give a demo of my site by next week Tuesday.

This is the script for the modal dialog for an announcements list, and this works:

(function () { 
  var itemCtx = {};
  itemCtx.Templates = {};
  itemCtx.Templates.Item = ItemOverrideFun;
  itemCtx.BaseViewID = 1;
  itemCtx.ListTemplateType = 104;
    // For the document library, I used DocumentTemplateType instead of ListTemplateType 

  SPClientTemplates.TemplateManager.RegisterTemplateOverrides(itemCtx);
})(); 

function openDialog(pUrl) { 
  var options = {
    title : "Announcement",
    width : 600,
    height : 400,
    url : pUrl };

  SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options);
}

function ItemOverrideFun(ctx) {
  var _announcementDesc = ctx.CurrentItem.Body;
  var _announcementTitle = ctx.CurrentItem.Title;
  var _announcementDate = ctx.CurrentItem.Datum;
  var _announcementID = ctx.CurrentItem.ID;

  return "<tr><td></td><td style='vertical-align: top;'>" 
  + _announcementDate + "</td><td>" 
  + '<a href="javascript:openDialog(' + "'" 
  + "http://sitecollection/subsite/Lists/Listname/DispForm.aspx?ID=" 
  + _announcementID + "');" + '">' 
  + _announcementTitle + '</a>'
  + "</td></tr>";
}

I replaced some names in the script above (removed my site info) but it's a working script. The one I try to use for the document library is very similar, the only changes I made are in the first function (see comment in code) and in the function ItemOverrideFun(ctx) part. Instead of calling the items of an announcements list I now try to call those of a document library, no success so far.

Can anyone tell me what I might be doing wrong? Help with the code is greatly appreciated, as I want to finish this as soon as I can.

(Additional info: Reason I need a modal dialog popup for the items in a document library is because there are too many columns and it makes the page too wide. I can't limit the amount of columns. I want to show only 3 columns in the view on the page (type of document, name of document, date created) and all the other columns shown in the dialog.)

  • hi! Can you, please, copy here the resulting url for the dialog window that pops up? – Denis Molodtsov Aug 22 '13 at 13:18
  • When I hover over it then I see javascript:openDialog('http://sitecollection/subsite/LibraryName/Forms/AllItems.aspx?ID=1'); in the status bar at the bottom of my browser (I replaced the name of my site collection, subsite and document library). The link is nearly the same as the one I use for the list dialog window, with the exception of LibraryName being replaced by ListName. – Magali Aug 22 '13 at 13:40
  • You see, the form name is wrong here for some reason. It should be DispFrom.aspx instead of AllItems‌.aspx. Don't know where the problem is yet. Are you sure you didn't misspell it in the ItemOverrideFun function? – Denis Molodtsov Aug 22 '13 at 13:47
  • Didn't really get what do you mean with "I used DocumentTemplateType instead of ListTemplateType". Try to set itemCtx.ListTemplateType = 101 instead of 104 in your code (101 is list template type for Document Library) – Tim Aug 22 '13 at 13:51
  • Oh I thought since I was going to use it for a document library, that I was supposed to change it from ListTemplateType to DocumentTemplateType. Didn't think it through, I thought it might work. I changed it to ListTemplateType = 101 but so far not really a change. By the way, where did you find the numbers for the types? Like 104 for Announcements (I think) and 101 for Document Library? I haven't found them anywere and things like that would really come in handy. – Magali Aug 22 '13 at 14:00

Your Answer

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

Browse other questions tagged or ask your own question.