none
JQuery/JavaScript to achieve this in SharePoint?

    Pergunta

  • Hi all,

    I will appreciate if someone can give me the JQuery or JavaScript as I am a newbie to these.

    My SharePoint page has List View Web Part (LVWP), and clicking on folders in a list stays on the page, just displaying the contents of the folder in the LVWP. While I need that clicking on the folder name should take the user to the folder and should not stay on the same page.

    Help is appreciated.


    • Editado ran009 sexta-feira, 8 de junho de 2012 18:09
    sexta-feira, 8 de junho de 2012 17:11

Respostas

  • In the code you pasted, one of the lines is:


    <A TABINDEX="-1" HREF="{ddwrt:GetVar('UnencodedFilterLink')}" onclick="javascript:EnterFolder('{ddwrt:GetVar('UnencodedFilterLink')}');javascript:return false;">
    <IMG BORDER="0" alt="Folder: {@FileLeafRef}" title="Folder: {@FileLeafRef}" SRC="/_layouts/images/folder.gif" />
    </A>

    So, it's a link that has both an href and an onclick (and a tabindex). The contents of the a tag that is displayed to the user is an <img> tag. So, you'll need to change the href, get rid of the onclick, and leave the img as-is. With XSL, you can't just specify a raw value easily for the HREF, you'll have to add it in as an xsl:attribute, like what was done earlier.

    That leaves you with:

    <A tabindex="-1">
      <xsl:attribute  name="href">
      <xsl:value-of select="@FileRef"/></xsl:attribute>
      <IMG ... />
    </A>






    Mike G.

    • Marcado como Resposta ran009 sexta-feira, 15 de junho de 2012 20:40
    sexta-feira, 15 de junho de 2012 17:23

