0

I'm trying use a TreeTable binding to OData with filters. But the filter value is inside another model. This post is about XML view binding.

Model 1 (got by navigation params):

{
  locationID: 'MD',
  locationName: 'My location'
}

So my tree table:

<table:TreeTable rows="{
      path: '/Model2',
      filters: [
          {
              path: 'LOC_ID',
              operator: 'EQ',
              value1: '{Model1>/locationID}'
          }
      ],
      parameters: {
          treeAnnotationProperties : {
              hierarchyLevelFor : 'HIERARCHY_LEVEL',
              hierarchyNodeFor : 'ROW_ID',
              hierarchyParentNodeFor : 'PARENT_ROW_ID',
              hierarchyDrillStateFor : 'DRILL_STATE'
          }
      }
}">

What do you think? any way?

cristhiam
  • 496
  • 1
  • 4
  • 17
  • Does this answer your question? [How to bind filter values in XML view](https://stackoverflow.com/questions/41777791/how-to-bind-filter-values-in-xml-view) – Boghyon Hoffmann Jul 17 '21 at 13:11

2 Answers2

0

as far as I know, XML filters does not support values from JSON/OData models. You can only use constants or otherwise, you can implement it in your JavaScript controller on the route matched.

StErMi
  • 5,389
  • 5
  • 48
  • 71
0

You have to use the controller bound to the View.

You can write some small logic in the onInit function.

onInit: function () {
  var table = this.byId("yourTableName");
  // get the value you want to use (not sure where and how your 
  // model is loaded)
  var value = this.getView().getModel().getParameter("yourParameter");
   
  // Bind your items here, use whatever you need and insert your filter value
  // Sorters etc can be added here
  table.bindItems({
    path: '/Model2',
    filters: [
      {
          path: 'LOC_ID',
          operator: 'EQ',
          value1: value
      }
    ],
    template: this.byId("tableTemplate"),
    templateShareable: true,
    parameters: {
      //your parameters
    }
  });
}

In order for this to work properly change your XML.

<Table ...>
  <columns>
    ...
  </columns>
  < ! - - Your items need to be swapped out for dependents - - >
  <dependents>
    <ColumnListItem
      id="tableTemplate">
      ...
    </ColumnListItem>
  </dependents>
</Table>

All of this worked fine for a sap.m.Table - but this should be adaptable for your case.

  • Hi @enzo-schröder nice answer, thank you. Ok Now I got the binding model. But I does not understand the "dependent" concept in treetable. Tree table defines the template inside the Column tag. – cristhiam Jan 25 '19 at 19:44
  • Ok I solved. Just like enzo-schröder and stErMi say only controller binding allowed (see Enzo table example). But you don't need dependent tag in treetable. If you get "replace" error just add filter as instance of sap.ui.model.Filter, not like JSON notation. – cristhiam Jan 25 '19 at 21:32