Answered Truncate Multiline of text Javascript Sharepoint 2010

  • 21 มิถุนายน 2555 12:19
     
      มีโค้ด

    Hello All,


    I am following the below article to truncate the text in multiline of text column(plain text not rich text)(SHAREPOINT 2010)

    http://techtrainingnotes.blogspot.com/2010/12/sharepoint-how-to-truncate-multiline.html

    But I am not getting the more link option.somebody help me

    Following is the code

    <script>	
    var SummaryName = "Reports " ;
    var ColumnWithDropDown = 0;  //first column is 0
    var ColumnWithLongText = 1;
    var CharactersToShow   = 50;
    var isEnhancedRichText = true;
    
    var tables = document.getElementsByTagName("TABLE");
    for (var i=0;i<tables.length;i++)
    {
      if ( tables[i].summary == SummaryName )
      {
        var rows = tables[i].getElementsByTagName("TR");
        for (var j=1;j<rows.length;j++)
        {
          if (rows[j].childNodes.length > 2)
          {
            if ( rows[j].childNodes[ColumnWithDropDown ] == "[object Text]") 
              continue; // fix for FireFox
    
            var href = rows[j].childNodes[ColumnWithDropDown ].getElementsByTagName("A")[0].href
            if (href.toLowerCase().indexOf("dispform.aspx") == -1 && href.toLowerCase().indexOf("listid=") == -1  )
            {
    
              var docID = rows[j].childNodes[ColumnWithDropDown].childNodes[0].id
    
              // if not "dispform.aspx" then must be a library or links list
              // if "listid=" then must be a task list in 2010
              var parts = href.split("/");
              parts[parts.length-1] = "forms/DispForm.aspx?ID=" + docID;
              href = parts.join("/");
            }
    
    
            var theNode;
            if (isEnhancedRichText)
            {
              theNode = rows[j].childNodes[ColumnWithLongText].childNodes[0].childNodes[0];
            }
            else
            {
              theNode = rows[j].childNodes[ColumnWithLongText].childNodes[0];
            }
            if (theNode.innerHTML.length>CharactersToShow)
            {
              if (document.all)  // IE
                theNode.innerHTML = theNode.innerText.substring(0,CharactersToShow) 
                + "... <a href='" + href + "'><i>More</i></a>"
              else // FireFox
                try {
                theNode.innerHTML = theNode.textContent.substring(0,CharactersToShow) 
                + "... <a href='" + href + "'><i>More</i></a>"
                } catch (e) {}
            }
          }
        }
        
        break; // no need to check the other tables
      }
    }
    
    </script>

    Like Cricket







    • ย้ายโดย Lhan HanModerator 22 มิถุนายน 2555 1:52 sp2010 (From:SharePoint - General Question and Answers and Discussion (pre-SharePoint 2010))
    • เปลี่ยนแปลงประเภท spguy2012 22 มิถุนายน 2555 5:33
    • แก้ไขโดย spguy2012 22 มิถุนายน 2555 9:03
    •  