Todas as Respostas

  • You would need to look into the XSL of the List View Wep Part to modify the hyperlink created by the XSLT to open a new window.

    That said, I'm not sure if there is a specific XSL template applied to folder types, otherwise you would possibly apply this change to all items in the list.

    sexta-feira, 8 de junho de 2012 21:19
  • That will be a bit tricky, as even if you modify the href of the <a> tag, it's being modified by JS. You could disable the script, but I haven't tested that and don't know what that would do to the UI functionality. Perhaps instead you could remove the column that has the folder and replace it with a new column that has the following:

    <td>
      <a>          
        <xsl:attribute  name="href">
          <xsl:value-of select="@FileRef"/></xsl:attribute>
          <xsl:value-of select="@FileLeafRef.Name"/>
      </a>                  
    </td>

    The above will display the folder name with a link that points to the actual folder within the library.



    Mike G.

    sábado, 9 de junho de 2012 01:54
  • Thanks Mike,

    This seems promising. From SharePoint Designer, I have converted the LVWP to XSLT. Now how to figure out where exactly to make the change you mention please?

    :-)

    quinta-feira, 14 de junho de 2012 19:24
  • Sorry, the provided xsl will have to change a little based on going through the specific steps. From the beginning:

    1. on a new page, add an xsltlistviewwebpart for the desired library

    2. if desired, click add/remove columns, and get rid of the existing "name" column that has the existing link to the subfolders

    3. r-click on an existing column, and insert a new column in the middle of the table somewhere

    4. switch to split view (button at the bottom of the screen), and click on the empty table cell. In the code view, you should now have the almost empty td highlighted. (if you have trouble seeing it, the dumb trick is to type "abcdefg" into the blank cell in the gui, and then find that text in the code view)

    5. paste into the td:

    <a>          
        <xsl:attribute  name="href">
          <xsl:value-of select="$thisNode/@FileRef"/></xsl:attribute>
          <xsl:value-of select="$thisNode/@FileLeafRef.Name"/>
      </a>

      


    Mike G.

    quinta-feira, 14 de junho de 2012 20:16
  • Thanks Mike,

    I did exactly like above (dumb trick was useful), and I get this error

    "A reference to variable or parameter 'thisNode' cannot be resolved. The variable or parameter may not be defined, or it may not be in scope."

    Any clues?

    Thanks :-)

    quinta-feira, 14 de junho de 2012 20:35
  • Could you paste in the closest <xsl:template line that should be somewhere above the td where you pasted in the code. Also, the few lines right below it could be helpful as well.

    Mike G.

    sexta-feira, 15 de junho de 2012 03:04


  • 					<!--Type--><TH nowrap="" scope="col" class="ms-vh2">
    					<xsl:call-template name="dvt.headerfield" ddwrt:atomic="1" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime">
    						<xsl:with-param name="fieldname">@DocIcon</xsl:with-param>
    						<xsl:with-param name="fieldtitle">Type</xsl:with-param>
    						<xsl:with-param name="displayname">Type</xsl:with-param>
    						<xsl:with-param name="sortable">0</xsl:with-param>
    						<xsl:with-param name="fieldtype">Text</xsl:with-param>
    					</xsl:call-template>
    					</TH>
    					<!--LinkFilename-->
    					<!--Name--><TH nowrap="" scope="col" class="ms-vh2">
    						<xsl:call-template name="dvt.headerfield" ddwrt:atomic="1" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime">
    							<xsl:with-param name="fieldname">@LinkFilename</xsl:with-param>
    							<xsl:with-param name="fieldtitle">Name</xsl:with-param>
    							<xsl:with-param name="displayname">Name</xsl:with-param>
    							<xsl:with-param name="sortable">0</xsl:with-param>
    							<xsl:with-param name="fieldtype">Text</xsl:with-param>
    						</xsl:call-template>
    					</TH>
    					<!--Modified-->
    					<!--Modified--><TH nowrap="" scope="col" class="ms-vh2">ddddddd
    						<xsl:text xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" ddwrt:nbsp-preserve="yes" disable-output-escaping="yes">&amp;nbsp;</xsl:text>
    						dd</TH><TH nowrap="" scope="col" class="ms-vh2">
    						<xsl:call-template name="dvt.headerfield" ddwrt:atomic="1" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime">
    							<xsl:with-param name="fieldname">@Modified</xsl:with-param>
    							<xsl:with-param name="fieldtitle">Modified</xsl:with-param>
    							<xsl:with-param name="displayname">Modified</xsl:with-param>
    							<xsl:with-param name="sortable">1</xsl:with-param>
    							<xsl:with-param name="fieldtype">x:dateTime</xsl:with-param>
    						</xsl:call-template>
    					</TH>

    I tried inserting dddddd in a new column and have pasted the dddddd table cell and the cells just above and bellow that. Please let me know if you need anything else. :-)

    Thanks Mike
    • Editado ran009 sexta-feira, 15 de junho de 2012 03:56
    sexta-feira, 15 de junho de 2012 03:47
  • SharePoint 07? Sorry, I didn't pick up on that before:

    <a>
      <xsl:attribute  name="href">
      <xsl:value-of select="@FileRef"/></xsl:attribute>
      <xsl:value-of select="@FileLeafRef"/>
    </a>   

    But, the above needs to go in the "detail" row, not the header row. (I see that next to your "dddddd" is "<TH ...>". It should be in a "<TD...>"

    In the gui, click in the blank cell in the table in the row below (a row where the other fields have data, not labels(if there aren't any other rows, go to the library, add some folders, and then come back and refresh the screen)).


    Mike G.

    sexta-feira, 15 de junho de 2012 13:00
  • Great! It worked. You already answered my question, still taking a chance for this:

    Just left to this column (we just changed), is another column that shows the Type i.e. icons for folders/files. When user clicks on Folder icons; can we do exactly the same thing for this icon as well, so when user clicks on the Folder icon he is taken to the actual folder. Exactly like we just did for Name field?

    			<!--DocIcon-->
    			<!--Type-->
    			<TD Class="{$IDA5323W}">
    				<xsl:variable name="FieldIDAATNHY">
    					<xsl:choose>
    						<xsl:when test="@IsCheckedoutToLocal=''"></xsl:when>
    						<xsl:otherwise><A HREF="{ddwrt:URLLookup('', 'IsCheckedoutToLocal', string(@ID))}"><xsl:value-of select="@IsCheckedoutToLocal" /></A></xsl:otherwise>
    					</xsl:choose>
    				</xsl:variable>
    				<xsl:choose>
    					<xsl:when test="@FSObjType='1'">
    						<xsl:choose>
    							<xsl:when test="ddwrt:GetVar('RecursiveView')='1'"><IMG BORDER="0" alt="Folder: {@FileLeafRef}" SRC="/_layouts/images/folder.gif" /></xsl:when>
    							<xsl:otherwise>
    								<xsl:variable name="SetVarIDATONHY"><xsl:value-of select="$PagePath" />?RootFolder=<xsl:value-of select="@FileRef" />&amp;FolderCTID=<xsl:value-of select="@ContentTypeId" /></xsl:variable>
    								<xsl:value-of select="ddwrt:SetVar('UnencodedFilterLink', string($SetVarIDATONHY))" />
    								<A TABINDEX="-1" HREF="{ddwrt:GetVar('UnencodedFilterLink')}" onclick="javascript:EnterFolder('{ddwrt:GetVar('UnencodedFilterLink')}');javascript:return false;"><IMG BORDER="0" alt="Folder: {@FileLeafRef}" title="Folder: {@FileLeafRef}" SRC="/_layouts/images/folder.gif" /></A>
    							</xsl:otherwise>
    						</xsl:choose>
    					</xsl:when>
    					<xsl:otherwise><A TABINDEX="-1" HREF="{@FileRef}" onclick="return DispEx(this,event,'','','','','{ddwrt:ListProperty(&quot;DefaultItemOpen&quot;)}','{ddwrt:MapToControl(&quot;&quot;, string())}','{@HTML_x0020_File_x0020_Type}','','{ddwrt:GetUserID('CheckoutUser')}','{$Userid}','{ddwrt:ListProperty(&quot;ForceCheckout&quot;)}','{$FieldIDAATNHY}','{ddwrt:CurrentRights()}')">
    						<xsl:choose>
    							<xsl:when test="@CheckoutUser=''"><IMG BORDER="0" ALT="{@FileLeafRef}" title="{@FileLeafRef}" SRC="/_layouts/images/{ddwrt:MapToIcon(string(@HTML_x0020_File_x0020_Type),string(@File_x0020_Type))}" /></xsl:when>
    							<xsl:otherwise><IMG BORDER="0" ALT="{@FileLeafRef}
    Checked Out To: {@CheckoutUser}" title="{@FileLeafRef}
    Checked Out To: {@CheckoutUser}" SRC="/_layouts/images/{ddwrt:MapToIcon(string(@HTML_x0020_File_x0020_Type),string(@File_x0020_Type))}" /><img src="/_layouts/images/checkoutoverlay.gif" class="ms-vb-icon-overlay" alt="&lt;xsl:value-of select=&quot;@FileLeafRef&quot; /&gt;
    Checked Out To: ddwrt:UserLookup(string(@DocIcon), &quot;Title&quot;)&lt;" title="&lt;xsl:value-of select=&quot;@FileLeafRef&quot; /&gt;
    Checked Out To: ddwrt:UserLookup(string(@DocIcon), &quot;Title&quot;)" /></xsl:otherwise>
    						</xsl:choose>
    						</A></xsl:otherwise>
    				</xsl:choose>
    			</TD>
    			<!--LinkFilename-->
    			<!--Name-->
    			<!--Modified-->
    			<!--Modified-->
    			<TD Class="{$IDA5323W}">
    			<a>
      <xsl:attribute  name="href">
      <xsl:value-of select="@FileRef"/></xsl:attribute>
      <xsl:value-of select="@FileLeafRef"/>
    </a>
    			</TD>
    

    Bold text is the script we just changed, and above it where next change needs to be made.

    So sorry I pasted it in wrong forum and did not even mention this is MOSS 2007.

    In any case I will be marking your suggestion as answer :-)

    Thanks Mike, words cannot express my gratitude.

    sexta-feira, 15 de junho de 2012 16:26
  • In the code you pasted, one of the lines is:


    <A TABINDEX="-1" HREF="{ddwrt:GetVar('UnencodedFilterLink')}" onclick="javascript:EnterFolder('{ddwrt:GetVar('UnencodedFilterLink')}');javascript:return false;">
    <IMG BORDER="0" alt="Folder: {@FileLeafRef}" title="Folder: {@FileLeafRef}" SRC="/_layouts/images/folder.gif" />
    </A>

    So, it's a link that has both an href and an onclick (and a tabindex). The contents of the a tag that is displayed to the user is an <img> tag. So, you'll need to change the href, get rid of the onclick, and leave the img as-is. With XSL, you can't just specify a raw value easily for the HREF, you'll have to add it in as an xsl:attribute, like what was done earlier.

    That leaves you with:

    <A tabindex="-1">
      <xsl:attribute  name="href">
      <xsl:value-of select="@FileRef"/></xsl:attribute>
      <IMG ... />
    </A>






    Mike G.

    • Marcado como Resposta ran009 sexta-feira, 15 de junho de 2012 20:40
    sexta-feira, 15 de junho de 2012 17:23
  • Mike is a Legend!
    sexta-feira, 15 de junho de 2012 20:40