locked
Header filter date format RRS feed

  • Question

  • Hi all,

    does anybody know a way to set date format for dataview header filter? Here is a screenshot of what I have now:

    As you can see, the format is dd.mm.yyyy h:nn. I want to remove the time part and to have dd.mm.yyyy only. It is a common XSLT Data View. The header for this field is:

    <xsl:call-template name="dvt.headerfield" ddwrt:atomic="1" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime">
        <xsl:with-param name="fieldname">@Error_x0020_date</xsl:with-param>
        <xsl:with-param name="fieldtitle">Дата обнаружения</xsl:with-param>
        <xsl:with-param name="displayname">Error date</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>
    
    

    And the field itself is:

    <td class="ms-vb">
        <xsl:value-of select="ddwrt:FormatDate(string(@Error_x0020_date), 1049, 1)"/>
    </td>
    
    

    So in the field I can see the date in the way I want:

    But where should I set up date format for the header like I do for the field itself?

    Thanks in advance!


    Andrey V Artemyev | Saint-Petersburg, Russia
    Russian blog artemyev.biztoolbox.ru
    English blog enblog.biztoolbox.ru
    Wednesday, November 23, 2011 8:27 AM

All replies

  • You could always use a computed column field; set the Error_Date field to your computed column field, use data calculations to format the date to meet your requirements and choose the "Single line text" options to return your data as a string. Then finally include your new computed column into your target view and you should be set to go.

    Intro to data calculations: http://office.microsoft.com/en-us/windows-sharepoint-services-help/introduction-to-data-calculations-HA010121588.aspx


    Make sure you mark my reply as the answer if it had solved your request. Brandon M. Hunter MCTS - SharePoint 2010 Configuration
    Thursday, November 24, 2011 2:55 AM
  • Hi Brandon,

    why should I use a computed column when I already have a proper date format in the field? The problem in the filter values. I don't understand why there is "h:nn" part and where it can be changed.


    Andrey V Artemyev | Saint-Petersburg, Russia
    Russian blog artemyev.biztoolbox.ru
    English blog enblog.biztoolbox.ru
    Thursday, November 24, 2011 6:26 AM
  • Andrey,

    Can you try this?  http://www.stylusstudio.com/xsllist/200010/post90330.html

     

    Cheers,

    Jeff - MSFT

    Tuesday, November 29, 2011 12:33 AM
  • Hi Jeff,

    thanks for your reply. Maybe I misunderstand smth, but I can't see any reply in the thread your link goes to.


    Andrey V Artemyev | Saint-Petersburg, Russia
    Russian blog artemyev.biztoolbox.ru
    English blog enblog.biztoolbox.ru
    Tuesday, November 29, 2011 6:00 AM
  • Hi Andrey,

    My mistake.  I posted the wrong link earlier.  But I have also found that I misunderstood your question.  I just tried what you described in a new DataSheet view on one of my lists and the filter is formatted without the time.  I wondered if this is something specific to the Russian language pack?

    Tuesday, November 29, 2011 11:23 PM
  • Hi Jeff,

    I don't think there is Russian language pack influence. The only difference is that we use dd.mm.yyyy date format as a default one rather than mm.dd.yyyy or mm/dd/yyyy and 24 hours time format.

    If we are talking about a common "Created" SharePoint field, it shows filter values ok in a standard Sharepoint list:

    I can't try with a brand new XSLT DataView right now because I have some temporary troubles with SPD, but I'll try it ASAP after repairing and let you know whether the issue still appears.


    Andrey V Artemyev | Saint-Petersburg, Russia
    Russian blog artemyev.biztoolbox.ru
    English blog enblog.biztoolbox.ru
    Thursday, December 1, 2011 11:42 AM
  • I  had the same problem with filter. If I return date type from database, I get time stamp in the filter. If I format it to string using convert function, sort didn't work as it supposed to work with date, instead, it was sorting like string. So my solution was to have date format for sorting and string format for filter.

     The work around I did to get rid of time stamp in the filter is below.

    In the data source, in addition to date field, I also added another field with date format.

    Eg. DueDate is my date field which return date type, I added another field called FormattedDueDate which will return string type as shown below.

    CONVERT(VARCHAR(10), A.DueDate, 101) AS FormattedDueDate, A.DueDate

    In designer, I added this FormattedDueDate to the data source. In the header field, I have added another parameter name called "sortfieldname". So my source code change is

    orignal code:

    <xsl:call-template name="dvt.headerfield" ddwrt:atomic="1" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime">
           <xsl:with-param name="fieldname">@DueDate</xsl:with-param>
               <xsl:with-param name="fieldtitle">Due Date</xsl:with-param>
           <xsl:with-param name="displayname">Due Date</xsl:with-param>
           <xsl:with-param name="sortable">1</xsl:with-param>
           <xsl:with-param name="fieldtype">x:string</xsl:with-param>
          </xsl:call-template>

    Updated code:

    <xsl:call-template name="dvt.headerfield" ddwrt:atomic="1" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime">
           <xsl:with-param name="fieldname">@FormattedDueDate</xsl:with-param>
           <xsl:with-param name="sortfieldname">@DueDate</xsl:with-param>
           <xsl:with-param name="fieldtitle">Due Date</xsl:with-param>
           <xsl:with-param name="displayname">Due Date</xsl:with-param>
           <xsl:with-param name="sortable">1</xsl:with-param>
           <xsl:with-param name="fieldtype">x:string</xsl:with-param>
          </xsl:call-template>

    Now I will have to use the new sortfieldname variable in the sort functionality. For this I added sortfieldname in the param list and replaced "fieldname" with "sortfieldname" in the sortfield choose block.

    Orignal code:

    <xsl:template name="dvt.headerfield">
           <xsl:param name="fieldname" />
           <xsl:param name="fieldtitle" />
           <xsl:param name="displayname" />
           <xsl:param name="sortable">1</xsl:param>
           <xsl:param name="fieldtype">0</xsl:param>
           <xsl:choose>
            <xsl:when test="($dvt_adhocmode = 'sort' or $dvt_fieldsort = '1')and $sortable='1'">
             <xsl:variable name="sortfield">
              <xsl:choose>
               <xsl:when test="substring($fieldname, string-length($fieldname) - 5) = '(text)'">
           <xsl:value-of select="substring($fieldname, 1, string-length($fieldname) - 6)" />
          </xsl:when>
               <xsl:when test="substring($fieldname, 1, 1) = '@'">
           <xsl:value-of select="substring($fieldname, 2)" />
          </xsl:when>
               <xsl:otherwise>
           <xsl:value-of select="$fieldname" />
          </xsl:otherwise>
              </xsl:choose>
             </xsl:variable>

    Modified code:

    <xsl:template name="dvt.headerfield">
      <xsl:param name="fieldname" />
      <xsl:param name="sortfieldname" />
      <xsl:param name="fieldtitle" />
      <xsl:param name="displayname" />
      <xsl:param name="sortable">1</xsl:param>
      <xsl:param name="fieldtype">0</xsl:param>
      <xsl:choose>
       <xsl:when test="($dvt_adhocmode = 'sort' or $dvt_fieldsort = '1')and $sortable='1'">
        <xsl:variable name="sortfield">
         <xsl:choose>
          <xsl:when test="substring($sortfieldname, string-length($sortfieldname) - 5) = '(text)'">
           <xsl:value-of select="substring($sortfieldname, 1, string-length($sortfieldname) - 6)" />
          </xsl:when>
          <xsl:when test="substring($sortfieldname, 1, 1) = '@'">
           <xsl:value-of select="substring($sortfieldname, 2)" />
          </xsl:when>
          <xsl:otherwise>
           <xsl:value-of select="$sortfieldname" />
          </xsl:otherwise>
         </xsl:choose>
        </xsl:variable>

    Now I see old date without time in the filter and I also able to sort the field as date.

    Thanks

    Mahi

    Wednesday, May 13, 2015 10:06 PM