Sharepoint 数据视图 Web 部件工具栏排序默认

发布于 2024-09-08 15:00:42 字数 5787 浏览 3 评论 0原文

我在显示数据表的页面上有一个数据视图 Web 部件。

我想允许用户选择要排序的列。我认为执行此操作的唯一方法是进入数据视图属性,并启用带有排序功能的工具栏。这有效并允许用户使用列的下拉列表选择要排序的列。默认值为“无”,当页面首次加载时,不会应用排序(行按其 ID 显示,这几乎是随机的)。

我希望默认排序为特定列 - 即首次打开页面时,我希望数据按“姓氏”列排序。我不知道如何使用工具栏排序来实现这一点。

我尝试在获取数据的 SQL 语句中指定 ORDER BY SURNAME - 但这最终会覆盖工具栏排序,因此无论工具栏排序选择如何,始终按姓氏排序。

数据视图属性中还有另一个“排序”选项,允许您指定排序,但是这又会覆盖所有内容并使工具栏排序选项变得无用(选择其他内容没有效果)。

我想这个简单的问题肯定有解决方案吗?

排序工具栏生成的代码如下。我尝试通过更改为将姓氏作为下拉框中的选定项目 - 这使得默认情况下在下拉列表中选择姓氏列,但实际上并未应用排序。

有什么想法吗?

<table cellSpacing="0" cellPadding="2" border="0" class="ms-toolbar" style="margin-left: 3px; margin-right: 5px;">
        <tr>
            <td id="dvt_tb_sort" nowrap=""><table><tr><td nowrap="" class="ms-toolbar"><nobr>Sort by: <select>
                <xsl:variable name="clvar1_dvt_sortfield">&apos; + this.options[this.selectedIndex].value + &apos;</xsl:variable>
                <xsl:variable name="clvar2_dvt_sortfield">&apos; + this.options[this.selectedIndex].fieldtype + &apos;</xsl:variable>
                <xsl:variable name="clvar3_dvt_sortfield">&apos; + this.options[this.selectedIndex].title + &apos;</xsl:variable>
                <xsl:variable name="clvar4_dvt_sortfield">&apos; + this.options[this.selectedIndex].sorttype + &apos;</xsl:variable>
                <xsl:attribute name="OnChange">javascript:<xsl:value-of select="ddwrt:GenFireServerEvent(concat('NotUTF8;dvt_sortfield={', $clvar1_dvt_sortfield, '};dvt_sortdir={', $dvt_sortdir, '};dvt_sorttype={', $clvar4_dvt_sortfield, '}'))" /></xsl:attribute>
                <option value="">None</option>
                <option value="Location">
                <xsl:if test="$dvt_sortfield='Location'">
                    <xsl:attribute name="selected">yes</xsl:attribute>
                </xsl:if>
                Location</option>
                <option value="Email">
                <xsl:if test="$dvt_sortfield='Email'">
                    <xsl:attribute name="selected">yes</xsl:attribute>
                </xsl:if>
                Email</option>
                <option value="Mobile">
                <xsl:if test="$dvt_sortfield='Mobile'">
                    <xsl:attribute name="selected">yes</xsl:attribute>
                </xsl:if>
                Mobile</option>
                <option value="Position">
                <xsl:if test="$dvt_sortfield='Position'">
                    <xsl:attribute name="selected">yes</xsl:attribute>
                </xsl:if>
                Position</option>
                <option value="Telephone">
                <xsl:if test="$dvt_sortfield='Telephone' and not($dvt_sorttype='number')">
                    <xsl:attribute name="selected">yes</xsl:attribute>
                </xsl:if>
                Telephone</option>
                <option value="Telephone" sorttype="number">
                <xsl:if test="$dvt_sortfield='Telephone' and $dvt_sorttype='number'">
                    <xsl:attribute name="selected">yes</xsl:attribute>
                </xsl:if>
                Telephone(Number)</option>
                <option value="Forename">
                <xsl:if test="$dvt_sortfield='Forename' or $dvt_sortfield=''">
                    <xsl:attribute name="selected">yes</xsl:attribute>
                </xsl:if>
                Forename</option>
                <option value="Surname">
                <xsl:if test="$dvt_sortfield='Surname'">
                    <xsl:attribute name="selected">yes</xsl:attribute>
                </xsl:if>
                Surname</option>
                </select><a>
                <xsl:attribute name="href">
                    <xsl:choose>
                        <xsl:when test="$dvt_sortdir='descending'">javascript:<xsl:value-of select="ddwrt:GenFireServerEvent(concat('dvt_sortfield={', $dvt_sortfield, '};dvt_sortdir={ascending}'))" /></xsl:when>
                        <xsl:otherwise>javascript:<xsl:value-of select="ddwrt:GenFireServerEvent(concat('dvt_sortfield={', $dvt_sortfield, '};dvt_sortdir={descending}'))" /></xsl:otherwise>
                    </xsl:choose>
                </xsl:attribute>
                <xsl:if test="$dvt_sortfield" ddwrt:cf_ignore="1"><img border="0">
                    <xsl:attribute name="src">
                        <xsl:choose>
                            <xsl:when test="$dvt_sortdir='descending'"><xsl:value-of select="ddwrt:FieldSortImageUrl('Asc')" /></xsl:when>
                            <xsl:otherwise><xsl:value-of select="ddwrt:FieldSortImageUrl('Desc')" /></xsl:otherwise>
                        </xsl:choose>
                    </xsl:attribute>
                    <xsl:attribute name="alt">
                        <xsl:choose>
                            <xsl:when test="$dvt_sortdir='descending'">Descending</xsl:when>
                            <xsl:otherwise>Ascending</xsl:otherwise>
                        </xsl:choose>
                    </xsl:attribute>
                    </img></xsl:if>
                </a></nobr></td></tr></table></td><td width="99%"></td>
        </tr>
    </table>

