locked
How to filter/search through the results of a query RRS feed

  • Question

  • When I wrote this app in Silverlight, I had many queries, each with a specific purpose. This made the app very slow with all the back and forth to the server. What I would like to do is have a single query get all the pertinent information from the server, and then filter or search through the results to part out each chunk of information that I need from the whole.

    In my database, each option or set of options has the name of the control to which it is bound. I can easily retrieve all of the options but then I cannot figure out how to get subsets out of that result. The only thing I can think of is to apply a filter like so:

        screen.getOptionsByModelNo().then(function (results) {
            allOptions = results;
            var filter = "(ControlName eq " + msls._toODataString("tMotors", ":String") + ")";
            temp = allOptions.data.filter(filter).execute();
        });

    I can see the results in a Watch window and the data that I want is there. It is located in each array element under _data under the details and then finally under the _ (underscore).

    Watch Window

    How can I filter a query result that I already have to get a subset? I've tried allOptions.data and allOptions._data but both times attempting to look at my temp variable, it comes back as undefined in the watch window so the filter never gets applied.

    Tuesday, January 12, 2016 9:37 PM

Answers

  • Hi kyle ls,

    According to your description, you want to use one query to implement different searching from your database.

    Please create a basic query first and then add different parameters in your query. Then when you using this query on screen, please pass the parameters that you want to filter the data. Please refer to following screenshot.

    Best Regards,
    Weiwei

    • Proposed as answer by Angie Xu Tuesday, January 26, 2016 7:26 AM
    • Marked as answer by Angie Xu Tuesday, January 26, 2016 7:26 AM
    Friday, January 15, 2016 9:41 AM
    Moderator

All replies

  • Hi kyle ls,

    According to your description, you want to use one query to implement different searching from your database.

    Please create a basic query first and then add different parameters in your query. Then when you using this query on screen, please pass the parameters that you want to filter the data. Please refer to following screenshot.

    Best Regards,
    Weiwei

    • Proposed as answer by Angie Xu Tuesday, January 26, 2016 7:26 AM
    • Marked as answer by Angie Xu Tuesday, January 26, 2016 7:26 AM
    Friday, January 15, 2016 9:41 AM
    Moderator
  • It's been said that filtering a Visual Collection on the client side is not supported nor is providing a custom OData filter to the screen query.  You must use the query builder to design a server side query as suggested above.  However OData filtering can be done if you're feeling adventurous.

    HTML Client: Javascript Apply Filter to Screen Data Collection

    Monkey Patched LightSwitch Screen Collection Queries

    HTH,

    Josh

    Friday, January 15, 2016 2:05 PM