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