SharePoint 优化显示WebParts

 

在开发sharepoint中,经常遇到需要自定义显示列表中的一部分作为导航的内容, 如公告栏,新闻链接,最新动态等....

 

我们通常需要显示一个列表的标题,并且限制字符长度, 外加一些条件,如按创建的时间倒序这样来显示最新的动态, 显示的时间也需要转换格式等...

 

那我们来看看原始的列表如下图:

SharePoint 优化显示WebParts_第1张图片

 

修改后的效果:
SharePoint 优化显示WebParts_第2张图片

接下来我们用SPD打开这个站点,在sitepages里面新建一个页面, 命名为allexception, 这是个空白的页面, 然后点击插入显示表单

我们需要显示显示多少行,找到Name="MaximumRows" DefaultValue="5"/> 这样我们就让行数限制在5行,另外我们在name="RowLimit" select="5" />也修改成5

我们还需要显示根据标题的长度 比喻小于18个字符的全部显示,大于18个字符的显示其中的一部分外加省略号..
另外根据条件,如Status的Approved显示绿色,Denied显示为红色.
如下是代码:

 

此处是将创建时间格式截取年月日:

 

以上是全部代码:

    <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">1xsl:param>
    <xsl:param name="dvt_nextpagedata" />
    <xsl:param name="dvt_1_form_editkey" />
    <xsl:variable name="dvt_1_automode">1xsl: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">Tablexsl: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: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>

 

转载于:https://www.cnblogs.com/fengqingyangNo1/p/Sharepoint.html

你可能感兴趣的:(ui,javascript,runtime,ViewUI)