我有一个智能表,里面有一些定制的列。我想首先根据某个字段对表进行排序,我该如何实现?
到目前为止,我已经尝试了以下方法,但不起作用。
var oSmartTableBatches = this.getView().byId("sapAffectedBatchesSmartTable2");
oSmartTableAlerts.applyVariant({
sort: {
sortItems: [{
columnKey: "FieldName",
operation: "Descending"
}]
}
});我还尝试使用表示变体对实体集进行注释
<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模型。
我也尝试过使用beforeRebindTable函数添加一个排序器,但是它破坏了表个性化对话框,并且分组和过滤不再对表起作用。
发布于 2020-04-29 17:13:27
排序器必须是sap.ui.model.Sorter对象的数组,参见documentation。
发布于 2020-08-14 22:41:49
该applyVariant仅用于在P13N对话框中显示已排序的列。
您使用的注释仅适用于Grid表,而不适用于响应表!
如果要应用初始排序,则需要具有以下事件处理程序:
// 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对话框中的所有排序时,不仅在初始化时间,而且在这种情况下,初始排序顺序也将被应用!
https://stackoverflow.com/questions/61404388
复制相似问题