locked
HTML Client - Use one browse screen with multiple queries RRS feed

  • Question

  • Hello,

    I have a menu screen where there are 3 buttons: "show widgets by name", "show popular widgets" and "show flying widgets". All this screens should take the user to a browse screen where there is a list of widgets sorted by name, popularity or price.

    Now, I know I can set up filters and sorts in a query, and use a query as the data source for a browse screen. I know I can filter and sort from within buttons of a screen by using screen local data properties and screen query parameters. But I don't see how to do that from a different screen.

    We can reuse queries for different browse screens. Can we reuse browse screens for different queries?

    Thank you very much for your help

    Thursday, February 27, 2014 3:54 PM

Answers

  • You've stumbled on perhaps the biggest downfall of LS screens...namely, you cannot change to another query at runtime.  You can however operate on the query in the PreProcessQuery method of the data service code.

    Dynamic queries are doable using Linq Dynamic Query Library.  This would allow you to have a single screen bound to a single query having a single parameter for Sort and also sort dynamically by any number of fields.  Like this:

    http://social.msdn.microsoft.com/Forums/vstudio/en-US/500229db-f462-4fb4-ac25-9ab501a32607/html-table-server-side-sort?forum=lightswitch

    Alternatively, you could do this:

    Add a query Parameter called sortString

    Drag the parameter onto your screen (creates screen property sortString bound to the query param)

    Select the screen property and tick Is Parameter in properties pane

    then do something like this in preprocessquery code (air-code not tested):

    switch (sortString)
    {
        case "FieldA":
            query = query.OrderBy(a => a.FieldA);
            break;
        case "FieldB":
            query = query.OrderBy(a => a.FieldB);
            break;
        case "FieldC":
            query = query.OrderBy(a => a.FieldC);
            break;
        default:
            query = query.OrderBy(a => a.FieldA);
            break;
    }

    Now on your menu you should be able to do this:

    ShowSomeBrowseScreen("FieldA")

    HTH,

    Josh


    • Edited by joshbooker Friday, February 28, 2014 9:37 PM
    • Marked as answer by JoaquinR[BDv] Friday, February 28, 2014 11:03 PM
    Friday, February 28, 2014 9:29 PM

All replies

  • Not sure if i understand the whole picture correctly, but it the following article useful for you?

    http://blog.pragmaswitch.com/?p=1686


    paul van bladel

    Friday, February 28, 2014 9:56 AM
  • Thank you for your answer. That blog might be useful when they post the second part of the article :)

    Let me try to make myself more clear.

    I have one table, widgets. On that table, I create 3 queries: widgets sorted by field A, widgets sorted by field B, and widgets that have field B with value "x". Now, I could easily create 3 browse screens that would show the results of those queries: BrowseWidgetsByA, BrowseWidgetsByB, BrowseWidgetsWithX.

    My problem is that those 3 screens would have the same look and feel, and the same functionality. They are exactly the same screen, the only difference would be that the datasource is a different query. What I would like to do is have only one screen, BrowseWidgets, and choose the query at runtime, depending on what button my user presses on the main menu.


    Friday, February 28, 2014 11:52 AM
  • no problem, I know the author of the blog and  i'll contact him and give him a box of good cigars and a few exquisite bottles of wine. That may speed up part 2 :)

    paul van bladel

    Friday, February 28, 2014 6:11 PM
  • You've stumbled on perhaps the biggest downfall of LS screens...namely, you cannot change to another query at runtime.  You can however operate on the query in the PreProcessQuery method of the data service code.

    Dynamic queries are doable using Linq Dynamic Query Library.  This would allow you to have a single screen bound to a single query having a single parameter for Sort and also sort dynamically by any number of fields.  Like this:

    http://social.msdn.microsoft.com/Forums/vstudio/en-US/500229db-f462-4fb4-ac25-9ab501a32607/html-table-server-side-sort?forum=lightswitch

    Alternatively, you could do this:

    Add a query Parameter called sortString

    Drag the parameter onto your screen (creates screen property sortString bound to the query param)

    Select the screen property and tick Is Parameter in properties pane

    then do something like this in preprocessquery code (air-code not tested):

    switch (sortString)
    {
        case "FieldA":
            query = query.OrderBy(a => a.FieldA);
            break;
        case "FieldB":
            query = query.OrderBy(a => a.FieldB);
            break;
        case "FieldC":
            query = query.OrderBy(a => a.FieldC);
            break;
        default:
            query = query.OrderBy(a => a.FieldA);
            break;
    }

    Now on your menu you should be able to do this:

    ShowSomeBrowseScreen("FieldA")

    HTH,

    Josh


    • Edited by joshbooker Friday, February 28, 2014 9:37 PM
    • Marked as answer by JoaquinR[BDv] Friday, February 28, 2014 11:03 PM
    Friday, February 28, 2014 9:29 PM
  • Thank you very much Josh, that's what I need, and seems like the best option for many other scenarios, since it seems we could use it for filters and everything else (provided it was a finite number of fixed queries on the same entity).

    After banging my head against a wall for some days, I had just done all three identical separate screens. It works and the customer likes it, but it's really ugly inside. Good thing it's just a prototype, and I'll be able to use your solution in the real app.

    Just so you know, there will be a little comment honoring this answer in my code. If you ever end up maintaining some random SMB app in Spain, you might even see it some day! :)

    Friday, February 28, 2014 11:09 PM