SharePoint 优化显示WebParts
在开发sharepoint中,经常遇到需要自定义显示列表中的一部分作为导航的内容, 如公告栏,新闻链接,最新动态等....
我们通常需要显示一个列表的标题,并且限制字符长度, 外加一些条件,如按创建的时间倒序这样来显示最新的动态, 显示的时间也需要转换格式等...
那我们来看看原始的列表如下图:

修改后的效果:
接下来我们用SPD打开这个站点,在sitepages里面新建一个页面, 命名为allexception, 这是个空白的页面, 然后点击插入显示表单
我们需要显示显示多少行,找到<asp:Parameter Name="MaximumRows" DefaultValue="5"/> 这样我们就让行数限制在5行,另外我们在<xsl:variable name="RowLimit" select="5" />也修改成5
我们还需要显示根据标题的长度 比喻小于18个字符的全部显示,大于18个字符的显示其中的一部分外加省略号..
另外根据条件,如Status的Approved显示绿色,Denied显示为红色.
如下是代码:
<table border="" cellspacing="" width="100%">
<tr>
<td width="75%" class="ms-vb">
<a target="_blank" title="{@Title}">
<xsl:attribute name="href">http://liangji27/sites/charlie/Lists/Excemption%20Request/DispForm.aspx?ID=<xsl:value-of select="@ID"></xsl:value-of></xsl:attribute>
<xsl:if test="string-length(@Title)<=18">
<xsl:if test="@Status='Approved'">
<font color="#7FFF00"><xsl:value-of select="@Title" /></font>
</xsl:if>
<xsl:if test="not(@Status='Approved')">
<font color="#FF0000"><xsl:value-of select="@Title" /></font>
</xsl:if>
</xsl:if>
<xsl:if test="string-length(@Title)>18">
<xsl:if test="@Status='Approved'">
<font color="#7FFF00"><xsl:value-of select="substring(string(@Title),1,18)" />...</font>
</xsl:if>
<xsl:if test="not(@Status='Approved')">
<font color="#FF0000"><xsl:value-of select="substring(string(@Title),1,18)" />...</font>
</xsl:if>
</xsl:if>
</a>
</td>
<td width="25%" class="ms-vb">
<xsl:value-of select="substring(string(@Created_x0020_Date),4,10)"></xsl:value-of>
</td>
</tr>
</table>
此处是将创建时间格式截取年月日:
<xsl:value-of select="substring(string(@Created_x0020_Date),4,10)"></xsl:value-of>
以上是全部代码:
<WebPartPages:DataFormWebPart runat="server" IsIncluded="True" AsyncRefresh="True" FrameType="None" NoDefaultStyle="TRUE" ViewFlag="8" Title="Exception Request" PageType="PAGE_NORMALVIEW" ListName="{93CF56B6-AD1C-43EB-A007-0EB087CBBD27}" Default="FALSE" DisplayName="Exception Request" __markuptype="vsattributemarkup" __WebPartId="{8516696D-C2F0-4A7A-944E-15C0553F2767}" id="g_8516696d_c2f0_4a7a_944e_15c0553f2767" pagesize="1" __AllowXSLTEditing="true" WebPart="true" Height="" Width="">
<DataSources>
<SharePoint:SPDataSource runat="server" DataSourceMode="List" UseInternalName="true" UseServerDataFormat="true" selectcommand="<View></View>" id="Exception_x0020_Request2"><SelectParameters><WebPartPages:DataFormParameter Name="ListID" ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="{93CF56B6-AD1C-43EB-A007-0EB087CBBD27}"/><asp:Parameter Name="StartRowIndex" DefaultValue="0"/><asp:Parameter Name="nextpagedata" DefaultValue="0"/><asp:Parameter Name="MaximumRows" DefaultValue="5"/>
</SelectParameters><DeleteParameters><WebPartPages:DataFormParameter Name="ListID" ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="{93CF56B6-AD1C-43EB-A007-0EB087CBBD27}"/>
</DeleteParameters><UpdateParameters><WebPartPages:DataFormParameter Name="ListID" ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="{93CF56B6-AD1C-43EB-A007-0EB087CBBD27}"/>
</UpdateParameters><InsertParameters><WebPartPages:DataFormParameter Name="ListID" ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="{93CF56B6-AD1C-43EB-A007-0EB087CBBD27}"/></InsertParameters>
</SharePoint:SPDataSource>
</DataSources>
<ParameterBindings>
<ParameterBinding Name="ListID" Location="None" DefaultValue="{93CF56B6-AD1C-43EB-A007-0EB087CBBD27}"/>
<ParameterBinding Name="dvt_apos" Location="Postback;Connection"/>
<ParameterBinding Name="ManualRefresh" Location="WPProperty[ManualRefresh]"/>
<ParameterBinding Name="UserID" Location="CAMLVariable" DefaultValue="CurrentUserName"/>
<ParameterBinding Name="Today" Location="CAMLVariable" DefaultValue="CurrentDate"/>
<ParameterBinding Name="dvt_startposition" Location="Postback" DefaultValue=""/>
<ParameterBinding Name="dvt_firstrow" Location="Postback;Connection"/>
<ParameterBinding Name="dvt_nextpagedata" Location="Postback;Connection"/>
<ParameterBinding Name="dvt_1_form_editkey" Location="Postback;Connection"/>
</ParameterBindings>
<datafields>@Title,Title;@Approved,Approved;@Status,Status;@ID,ID;@ContentType,Content Type;@Modified,Modified;@Created,Created;@Author,Created By;@Editor,Modified By;@_UIVersionString,Version;@Attachments,Attachments;@File_x0020_Type,File Type;@FileLeafRef,Name (for use in forms);@FileDirRef,Path;@FSObjType,Item Type;@_HasCopyDestinations,Has Copy Destinations;@_CopySource,Copy Source;@ContentTypeId,Content Type ID;@_ModerationStatus,Approval Status;@_UIVersion,UI Version;@Created_x0020_Date,Created;@FileRef,URL Path;@ItemChildCount,Item Child Count;@FolderChildCount,Folder Child Count;</datafields>
<XSL>
<xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal">
<xsl:output method="html" indent="no"/>
<xsl:decimal-format NaN=""/>
<xsl:param name="dvt_apos">'</xsl:param>
<xsl:param name="ManualRefresh"></xsl:param>
<xsl:param name="dvt_firstrow">1</xsl:param>
<xsl:param name="dvt_nextpagedata" />
<xsl:param name="dvt_1_form_editkey" />
<xsl:variable name="dvt_1_automode">1</xsl:variable>
<xsl:template match="/" xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:SharePoint="Microsoft.SharePoint.WebControls">
<xsl:choose>
<xsl:when test="($ManualRefresh = 'True')">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td valign="top">
<xsl:call-template name="dvt_1"/>
</td>
<td width="1%" class="ms-vb" valign="top">
<img src="/_layouts/images/staticrefresh.gif" id="ManualRefresh" border="0" onclick="javascript: {ddwrt:GenFireServerEvent('__cancel')}" alt="Click here to refresh the dataview."/>
</td>
</tr>
</table>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="dvt_1"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="dvt_1">
<xsl:variable name="dvt_StyleName">Table</xsl:variable>
<xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row"/>
<xsl:variable name="dvt_RowCount" select="count($Rows)"/>
<xsl:variable name="RowLimit" select="5" />
<xsl:variable name="FirstRow" select="$dvt_firstrow" />
<xsl:variable name="LastRow" select="$FirstRow + $dvt_RowCount - 1" />
<xsl:variable name="IsEmpty" select="$dvt_RowCount = 0" />
<xsl:variable name="dvt_IsEmpty" select="$dvt_RowCount = 0"/>
<xsl:choose>
<xsl:when test="$dvt_IsEmpty">
<xsl:call-template name="dvt_1.empty"/>
</xsl:when>
<xsl:otherwise>
<table border="0" width="100%">
<xsl:call-template name="dvt_1.body">
<xsl:with-param name="Rows" select="$Rows"/>
<xsl:with-param name="FirstRow" select="1" />
<xsl:with-param name="LastRow" select="$LastRow - $FirstRow + 1" />
</xsl:call-template>
</table>
</xsl:otherwise>
</xsl:choose>
<xsl:call-template name="dvt_1.commandfooter">
<xsl:with-param name="FirstRow" select="$FirstRow" />
<xsl:with-param name="LastRow" select="$LastRow" />
<xsl:with-param name="RowLimit" select="$RowLimit" />
<xsl:with-param name="dvt_RowCount" select="$dvt_RowCount" />
<xsl:with-param name="RealLastRow" select="number(ddwrt:NameChanged('',-100))" />
</xsl:call-template>
</xsl:template>
<xsl:template name="dvt_1.body">
<xsl:param name="Rows"/>
<xsl:param name="FirstRow" />
<xsl:param name="LastRow" />
<xsl:for-each select="$Rows">
<xsl:variable name="dvt_KeepItemsTogether" select="false()" />
<xsl:variable name="dvt_HideGroupDetail" select="false()" />
<xsl:if test="(position() >= $FirstRow and position() <= $LastRow) or $dvt_KeepItemsTogether">
<xsl:if test="not($dvt_HideGroupDetail)" ddwrt:cf_ignore="1">
<xsl:call-template name="dvt_1.rowview" />
<!--
<xsl:choose>
<xsl:when test="$dvt_1_form_editkey = ddwrt:EscapeDelims(string(@ID))">
</xsl:when>
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose>
-->
</xsl:if>
</xsl:if>
</xsl:for-each>
</xsl:template>
<xsl:template name="dvt_1.rowview">
<tr>
<td>
<table border="0" cellspacing="0" width="100%">
<tr>
<td width="75%" class="ms-vb">
<a target="_blank" title="{@Title}">
<xsl:attribute name="href">http://liangji27/sites/charlie/Lists/Excemption%20Request/DispForm.aspx?ID=<xsl:value-of select="@ID"></xsl:value-of></xsl:attribute>
<xsl:if test="string-length(@Title)<=18">
<xsl:if test="@Status='Approved'">
<font color="#7FFF00"><xsl:value-of select="@Title" /></font>
</xsl:if>
<xsl:if test="not(@Status='Approved')">
<font color="#FF0000"><xsl:value-of select="@Title" /></font>
</xsl:if>
</xsl:if>
<xsl:if test="string-length(@Title)>18">
<xsl:if test="@Status='Approved'">
<font color="#7FFF00"><xsl:value-of select="substring(string(@Title),1,18)" />...</font>
</xsl:if>
<xsl:if test="not(@Status='Approved')">
<font color="#FF0000"><xsl:value-of select="substring(string(@Title),1,18)" />...</font>
</xsl:if>
</xsl:if>
</a>
</td>
<td width="25%" class="ms-vb">
<xsl:value-of select="substring(string(@Created_x0020_Date),4,10)"></xsl:value-of>
</td>
</tr>
</table>
</td>
</tr>
</xsl:template>
<xsl:template name="dvt_1.empty">
<xsl:variable name="dvt_ViewEmptyText">There are no items to show in this view.</xsl:variable>
<table border="0" width="100%">
<tr>
<td class="ms-vb">
<xsl:value-of select="$dvt_ViewEmptyText"/>
</td>
</tr>
</table>
</xsl:template>
<xsl:template name="dvt_1.commandfooter">
<xsl:param name="FirstRow" />
<xsl:param name="LastRow" />
<xsl:param name="RowLimit" />
<xsl:param name="dvt_RowCount" />
<xsl:param name="RealLastRow" />
</xsl:template>
</xsl:stylesheet> </XSL>
</WebPartPages:DataFormWebPart>
SharePoint 优化显示WebParts的更多相关文章
- 2022-09-11-Typecho_RSS优化显示全文
layout: post cid: 26 title: Typecho RSS优化显示全文 slug: 26 date: 2022/09/11 15:53:38 updated: 2022/09/11 ...
- sharepoint 2010 显示和隐藏Ribbon区域条
在sharepoint 2010的页面中,我们在页面的最上方,有一条深灰色的Ribbon工具栏,如下图,这里可以通过下面的脚本,做一些脚本,来控制它的隐藏和显示. 最后把这些脚本,放在v4.maste ...
- 前端性能优化之优化图片 && 优化显示图片
前端图片优化一直以来都是热门话题,从需求上来看,很多站点往往是图片体积大于代码体积, 图片请求多余代码文件请求, 给前端的性能带来了很大的困扰,那么应该如何解决呢? 零. 认识图片 我们通常使用的图片 ...
- sql server 数据库优化--显示执行计划
刚开始用SQL Server的时候,我没有用显示执行计划来对查询进行分析.我曾经一直认为我递交的SQL查询都是最优的,而忽略了查询性能究竟如何,从而对“执行计划”重视不够.在我职业初期,我只要能获 ...
- SharePoint 2013 显示“以其他用户身份登录”菜单项
最近在SharePoint 2013的网站上发现,没有看到有切换不同用户登录的入口,在SharePoint 2010中是存在这样的菜单项能够很方便的进行用户切换的,不知道为什么,SharePoint ...
- php时间区间,优化显示
<?php /** * 类似微信的时间显示 * 规则是:今天的,显示几秒前,几分钟前,几小时前,昨天的显示昨天 上午 XX:XX * 再往前,本周的,显示周几+时间,再往前,本年的,显示月日+时 ...
- 2016/3/26 weixin 头像 昵称 网页优化显示 缺表中数据 只有代码 无显示效果
weixin.php <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...
- 优化移动设备上SharePoint 2013网站
优化移动设备上SharePoint 2013网站 本文由SPFarmer翻译自Waldek Mastykarz的文章 移动市场在持续的增长.在不远的将来,使用移动设备浏览站点将会超过电脑.为了保证用户 ...
- SharePoint 2013技巧分享系列 - Active Directory同步显示用户照片
为了保持通讯信息的一致性,需要设置SharePoint,Exchange, Lync等信息同步更新显示,例如,员工头像信息. 本文介绍如何在SharePoint 2013中同步显示Active Dir ...
随机推荐
- html&css静态页面
状态不好,整晚未眠. 想着敲点代码,遇着复杂的又自己生气,所以就敲了博客园的,总是很纠结"哪样的文字算标题算段落或要用span""什么时候用div比较好"&qu ...
- Android TintResources Leak
在使用Android WebView的时候,可能会造成Activity的内存泄漏,这个是Android的Bug,目前发现在WebView内部在使用TintResources时会发生内存泄漏,但是在ap ...
- UI3_CustomUITableViewCell
// AppDelegate.m // UI3_CustomUITableViewCell // // Created by zhangxueming on 15/7/15. // Copyright ...
- Linux开机启动程序详解[转]
Linux开机启动程序详解 我们假设大家已经熟悉其它操作系统的引导过程,了解硬件的自检引导步骤,就只从Linux操作系统的引导加载程序(对个人电脑而言通常是LILO)开始,介绍Linux开机引导的步骤 ...
- 8套迷人精致的CSS3 3D按钮动画
1.纯CSS3 3D按钮 按钮酷似牛奶般剔透 CSS3按钮一般都可以设计的非常漂亮,利用投影.渐变等CSS3属性特效可以把按钮渲染的十分动感.今天分享的这款CSS3按钮外观非常特别,它看上去酷似晶莹剔 ...
- win8.1环境下硬盘安装centos6.5双系统
作为一名软件工程师或是相关行业的从业人员,经常会用到linux系统,这里为大家介绍的安装linux的方案是在原有win环境下安装linux双系统,两个系统选择分别为win8.1 和centos6.5. ...
- js设计模式(7)---装饰者模式
0.前言 下午做事效率很低,无精打采的,整个脑子就跟浆糊一样,看看时间一点点流去,心中只能无可奈何,哎,码农的激情难道就这么容易熄灭吗? 1.该模式的使用情况 假如我们想给对象增加功能,但是又不想修改 ...
- IOS_修改项目模板
1. /Applications/Xcode.app/Contents/Developer/Library/Xcode/Templates/File\ Templates/Source/Cocoa\ ...
- oracle 文件导出
$ cat me.sqlset echo offset term offset line 1000 pages 0set feedback offset heading offset trimspoo ...
- 用cookie实现localstorage功能
在项目中需要利用到html5的localstorage.但在利用这个属性的时候却发现无法达到预定目标.经过不断的检查及排除,最后发现原因所在: 项目中使用的浏览器是支持localstorage的,但是 ...