cancel
Showing results for 
Search instead for 
Did you mean: 

how to apply filters on RowRepeater

Former Member
0 Kudos

Hi All,

I am having following json data

var dataObject =  [{name:"test1", id:"1", isSelected: true},

                            {name:"test2", id:"2", isSelected: true},

                            {name:"test3", id:"3", isSelected: true},

                            {name:"test4", id:"4", isSelected: false},

                            {name:"test5", id:"5", isSelected: false},

                            {name:"test6", id:"6", isSelected: true},

                            {name:"test7", id:"7", isSelected: true}

                           ]

               

i am binding above JSON using RowRepeater control. Now there are two rowRepeater control one binds value with isSelected = true and other bind value with is selected = false;  I am able to bind data to repeater grid. but filter is not working.
I have tried as

  var oModel = new sap.ui.model.json.JSONModel();

  oModel.setData({"data": dataObject});

  sap.ui.getCore().setModel(oModel);

var testFilter = new sap.ui.model.Filter("isSelected","EQ","true");

                       /*new sap.ui.model.Filter("isSelected","EQ",true);*/    

oRowRepeater1.applyFilter(testFilter);

but it is not working. Also I want user can select/unselect any Name form JSON base on that both repeater should updated their data binding. Actual JSON is very huge data(columns/properties) but here I have enter only required one to understand my logic.

I have also tried following link solution but filter never come to work

RowRepeater - SAPUI5 Demo Kit

Any help is appreciated.

Thanks in Advanced.

Accepted Solutions (1)

Accepted Solutions (1)

former_member184578
Active Contributor
0 Kudos

Hi,

Try this,


oRowRepeater.bindRows(

  {path: "/data",

  template: oRowTemplate,

  filters:  [new sap.ui.model.Filter("isSelected", sap.ui.model.FilterOperator.EQ, true) ]

  } );

hope this helps you,

Regards,

Kiran

Former Member
0 Kudos

Thanks kiran,

It works. But I am also showing count of user bind to each table. How would I get total count after applying filter.

former_member184578
Active Contributor
0 Kudos

Hi,

For showing the count, loop over the model data and get the count.

Try this code:


var modelData = oModel.getData();

  var rowCount = 0;

  for(var i = 0; i < modelData.data.length; i++){

 

  if(modelData.data[i].isSelected){

  rowCount = rowCount + 1;

  }

  }

Now rowCount contains the count.

hope this helps,

Regards,

Kiran

Former Member
0 Kudos

Thanks Kiran,

I know this way. But there are few more filter on LHS rowRepeator control. So it will be better rowrepeater would give statistic like no of pages that he is displaying, PageSize(getRow() - give me all row, getNumberOfRow() give me current page row) + last page rowcount etc. so that I can sum them up and get exact count.

or otherwise I have to apply few more filter logic in your for loop to get that number again.

Answers (0)