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 ...
随机推荐
- Android 开源项目分类汇总
Android 开源项目分类汇总 Android 开源项目第一篇——个性化控件(View)篇 包括ListView.ActionBar.Menu.ViewPager.Gallery.GridView ...
- 图解win7中IIS7.0的安装及配置ASP环境
控制面板中“程序”的位置 “程序”中“打开或关闭Windows功能”的位置 如图,安装IIS7时需要选择要使用的功能模块 IIS7安装完成之后可以在开始菜单的所有程序中看到“管理工具”,其中有一个“I ...
- oracle生成.net的guid方法;
最近在做一个T1的.NET项目,数据库oracle的时候,遇到一个问题..NET里面的某个数据库表类的某个字段是guid类型.但是用oracle生成的guid.跟.NET的guid 无法识别.导致报错 ...
- Oracle数据库对象_视图
视图是一种非常重要的数据库对象,它的形式类似于普通表,我们可以从视图中查询数据. 实际上它是建立在表上的一种虚表,在视图中并不存储真正的数据,而是仅仅保存一条SELECT语句,对视图的访问将被转化为对 ...
- OC9_代理正向传值
// // ProtectedDeleagate.h // OC9_代理正向传值 // // Created by zhangxueming on 15/6/24. // Copyright (c) ...
- webpShere中数据库集群url的设置
数据源配置的URL如下: jdbc:oracle:thin:@(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 10 ...
- JAVA:IO流——File类
1.掌握File 类的作用 2.可以使用File 类中的方法对文件进行操作 所有的 io 操作都保存在 java.io 包中. 构造方法:public File (String pathname) 直 ...
- echarts标准饼图(一)——基本配置demo
echarts标准饼图解读共分为四部分, 一.基本配置demo 二.标题(title)配置 三.提示框(tooltip)配置 四.图例(legend)配置 五.系列列表(series )配置 下面是一 ...
- sort()的多种用法
sort() 方法用于对数组的元素进行排序. 一.默认情况 在默认情况下, sort() 方法按升序排列数组项.为了实现排序, sort() 方法会调用每个数组项的 toString() 转型方法, ...
- 九款酷炫基于jquery实现的应用及源码
1.HTML5 Loading动画加载 五彩的圆环Loading 今天我们要分享一款基于HTML5的Loading加载动画特效,这款HTML5加载动画是一个五彩的圆环,圆环不停地转动从而体现加载正在进 ...