在 treetable 中保留 bindrows() 之后的标记行

Keep the marked row after bindrows() in treetable

我正在尝试为树构建一个刷新按钮 table。刷新动作后(使用bindrows方法定义过滤条件),需要保留之前标记的行。 问题是,刷新操作后,标记的行将消失。我不确定 addEventDelegate() 是否是一个 suitable 方法,因为这个方法没有任何反应,即使我在 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);               
},

树中标记的行-table需要在刷新事件后保留

您可以使用 Custom Data and sap.ui.model.Binding attachDataReceived()

来实现

1.Save 行内的 selected 行上下文路径 selection 方法。

//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.After 数据被接收循环自定义数据和select 再次行

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));
    }