none
"Type (icon linked to document)" not working in SharePoint 2013

Answers

  • This code seems to work fairly reliably on views that have groups.

    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
    </script>
    <script type="text/javascript">
    function ReplaceIcons()
    {
       var p = $(location).attr("pathname");
       var listUrl = p.replace(p.substr(p.lastIndexOf('/') + 1),'');
        $(".ms-vb-icon img").each(function() {
           var alt = $(this).attr('alt').split("_")[0];
            alt = listUrl + "/DispForm.aspx?ID=" + alt + "&Source=" + encodeURIComponent(window.location.href);  
           var a = $('<a/>').attr('href', alt);
            $(this).wrap(a);
        });
    }
    $(document).ready(function() {
         var defaultExpCollGroupMethod = ExpCollGroup; 
         ExpCollGroup = function() {  
               defaultExpCollGroupMethod.apply(this, arguments);
               setTimeout(ReplaceIcons,2000);
         };
         ReplaceIcons();
    });
    </script>

    Friday, August 15, 2014 1:43 AM
  • One more addition... This will do the same as above, but have the DispForm.aspx show in a pop up window instead of redirecting the browser to another page.

    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
    </script>
    <script type="text/javascript">
    function ReplaceIcons()
    {
       var p = $(location).attr("pathname");
       var listUrl = p.replace(p.substr(p.lastIndexOf('/') + 1),'');
        $(".ms-vb-icon img").each(function() {
           var alt = $(this).attr('alt').split("_")[0];
            alt = listUrl + "/DispForm.aspx?ID=" + alt + "&Source=" + encodeURIComponent(window.location.href);  
           var a = $('<a/>').attr('href', alt).attr('onclick',"javascript:OpenPopUpPage('" + alt + "',RefreshPage);return false;");
           $(this).wrap(a);
        });
    }
    $(document).ready(function() {
         var defaultExpCollGroupMethod = ExpCollGroup; 
         ExpCollGroup = function() {  
               defaultExpCollGroupMethod.apply(this, arguments);
               setTimeout(ReplaceIcons,2000);
         };
         ReplaceIcons();
    });
    </script>

    Friday, August 15, 2014 6:50 PM

All replies

  • Hi Stoonad,

    According to your description, my understanding is that you want to make the Type(icon linked to document) to link to the current item.

    I recommend to use the code below to achieve this goal:

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function() {
        $(".ms-vb-icon img").each(function() {
           var alt = $(this).attr('alt').split("_")[0];
            alt = "http://sp/Lists/listB/DispForm.aspx?ID=" + alt;  // change the URL to the current list
           var a = $('<a/>').attr('href', alt);
            $(this).wrap(a);
        });
    });
    </script>
    

    Thanks,

    Victoria

    Forum Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.



    Victoria Xia
    TechNet Community Support

    Wednesday, August 13, 2014 10:00 AM
  • Thanks, I will try it. It's not ideal because it has to have the site URL hard coded into it.

    There is not a generic way to make the field do what it actually says it does? ("link to a document")

    It worked in SP 2007 and SP 2010.

    Wednesday, August 13, 2014 6:29 PM
  • Hi Stoonad,

    According to your description, my understanding is that you want to make the Type(icon linked to document) to link to the current item.

    I recommend to use the code below to achieve this goal:

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function() {
        $(".ms-vb-icon img").each(function() {
           var alt = $(this).attr('alt').split("_")[0];
            alt = "http://sp/Lists/listB/DispForm.aspx?ID=" + alt;  // change the URL to the current list
           var a = $('<a/>').attr('href', alt);
            $(this).wrap(a);
        });
    });
    </script>

    Thanks,

    Victoria

    Forum Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.



    Victoria Xia
    TechNet Community Support

    where do we need to use the above code ? in master page or on the library itself?
    Wednesday, August 13, 2014 7:46 PM
  • This is your code, tweaked to be a little more generic across pages.

    It gets the list URL from the current page URL instead of hard coding it, and also adds the "&Source=" to the end so when DispForm.aspx is closed, it takes you back to where you were.

    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
    </script>
    <script type="text/javascript">
    $(document).ready(function() {
       var p = $(location).attr("pathname");
       var listUrl = p.replace(p.substr(p.lastIndexOf('/') + 1),'');
        $(".ms-vb-icon img").each(function() {
           var alt = $(this).attr('alt').split("_")[0];
            alt = listUrl + "/DispForm.aspx?ID=" + alt + "&Source=" + encodeURIComponent(window.location.href);  
           var a = $('<a/>').attr('href', alt);
            $(this).wrap(a);
        });
    });
    </script>

    Wednesday, August 13, 2014 7:47 PM
  • I suppose it could be put on the master page.

    I edited the list view page and put it into a Script Editor web part. That's what I do not like - it has to be done on every list that uses that field.

    It worked in SP 2007, and in SP 2010, you could edit fldtypes.xsl or create an override xsl file and fix the xsl that MS broke in SP 2010.

    I can't for the life of me figure out how to do the same thing in SP 2013.

    Wednesday, August 13, 2014 7:51 PM
  • The above works OK on a list view UNLESS it is grouped.  When a list view is grouped and not expanded, the list items are not on the page and they are rendered dynamically via Ajax.

    I was able to get this somewhat working by hooking into the ExpCollGroup function, - that works when a user expands the group by clicking on it.

    But I cannot figure out what function is called when the page is rendered to expand the groups previously expanded.

    Anyone know what that is?

    Wednesday, August 13, 2014 9:40 PM
  • This code seems to work fairly reliably on views that have groups.

    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
    </script>
    <script type="text/javascript">
    function ReplaceIcons()
    {
       var p = $(location).attr("pathname");
       var listUrl = p.replace(p.substr(p.lastIndexOf('/') + 1),'');
        $(".ms-vb-icon img").each(function() {
           var alt = $(this).attr('alt').split("_")[0];
            alt = listUrl + "/DispForm.aspx?ID=" + alt + "&Source=" + encodeURIComponent(window.location.href);  
           var a = $('<a/>').attr('href', alt);
            $(this).wrap(a);
        });
    }
    $(document).ready(function() {
         var defaultExpCollGroupMethod = ExpCollGroup; 
         ExpCollGroup = function() {  
               defaultExpCollGroupMethod.apply(this, arguments);
               setTimeout(ReplaceIcons,2000);
         };
         ReplaceIcons();
    });
    </script>

    Friday, August 15, 2014 1:43 AM
  • One more addition... This will do the same as above, but have the DispForm.aspx show in a pop up window instead of redirecting the browser to another page.

    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
    </script>
    <script type="text/javascript">
    function ReplaceIcons()
    {
       var p = $(location).attr("pathname");
       var listUrl = p.replace(p.substr(p.lastIndexOf('/') + 1),'');
        $(".ms-vb-icon img").each(function() {
           var alt = $(this).attr('alt').split("_")[0];
            alt = listUrl + "/DispForm.aspx?ID=" + alt + "&Source=" + encodeURIComponent(window.location.href);  
           var a = $('<a/>').attr('href', alt).attr('onclick',"javascript:OpenPopUpPage('" + alt + "',RefreshPage);return false;");
           $(this).wrap(a);
        });
    }
    $(document).ready(function() {
         var defaultExpCollGroupMethod = ExpCollGroup; 
         ExpCollGroup = function() {  
               defaultExpCollGroupMethod.apply(this, arguments);
               setTimeout(ReplaceIcons,2000);
         };
         ReplaceIcons();
    });
    </script>

    Friday, August 15, 2014 6:50 PM