I have a data view web part on a page which is displaying a table of data.

I want to allow users to choose which column to sort by. I think the only way to do this is go into the data view properties, and enable the toolbar with sorting. This works and allows the user to select a column to sort using a dropdown list of columns. The default is 'none', and when the page first loads, there is no sorting applied (rows are shown by their ID, which is pretty much random).

I want the default sort to be a particular column - i.e. when the page is first opened, I want the data to be sorted by a 'Surname' column. I can't figure out how to achieve this using the toolbar sort.

I have tried specifying an ORDER BY SURNAME in the SQL statement which gets the data - however this ends up overriding the toolbar sort, so sorting is always by surname, regardless of the toolbar sort selection.

There is another 'sorting' option in the data view properties which allows you to specify a sort, however again this overrides everything and renders the toolbar sorting option useless (selectiong something else has no effect).

I'm thinking surely there must be a solution to this simple problem?

The generated code for the sorting toolbar is below. I have tried making the surname the selected item in the dropdown box by changing to - this makes the surname column selected in the dropdown by default but the sorting isn't actually applied.

Any ideas?

<table cellSpacing="0" cellPadding="2" border="0" class="ms-toolbar" style="margin-left: 3px; margin-right: 5px;">
        <tr>
            <td id="dvt_tb_sort" nowrap=""><table><tr><td nowrap="" class="ms-toolbar"><nobr>Sort by: <select>
                <xsl:variable name="clvar1_dvt_sortfield">' + this.options[this.selectedIndex].value + '</xsl:variable>
                <xsl:variable name="clvar2_dvt_sortfield">' + this.options[this.selectedIndex].fieldtype + '</xsl:variable>
                <xsl:variable name="clvar3_dvt_sortfield">' + this.options[this.selectedIndex].title + '</xsl:variable>
                <xsl:variable name="clvar4_dvt_sortfield">' + this.options[this.selectedIndex].sorttype + '</xsl:variable>
                <xsl:attribute name="OnChange">javascript:<xsl:value-of select="ddwrt:GenFireServerEvent(concat('NotUTF8;dvt_sortfield={', $clvar1_dvt_sortfield, '};dvt_sortdir={', $dvt_sortdir, '};dvt_sorttype={', $clvar4_dvt_sortfield, '}'))" /></xsl:attribute>
                <option value="">None</option>
                <option value="Location">
                <xsl:if test="$dvt_sortfield='Location'">
                    <xsl:attribute name="selected">yes</xsl:attribute>
                </xsl:if>
                Location</option>
                <option value="Email">
                <xsl:if test="$dvt_sortfield='Email'">
                    <xsl:attribute name="selected">yes</xsl:attribute>
                </xsl:if>
                Email</option>
                <option value="Mobile">
                <xsl:if test="$dvt_sortfield='Mobile'">
                    <xsl:attribute name="selected">yes</xsl:attribute>
                </xsl:if>
                Mobile</option>
                <option value="Position">
                <xsl:if test="$dvt_sortfield='Position'">
                    <xsl:attribute name="selected">yes</xsl:attribute>
                </xsl:if>
                Position</option>
                <option value="Telephone">
                <xsl:if test="$dvt_sortfield='Telephone' and not($dvt_sorttype='number')">
                    <xsl:attribute name="selected">yes</xsl:attribute>
                </xsl:if>
                Telephone</option>
                <option value="Telephone" sorttype="number">
                <xsl:if test="$dvt_sortfield='Telephone' and $dvt_sorttype='number'">
                    <xsl:attribute name="selected">yes</xsl:attribute>
                </xsl:if>
                Telephone(Number)</option>
                <option value="Forename">
                <xsl:if test="$dvt_sortfield='Forename' or $dvt_sortfield=''">
                    <xsl:attribute name="selected">yes</xsl:attribute>
                </xsl:if>
                Forename</option>
                <option value="Surname">
                <xsl:if test="$dvt_sortfield='Surname'">
                    <xsl:attribute name="selected">yes</xsl:attribute>
                </xsl:if>
                Surname</option>
                </select><a>
                <xsl:attribute name="href">
                    <xsl:choose>
                        <xsl:when test="$dvt_sortdir='descending'">javascript:<xsl:value-of select="ddwrt:GenFireServerEvent(concat('dvt_sortfield={', $dvt_sortfield, '};dvt_sortdir={ascending}'))" /></xsl:when>
                        <xsl:otherwise>javascript:<xsl:value-of select="ddwrt:GenFireServerEvent(concat('dvt_sortfield={', $dvt_sortfield, '};dvt_sortdir={descending}'))" /></xsl:otherwise>
                    </xsl:choose>
                </xsl:attribute>
                <xsl:if test="$dvt_sortfield" ddwrt:cf_ignore="1"><img border="0">
                    <xsl:attribute name="src">
                        <xsl:choose>
                            <xsl:when test="$dvt_sortdir='descending'"><xsl:value-of select="ddwrt:FieldSortImageUrl('Asc')" /></xsl:when>
                            <xsl:otherwise><xsl:value-of select="ddwrt:FieldSortImageUrl('Desc')" /></xsl:otherwise>
                        </xsl:choose>
                    </xsl:attribute>
                    <xsl:attribute name="alt">
                        <xsl:choose>
                            <xsl:when test="$dvt_sortdir='descending'">Descending</xsl:when>
                            <xsl:otherwise>Ascending</xsl:otherwise>
                        </xsl:choose>
                    </xsl:attribute>
                    </img></xsl:if>
                </a></nobr></td></tr></table></td><td width="99%"></td>
        </tr>
    </table>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不顾 2024-09-15 15:00:42

詹姆斯,
搜索标记为 dvt_sortfield 的参数绑定,然后手动写入:Default="FIELDNAME" 行。
这应该可以解决问题。

ParameterBinding Name="dvt_sortfield" Default="ID" Location="Postback;Connection"

如果您需要更改默认排序,还有一个名为 dvt_sortdir 的排序参数,您可以在 ParameterBinding 标记中再次设置它。

James,
Search for the parameter binding labeled dvt_sortfield, then manually write in: Default="FIELDNAME" line.
This should do the trick.

ParameterBinding Name="dvt_sortfield" Default="ID" Location="Postback;Connection"

If you need to change the default sort there is also a sort parameter called dvt_sortdir and you can set it again in the ParameterBinding tag.

Dan

浅忆 2024-09-15 15:00:42

如果您在 SQL 中首先选择“姓氏”列,会发生什么情况?

What happens if you select the Surname column first in the SQL?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文