Sapui5:如何在 smarttable 中设置初始排序顺序? [英] Sapui5: How can I set an initial sort order in smarttable?

查看:70
本文介绍了Sapui5:如何在 smarttable 中设置初始排序顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张智能桌子.如何在 smarttable 的一列或多列上设置初始排序顺序?

<semantic:SemanticPage id="page"><语义:内容><smartTable:SmartTable id="smartTable";entitySet=ProjectHeaderSet"tableBindingPath="/ProjectHeaderSet";app:p13nDialogSettings="{sort:{items:[{columnKey: '说明',操作:'升序'}]}}"标头={i18n>/X000558}";showRowCount=真";tableType="响应式";smartFilterId="prdefWorklistFilterBarId";showFullScreenButton="true";useVariantManagement="false";enableAutoBinding="true"忽略字段=WbsElement,Method,Refnumber"initialVisibleFields=ProjectDefinition,Description,ZProjecttypeName,ZMsSchemeText"><智能表:自定义工具栏><m:OverflowToolbar design="透明"><m:ToolbarSpacer/><m:SearchField id="searchField";工具提示={i18n>/X000559}"宽度=自动"搜索=onSearch"liveChange=onSearchLiveChange"></m:SearchField><m:Button type="透明";press=onCreateBtnPress"icon="sap-icon://add";工具提示={i18n>/X000053}"/><m:Button type="透明";press=onDeleteBtnPress"icon="sap-icon://delete";工具提示={i18n>/X000058}"/></m:OverflowToolbar></smartTable:customToolbar><m:Table id="table"模式=多选"><m:项目><m:ColumnListItem type=导航"press=onPress"/></m:items></m:表></smartTable:SmartTable></semantic:content></semantic:SemanticPage></mvc:查看>

唯一可能是一种解决方案的部分在这里:

app:p13nDialogSettings="{sort:{items:[{columnKey: '说明',操作:'升序'}]}}"

解决方案

感谢为我在此

我在其中一条评论中发现了这张图片这里.

注意:不要忘记将以下定义放入注释文件中:

<注释项=Common.ApplyMultiUnitBehaviorForSortingAndFiltering"/></注释>

不要忘记根据您的命名空间和实体容器的名称更新 namespace.EntityContainerName.

它也只在网格表上显示排序标志!

I have a smart table. How can I set an initial sort order on one or multiple columns of the smarttable?

<mvc:View xmlns:m="sap.m" xmlns:mvc="sap.ui.core.mvc" xmlns:semantic="sap.m.semantic" xmlns:footerbar="sap.ushell.ui.footerbar"
    xmlns:smartFilterBar="sap.ui.comp.smartfilterbar" xmlns:smartTable="sap.ui.comp.smarttable"
    xmlns:app="http://schemas.sap.com/sapui5/extension/sap.ui.core.CustomData/1"
    controllerName="audi.project.definition.controller.Worklist">
    <semantic:SemanticPage id="page">
        <semantic:content>
            <smartTable:SmartTable id="smartTable" entitySet="ProjectHeaderSet" tableBindingPath="/ProjectHeaderSet"
                app:p13nDialogSettings="{sort:{items:[{
                    columnKey: 'Description',
                    operation: 'Ascending'
                }]}}" 
                header="{i18n>/X000558}" showRowCount="true" tableType="Responsive" smartFilterId="prdefWorklistFilterBarId"
                showFullScreenButton="true" useVariantManagement="false" enableAutoBinding="true" ignoredFields="WbsElement,Method,Refnumber"
                initiallyVisibleFields="ProjectDefinition,Description,ZProjecttypeName,ZMsSchemeText">
                <smartTable:customToolbar>
                    <m:OverflowToolbar design="Transparent">
                        <m:ToolbarSpacer/>
                        <m:SearchField id="searchField" tooltip="{i18n>/X000559}" width="auto" search="onSearch" liveChange="onSearchLiveChange"></m:SearchField>
                        <m:Button type="Transparent" press="onCreateBtnPress" icon="sap-icon://add" tooltip="{i18n>/X000053}"/>
                        <m:Button type="Transparent" press="onDeleteBtnPress" icon="sap-icon://delete" tooltip="{i18n>/X000058}"/>
                    </m:OverflowToolbar>
                </smartTable:customToolbar>
                <m:Table id="table" mode="MultiSelect">
                    <m:items>
                        <m:ColumnListItem type="Navigation" press="onPress"/>
                    </m:items>
                </m:Table>
            </smartTable:SmartTable>
        </semantic:content>
    </semantic:SemanticPage>
</mvc:View>

The only part that could be one solution is here:

app:p13nDialogSettings="{sort:{items:[{
    columnKey: 'Description',
    operation: 'Ascending'
}]}}"

解决方案

Thanks to the answer provided for my another question in this page, I finally reached to an answer for this question. I had to use applyVariant function in the onBindingChange or onInit function of the view. Thus I can call a function like the following each time the view is initiated or the route is matched.

    setInitialSortOrder: function() {
            var oSmartTable = this.getView().byId("mySmartTableId");            
            oSmartTable.applyVariant({
                 sort: {
                          sortItems: [{ 
                                         columnKey: "ColumnId", 
                                         operation:"Ascending"}
                                     ]
                       }
            });
    }

Updated Solution

The other possibility is to use annotation. Using the annotations has some benefices in comparison to the previous solution. You can add a sort order on your set by following this annotation settings:

I found this picture in one of the comments here.

Note: Don't forget to put the following definition in your annotation file:

<Annotations xmlns="http://docs.oasis-open.org/odata/ns/edm" Target="namespace.EntityContainerName">
        <Annotation Term="Common.ApplyMultiUnitBehaviorForSortingAndFiltering"/>
</Annotations>

Don't forget to update namespace.EntityContainerName based on your namespace and the entity container's name.

Also it shows the sorting sign only on grid table!

这篇关于Sapui5:如何在 smarttable 中设置初始排序顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