2017-09-14 19 views
0

カテゴリでフィルタリングするために使用されるSAPUI5 TreeTableがあります。私が望むのは、親カテゴリを選択すると、すべての子を選択し、親が選択解除されたときには子が崩壊しているかどうかにかかわらず選択を解除する必要があるということです。問題は明らかに、折りたたまれたアイテムに基づいて異なるため、インデックスを使用できないということです。木のテーブルデータがoEvent.getSource().oKeysは、親と子の情報を持っている表のカスタムデータでこれを保存します受信され1.OnceSAPUI5 TreeTable親が選択されたときに子供を選択します。

  <t:TreeTable 
       id="treeCategoriesFilterItem" 
        rows="{path:'tree_categories>/', parameters: {arrayNames:['categories']}}" 
        selectionMode="MultiTogle" 
        enableSelectAll="false" 
        ariaLabelledBy="title" 
        visibleRowCountMode="Fixed" 
        rowSelectionChange="onCategoriesRowSelectionChange" 
        > 
       <t:columns> 
        <t:Column width="100%"> 
         <Label text="{i18n>label.ticket.category}"/> 
         <t:template> 
          <Text text="{tree_categories>name}"/> 
         </t:template> 
        </t:Column> 
       </t:columns> 
      </t:TreeTable> 

答えて

1

あなたは

ことによってそれを達成することができます。このデータは、選択した親の子を取得するのに役立ちます。親が選択されている

var oRowsBinding = oTable.getBinding("rows"); 
oRowsBinding.attachDataReceived(function(oEvent){ 
    var oKeys = oEvent.getSource().oKeys;//will have the parent and child information. 
    oTable.data("keys", oKeys);//store the key values 
}.bind(this)); 

2.親とループのパスを結合すべてのチャイルズの結合パスを取得し、モデルsetProperty()を使用して子項目を選択するには、対応するプロパティを更新します。同じものを選択解除することになります。

onSelection: function(oEvent){ 
    var oSource = oEvent.getSource(); 
    bPCBEnabled = oSource.getSelected(), 
    oRow = oSource.getParent(), 
    oTable = oRow.getParent(), 
    iHierarchyLevel = oRow.getBindingContext("oModel").getObject().HierarchyLevel; 
    if(iHierarchyLevel === 1 && oTable && oTable.data() && oRow){ 
     if(bPCBEnabled)//expand/collapse parent 
      oTable.expand(oRow.getIndex()); 
     else 
      oTable.collapse(oRow.getIndex()); 

     var oKeys = oTable.data().keys, 
     sPath = oRow.getBindingContext("oModel").sPath,//parent binding path 
     oChilds = oKeys[sPath.replace("/", "")]; 
     for(var iKey in oChilds){ 
      sChildPath = "/" +oChilds[iKey],//child binding path 
      oModel = oTable.getModel("oModel"), 
      oModel.setProperty(sChildPath + "/Enabled", bPCBEnabled);//change to your corresponding model property which tells is selected/deselected 
     } 
    } 
} 
関連する問題