cancel
Showing results for 
Search instead for 
Did you mean: 

getBindingInfo - how to avoid it?

Former Member
0 Kudos

Hi guys,

I have an app with an XML view and controller.

What I need to do basically is to put a table on the view, and items with binding - however the binding filter should be dynamic.

So right now I'm having a workaround, which I have a feeling is not so great.

Is there a better way to do this than what I did?

In the controller, I can't get the table's binding, but only the binding info which I think is not recommended to use.

What I also want to avoid is to first load the data without the filter, and then put the filter.

This is what the XML view looks like:

...

<Table

       id="table"

       items="{

            path: '/Rules',

            filters: [],

            sorter: {

            path: 'Name',

            descending: false

       }

  }"

  growing="true"

  growingScrollToLoad="true"

  updateFinished="onUpdateFinished">

...

and the controller:

...

onInit : function () {

  oTable = this.byId("table");

  var appId = "Something not static";

  var oBinding = oTable.getBindingInfo("items");

  oBinding.filters = [new sap.ui.model.Filter("ApplicationId", "EQ", appId)];

...

Thanks,

Or.

Accepted Solutions (0)

Answers (3)

Answers (3)

SergioG_TX
Active Contributor
0 Kudos

Or

you can declare the end point in the table (view)  then on the controller event ... onBeforeRendering you can apply the filter you need (dynamically)

Former Member
0 Kudos

Hi, I tried what you offered but the results were the same - in onBeforeRendering event I get undefined in table.getBinding()

Former Member
0 Kudos

Hi,

You can do this, SAPUI5 Explored

there dynamic filter used, check the handleConfirm function in Controller file, Dialog.fragment.xml is for the filter,sorter Pop-up(do check this too)

One more thing, "In the controller, I can't get the table's binding" Why?

if you are able to get the table control, I think you should get its binding too.

Thanks,

Chandan

Former Member
0 Kudos

Hi Chandan,

The thing is that I don't have the table bound to the model (oDataModel) yet, when I want to put the filter.

As you can see I declare the table in the XML view, and in the controller's onInit event I try to add the filter. At that point the table.getBinding() returns undefined, but the table.getBindingInfo() returns the binding info as I declared in the XML view.

In the example you sent, the table is already bound to the model, and then the filter is changed.

What I also want to avoid in my code is to bind the table to the path with all the items, and then put the filter, because then I have two calls to the bh. (I use oDataModel)

Thanks,

Or.

Former Member
0 Kudos

Sorry I didn't get you,

As far you question, at first you don't want filter so why are you pushing filter at onInit()?


Former Member
0 Kudos

I want filter from the beginning, I just can't define it in the XML because it is dynamic, so I define it in the onInit() event.

What I tried to explain, is that I don't want the table to call the bh for data without filter, and then to call again with it.

Former Member
0 Kudos

So a filter is predefined and on that data you want dynamic filter?

So if the Model is Odata, at onInit() read the model with your filter, then use the dynamic filter in a different function(as in my 1st reply).

Like this- inside onInit() do something like this-

oModel.read("/your_dataset",                

                   null,

                   ["$filter=your_entity eq 'value'"], // filter it

                   false,

                   function(oData, oResponse){

                      //oData will contain filtered data, bind it with the table        

            } 

      

       );

Now make use of SAPUI5 explored example filter in your own function.

This should do your job.

Thanks,

chandan

jamie_cawley
Advisor
Advisor
0 Kudos

Why don't you move the items declaration from the view to the controller?

Regards,

Jamie

SAP - Technology RIG

Former Member
0 Kudos

Because when I declare the items in the controller (with bindAggregation), I also need to move the table template there as well - otherwise there is an error thrown.

And since the template is the biggest part of the table definition - it turns out that I declare some controls in the XML view and some in the controller..

I want to keep the controls I declare in the controller at minimum.

jamie_cawley
Advisor
Advisor
0 Kudos

You can use a fragment to declare the table and then use it for the template.


var oTblFrag = new sap.ui.xmlfragment("com.sap.demo.view.Table", this);

  this._oList.bindAggregation("items", {

   path: "/Collection",

   template: oTblFrag,

   filters: myFilters

  });

Regards,

Jamie

SAP - Technology RIG