cancel
Showing results for 
Search instead for 
Did you mean: 

How to apply filter to Table rows between 2 fields, if field old_price is not equal to new_price?

nareshmallya
Explorer
0 Kudos

I have a sap.m.Switch which says 'prices changed' and a sap.ui.table with 2 columns old_price and new_price. When user clicks on the switch, I need to filter the table rows with condition that old_price is not equal to new_price (old_price != new_price). How do we apply such a condition in sap.ui.model.Filter? I am trying something like below code, but it isn't working.
I am using JSONModel to bind the table rows.

aFilters.push(
	new Filter({
                    path: "NEW_PRICE", 
                    operator: FilterOperator.NE,
                    value1: "{OLD_PRICE}"
                }))
oTable.getBinding("rows").filter(aFilters);

Any help will be greatly appreciated.

Accepted Solutions (1)

Accepted Solutions (1)

AlexNecula
Active Contributor
0 Kudos

Hi,

Since you're using the JSONModel, you can make use of the test parameter which lets you write javascript code that will work on client-side filtering.

Example from the documentation

For the path property, don't use old/new price but the Id (or whatever key you have). This way, you can retrieve the whole row based on it and check the difference of old/new price.

Alex

nareshmallya
Explorer
0 Kudos

Hi Alex, thanks for your response.

Can you please clarify what you mean by the phrase 'but the Id (or whatever key you have)' here? If I use the filter path as the table's array called '/SimulationData' which has old_price and new_price fields, I can see test function provides the whole array instead of each row. How do we retrieve the per row and then check the new/old price fields difference here? Inside the test function, do I need to do a for loop over it and check per row price difference and return true/false boolean?

AlexNecula
Active Contributor

nareshmallya, don't pass the whole entityset, just use a property like you would do with normal filtering.

Use the key property for your entity. I don't know what it is because I can't see how the service is defined.

nareshmallya
Explorer

Thanks a lot Alex, it works! Passing the 'ID' field as the filter path did the trick. Inside the Filter's test function, I then retrieved the row from the entityset array based on this ID and returned the boolean of condition old_price != new_price.

Answers (0)