我正在尝试为树表构建一个刷新按钮。刷新操作(使用具有已定义过滤条件的bindrows
方法)后,需要保留上一个标记的行。
问题是,在刷新操作之后,标记的行将消失。我不确定addEventDelegate()
是否是一种合适的方法,因为即使我在onAfterRendering()
内设置了调试器,这种方法也无法做出任何反应。
有没有人有解决这种情况的解决方案?
onRefresh : function() {
var oTreeTable = this.getView().byId("treeTable");
oTreeTable.bindRows({
path: "/TTBL_Set",
filters: filterRefresh,
parameters: {
countMode: "Request",
numberOfExpandedLevels: 4
}
});
oTreeTable.addEventDelegate({
onAfterRendering: function() {
oTreeTable.setSelectedIndex(iCurrentSelectedIndex); //iCurrentSelectedIndex is pre-defined
}
}, this);
},
答案 0 :(得分:0)
您可以使用Custom Data和sap.ui.model.Binding attachDataReceived()
1.在行选择方法中保存选定的行上下文路径。
//inside rowSelectionChange() method
var oTTable = getYourTable;
oCutsData = {},
rowContextPath = oEvent.getSource().getBindingContext().getPath();
if(oTTable && oTTable.data("selectedRows")){
oCustData = oTTable.data("selectedRows");//add your new row selection context path and update the object
oCutsData[rowContextPath] = rowContextPath;
}else{//for first selection
oCutsData = {};
oCutsData[rowContextPath] = rowContextPath;//create new object
}
oTTable.data("selectedRows",oCutsData);
2.收到数据后,循环自定义数据并再次选择行
var oTTable = this.getView().byId("yourTableID")
if(oTTable){
var oRowsBinding = oTTable.getBinding("rows");//Rows Binding
oRowsBinding.attachDataReceived(function(oEvent){
var oSelectedRows = oTTable.data("selectedRows");
if(oSelectedRows){
var oModel = getYourModel(); //Tree table model
var sPath = null;//only for one selection
for(var path in oSelectedRows){
sPath = oSelectedRows[path];
}
//get the row contexts and compare with the previous selected row and select
var oRowContexts = oTTable._getRowContexts();
for(var index in oRowContexts){
if(oRowContexts[index].context.getPath() === sPath ){
//Select the table row using row index
oTTable.setSelectedIndex(parseInt(index));
break;
}
}
//after the loop destroy the custom data using destroyCustomData()
oTTable.destroyCustomData();
}
}.bind(this));
}