[英]How to implement initial sorting in SAP UI5 Smart Table
我有一個智能表,里面有一些自定義列。 我想最初根據某個字段對表格進行排序,我該如何實現?
到目前為止,我已經嘗試了以下方法,但沒有奏效。
var oSmartTableBatches = this.getView().byId("sapAffectedBatchesSmartTable2");
oSmartTableAlerts.applyVariant({
sort: {
sortItems: [{
columnKey: "FieldName",
operation: "Descending"
}]
}
});
我還嘗試使用 Presentation Variant 注釋實體集
<Annotation Term="com.sap.vocabularies.UI.v1.PresentationVariant">
<Record>
<PropertyValue Property="SortOrder">
<Collection>
<Record>
<PropertyValue Property="Property" PropertyPath="FieldName"/>
<PropertyValue Property="Descending" Boolean="true"/>
</Record>
</Collection>
</PropertyValue>
</Record>
</Annotation>
我正在使用 odata v2 model。
我還嘗試使用 beforeRebindTable function 添加排序器,但是它破壞了表格個性化對話框,並且分組和過濾不再適用於表格。
排序器必須是sap.ui.model.Sorter
對象的數組,請參閱文檔。
applyVariant
僅用於在 P13N 對話框中顯示已排序的列。
您使用的注釋僅適用於網格表而不是響應表!
如果要應用初始排序,則需要具有以下事件處理程序:
// define this variable in onInit function or in the controller class level
initView: true,
// smart table event handler
onBeforeRebindTable: function (oEvent) {
var mBindingParams = oEvent.getParameter("bindingParams");
if(this.initView){
// to apply the sort
mBindingParams.sorter = [new sap.ui.model.Sorter({ path: "FieldName", descending: true})];
// to short the sorted column in P13N dialog
var oSmartTable = oEvent.getSource();
oSmartTable.applyVariant({
sort: {
sortItems: [{
columnKey: "FieldName",
operation: "Descending"
}]
}
});
// to prevent applying the initial sort all times
this.initView = false;
}
},
此代碼僅在加載應用程序或用戶按下瀏覽器刷新按鈕時對數據進行排序!
不要忘記保留行mBindingParams.sorter = [new sap.ui.model.Sorter({ path: "FieldName", descending: true})];
在if
條件內,否則每次該用戶應用排序時,您將覆蓋它。
這種情況也是可能的:
if(mBindingParams.sorter.length === 0)
但在這種情況下,用戶無法刪除排序條件。 因此,當他或她在P13N
對話框中刪除所有排序時,不僅在初始化時,而且在這種情況下也會應用初始排序順序!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.