ตอบทั้งหมด

  • 22 มิถุนายน 2555 6:53
     
     
    somebody help me plz

    Like Cricket

  • 22 มิถุนายน 2555 7:06
     
     
    The answer is easy: you're not allowed to add scripts to the standard metadata columns as this would open up SharePoint to all kinds of script injection attacks (and everybody would start complaining how unsafe SharePoint is). The content editor web part does allow you to place JavaScript in it, or you can develop a custom field type (CFT) that does allow it ( http://msdn.microsoft.com/en-us/library/ms446361.aspx ), but remember your solution will become considerably less safe because of it.

    Kind regards,
    Margriet Bruggeman

    Lois & Clark IT Services
    web site: http://www.loisandclark.eu
    blog: http://www.sharepointdragons.com

  • 22 มิถุนายน 2555 7:10
     
     
    So,you mean to drop me this functionality using CEWP in SharePoint ?

    Like Cricket

  • 22 มิถุนายน 2555 7:14
     
     
    If that's an option for you yes, but since you wanted to add this for every column for every list item, I suspect it's not an option for you. In which case, you may have to build the custom CFT i was talking about.

    Kind regards,
    Margriet Bruggeman

    Lois & Clark IT Services
    web site: http://www.loisandclark.eu
    blog: http://www.sharepointdragons.com

  • 22 มิถุนายน 2555 8:59
     
     

    That is fine.

    Thanks for the reply


    Like Cricket

  • 22 มิถุนายน 2555 10:24
    ผู้ดูแล
     
     

    Hi Spguy2012,

    The code looks well. The things need to be checked in my mind are:
    var ColumnWithDropDown
    var ColumnWithLongText

    In the code, ColumnWithDropDown is 0, it means it is the first column. By default, in a SharePoint 2010 library or list, the "Title" column is in the third column(First column: checkbox; Second column: Attachment). So, please ensure the column indexes are correct for these two columns.

    If it is a list, the following code must be replaced.
    parts[parts.length-1] = "forms/DispForm.aspx?ID=" + docID;
    to
    parts[parts.length-1] = "listform.aspx?ListId=" + docID;

    Thanks,
    Jinchun Chen


    Jinchun Chen
    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 AT microsoft.com(Please replace AT with @)

  • 22 มิถุนายน 2555 10:38
     
      มีโค้ด

    Hi Chen,

    Thanks for the reply

    I made changes,but I am getting like

    'rows[...].childNodes[...].childNodes.0.childNodes' is null or not an object




    Like Cricket

  • 22 มิถุนายน 2555 10:41
    ผู้ดูแล
     
     

    Could you please send me the HTML of your table? spforumdata@microsoft.com


    Jinchun Chen
    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 AT microsoft.com(Please replace AT with @)

  • 22 มิถุนายน 2555 10:42
    ผู้ดูแล
     
     

    Also, could you please help to answer questions?

    1. Is the text turncated?
    2. Is the characters "..." being shown?

    Jinchun Chen
    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 AT microsoft.com(Please replace AT with @)

  • 22 มิถุนายน 2555 10:57
     
     

    Chen ,

    Mail has been sent to the respective email id

    Please check it out once


    Like Cricket

  • 22 มิถุนายน 2555 11:05
    ผู้ดูแล
     
     คำตอบ

    Hi,

    Please make changes to the following code:

    var ColumnWithDropDown = 2;  //first column is 0
    var ColumnWithLongText = 3;
    var CharactersToShow   = 50;
    var isEnhancedRichText = false;

    Thanks,
    Jinchun Chen


    Jinchun Chen
    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 AT microsoft.com(Please replace AT with @)

    • ทำเครื่องหมายเป็นคำตอบโดย spguy2012 23 มิถุนายน 2555 16:49
    •  
  • 22 มิถุนายน 2555 11:16
     
     

    Hi Chen,

    Now its fine

    Thank you so much for that.

    But the link is redirecting to some other page ,Instead I want to expand it on the same page.Is it doable?


    Like Cricket

    • ทำเครื่องหมายเป็นคำตอบโดย spguy2012 22 มิถุนายน 2555 11:32
    • ยกเลิกการทำเครื่องหมายเป็นคำตอบโดย spguy2012 23 มิถุนายน 2555 16:49
    •  
  • 22 มิถุนายน 2555 11:28
    ผู้ดูแล
     
     

    Hi Like,

    The link is the display form of the item by default: http://mysite.com/myteam/myname/_layouts/listform.aspx?PageType=4&amp;ListId={7F76406B-95EA-4E79-A219-3AF03F24A4B1}&amp;ID=2&amp;ContentTypeID=0x010016B6B80877AECF489996EFF41A05FD5F

    We can use window.open to open it from a new window:

    "... <a href=javascript:window.open('" + href + "')><i>More</i></a>"

    If we want to expand it from the same page, more code is required.

    Thanks,
    Jinchun Chen


    Jinchun Chen
    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 AT microsoft.com(Please replace AT with @)

  • 22 มิถุนายน 2555 11:31
     
     

    Thanks for the responses

    Could you please give me some guidance to write the code to expand it on the same page


    Like Cricket