Locked Beta 2 Multiple Sorts in Query not working

  • Friday, March 25, 2011 4:59 PM
     
     
    I have upgraded Visual Studio 2010 to SP1 and installed LightSwitch Beta 2.  I am manually replicating Beta 1 projects in Beta 2.  It seems that the Edit Query Sort on a screen Data Item only sorts on the first field.  If I add one or more fields to the sort, the additional fields seem to have no effect.

All Replies

  • Friday, March 25, 2011 5:51 PM
     
     Answered Has Code

    Hi Steve,

    Thanks for pointing this issue out.  Yes this is a bug.  If this is a blocking issue for you, the only workaround that I know of it to define the multi-segment sort within the _PreprocessQuery method of the modeled query the screen collection is built on.

    1.  Define a modeled query under the entity data you want to display on the screen.

    2.  Within the query designer, select the Write Code toolbar button, select the <queryName>_PrepocessQuery method and add the following code:

    query = query.OrderBy(c => c.Country).ThenBy(c => c.City);
    

    3.  Create your screen using the query created in step #2.

    HTH

  • Saturday, May 14, 2011 1:42 PM
     
      Has Code

    Hi Steve,

    Thanks for pointing this issue out.  Yes this is a bug.  If this is a blocking issue for you, the only workaround that I know of it to define the multi-segment sort within the _PreprocessQuery method of the modeled query the screen collection is built on.

    1.  Define a modeled query under the entity data you want to display on the screen.

    2.  Within the query designer, select the Write Code toolbar button, select the <queryName>_PrepocessQuery method and add the following code:

    query = query.OrderBy(c => c.Country).ThenBy(c => c.City);
    

    3.  Create your screen using the query created in step #2.

    HTH

    For LightSwitch Beta 2 this work around only works with the editable grid, NOT the list detail. 

    VB syntax:

    query = From c In query Select c Order By c.Country, c.City
    
    

    Lack of support for multiple sort terms is a significant bug that will hopefully be fixed soon.

     

  • Sunday, May 15, 2011 12:54 AM
     
      Has Code

    Hi Mark,

    The "workaround" *should* work in any PreProcessQuery method, but maybe you need to use the VB equivalent of snomis's code, instead of what you showed above (which must suffer from the same bug as doing it in the query designer).

    Try:

      query = query.OrderBy(Function(c) c.Country).ThenBy(Function(c) c.City)

    Yann

  • Sunday, May 15, 2011 2:35 AM
     
     
    Hi Yann,

    I just provided the VB syntax as a help to those using VB. The bug we're speakiing of has nothing to do with using VB or C# but is a bug in the underlying architecture of LightSwitch.

    As I said above the work around of sorting within a PreProcessQuery method works for an Editiable Grid but NOT for a List Detail screen. This is because the List Detail screen uses a List control in the leftmost column and it appears that the List control in particular ignores the PreProcessQuery method. One way to get around this is to create a List Detail screen and then to manually replace the List control with a Columns Layout control - which does honor the PreProcessQuery method.

  • Sunday, May 15, 2011 1:45 PM
     
     

    Hi snomis,

    Is this bug going to be fixed in RTM?

  • Monday, May 16, 2011 1:05 AM
     
     

    Mark,

    Sorry, I must have both misunderstood, & also given the wrong impression in my reply. I am aware that bug has nothing to do with either VB or C#, but LS itself.

    The direct translation from "query = query.OrderBy(c => c.Country).ThenBy(c => c.City);" is "query = query.OrderBy(Function(c) c.Country).ThenBy(Function(c) c.City)", not "query = From c In query Select c Order By c.Country, c.City".

    The only reason I pointed it out, was that I thought "query = From c In query Select c Order By c.Country, c.City" *might* actually suffer from the same bug as using a multi-segment query in the query designer.

    I wasn't aware, however, that a List control did not "honor" the PreProcessQuery, so thanks for pointing that out. This seems to be a separate bug than the one the team already knows about, the one that the PreProcessQuery workaround was provided for.

    Have you enetered a bug report on Connect for the List control bug that you've discovered?

    https://connect.microsoft.com/site1231/feedback/CreateFeedbackForm.aspx?FeedbackFormConfigurationID=4841&FeedbackType=1

    Yann

  • Monday, May 16, 2011 1:55 AM
     
     

    Ran into this today also.  But think it goes deeper.  I can't get a single sort to work either.  If I sort by "Id" on the edit query of the screen, it does not sort.  Screen is a editable grid.  Nothing seems to sort.  Seems the grid overwrites the sort.  Even doing the PreProcess thing does not help.  Same result in Editable grid screen and Search screen.  Will try List screen.

     [edit]  Now not sure what is happening.  One list screen works find with multiple sort.  Another list screen does not even work with 1 sort. hmm 

  • Monday, May 16, 2011 1:46 PM
     
     

    For those who are having troubles getting a single or multiple sorts defined within a query working, can you make sure that you don't have any sorts defined in the persisted user settings?  I would suggest stopping your application, go to My Documents > Microsoft > LightSwitch > Settings, delete the folder for you application, and then rerun your application.

    http://social.msdn.microsoft.com/Forums/en/lightswitchgeneral/thread/f11eaa39-47d8-4423-a22f-169016abee3d

    Any user defined settings will override the sort defined by the query.

    HTH

  • Monday, May 16, 2011 6:44 PM
     
     

    @Somis:

    There needs to be a simple "standard" way for the user to restore the default sorting. 

    Users work with grid lists to quickly rearrange grid data.   Their requirements (and clear expectations) are to have Excel and Access like capability to sort and filter lists with the ability to reset the grid back to the default sort that was specified as part of their business requirements.

    How does LS accomplish this with B2 (with all bug work arounds) and with RTM?

     

  • Tuesday, May 17, 2011 12:15 AM
     
     

    Hi Garth,

    I ABSOLUTELY agree!

    We CANNOT be asking users to exit the application, find a folder, & then delete it, to restore "default" sorting.

    I REALLY hope this is "fixed" before RTM.

    Yann

  • Tuesday, May 17, 2011 3:10 AM
     
     
    At least have ability in code to ignore any user settings on a grid, as sometime sort order can matter (i.e. account list with running balance needing to be sorted by Date ThenBy ID).
  • Tuesday, May 17, 2011 1:31 PM
     
     
    If the sort order is a critical piece to how the data is presented, I would suggest disabling the 'Supports Sorting' option on the screen query that backs the screen.  This will allow you to define a sort for the query but will disallow your end users from changing the sort through the UI.