0

I am trying to filter an upshot RemoteDataSource. With the setFilter function I can pass in an array of filters, but at the moment there is no way of specifying whether I want to apply (filter1 AND filter2), or (filter1 OR filter2). Looking into the upshot.js code, it is clearly visible why:

$.each(query.filters, function (index, filter) {
    if (filterParameter) {
        filterParameter += " and ";
    }
    filterParameter += applyOperator(filter.property, filter.operator, filter.value);
});

As you can see, the "and" is hardcoded into upshot. Is there any other way of supporting "or" between filters, or will I have to manually modify things? And if have to modify, what is the best approach to take so that my modifications don't get discarded when I update to a newer version of upshot?

This is the same question as the one on the ASP.NET forums.

Szilard Muzsi
  • 1,881
  • 2
  • 16
  • 20

1 Answers1

0

I know it's a horrible hack, but you can do this

self.dataSource.setFilter({ 
    property: "(CustomerId eq 1) or (CustomerId eq 2) and true", 
    operator: "==", 
    value: true });

Basically you just need to realize that the upshot filter is a very leaky abstraction on top of the OData $filter. So in the 'property' you can write any OData filter that you want as long as you end it with "true==true"

Reminds me of SQL Injection techniques. I covered data manipulation in Upshot on my blog http://bartjolling.blogspot.com/2012/04/building-single-page-apps-with-aspnet.html

My conclusion was that it's still very far away from being ready for a real business application.

Bart Jolling
  • 595
  • 6
  • 21
  • I guess that would be an option too, but it seems overly difficult to build up and maintain when you have dynamic filter properties. Since it's a hack anyway, it would be easier to just modify the piece of code inside upshot to take into consideration a fourth parameter that would set the `and` or `or` between the filters. – Szilard Muzsi Apr 07 '12 at 19:44
  • The code in your question seems to come from the "DataProvider.OData.js" part of Upshot. If I read the constructor for RemoteDataSource correctly, you can pass your own custom dataProvider as a parameter to a RemoteDataSource. This would allow you to filter as you please without less maintenance issues – Bart Jolling Apr 10 '12 at 12:11