2017-12-18 147 views
1

我有一個智能表。如何在智能表的一列或多列上設置初始排序順序?Sapui5:如何在智能表中設置初始排序順序?

<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> 

這可能是一個解決方案只有一部分是在這裏:

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

回答

0

由於在此page提供給我的另一個問題的答案,我終於達到了這個答案題。我必須在onBindingChangeonInit函數中使用applyVariant函數的視圖。因此,每次啓動視圖或路由匹配時,我都可以調用類似以下的函數。

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