locked
Sorting Query Trouble RRS feed

  • Question

  • Try as I might I cannot get sorting to work on my screen.
    I have an child entity "orders" that shows the orders made for the parent entity when a specific parnt name is selected.
    On the screen I have several tabs showing the grids for orders but none of my table or screen queries is sorting the grids properties in the order defined by a query.
    I am trying to sort by a boolean "Reviewed" check box and put the ones checked in order alphabetically by string "name".
    Then the ones that are not checked or null in alphabetical order. Since no query would even function for some unknow reason.
    I tried just hitting the sort at the top of the "reviewed" column but it only orders them by True false null and not alphabetically.
    Note too Name comes from a related table one "Name" to many "Orders".
    Can you think of anything I might be doing wrong?
    Tuesday, March 3, 2015 12:35 AM

Answers

  • I got the query working but now I can't show the screen in the tasks section of screen browsing because it now requires a passed parameter from the order so the only navigation is to it is from adding a new order and then it filters out all other patients. I will have to duplicate this screen and make a version without the Revived By tab or better yet split the screen design into two screens one Times and one MAR Creation. Possibly considering a Third for those who only do review and not generating MARS called the Review Screen for Professionals such as Nurse Administrators or Pharmacy .
    • Marked as answer by reigh7 Monday, March 16, 2015 1:01 AM
    Monday, March 16, 2015 1:01 AM
  • You could make the parameter optional and check for nulls before using it to have a dual purpose screen.

    Dave


    Dave Baker | AIDE for LightSwitch | Xpert360 blog | twitter : @xpert360 | Xpert360 website | Opinions are my own. For better forums, remember to mark posts as helpful/answer.

    • Marked as answer by reigh7 Monday, March 16, 2015 7:18 PM
    Monday, March 16, 2015 9:18 AM
  • I can also do this so that only people with permissions to review can see un reviewed medications. see this video
    • Marked as answer by reigh7 Thursday, March 19, 2015 10:54 PM
    Thursday, March 19, 2015 10:54 PM

All replies

  • Hi,

    It sounds like you are using the desktop client so take a look at this Manipulate sort and column settings.

    That will give you some control over sorting.

    Dave


    Dave Baker | AIDE for LightSwitch | Xpert360 blog | twitter : @xpert360 | Xpert360 website | Opinions are my own. For better forums, remember to mark posts as helpful/answer.

    Tuesday, March 3, 2015 2:57 PM
  • Make sure you are using your custom query that contains the sort logic for Orders on the screen.  You will have to add this manually.  The default child collection added to the designer will be the base table query not your custom query.  You may also be able to select the collection and choose the query source.  Make sure to select your custom query as the source.  If you are using the correct query as the source for the screen collection, and the query itself is configured properly, I assure you it works.
    Tuesday, March 3, 2015 8:28 PM
  • I think you are on the right track here. I want to edit the child entity manually but I don't know how. I went to the edit query for the child entity on the screen but there is no option to add code to manually sort or filter for a screen query in VS LS 2012. Ideally I would like to sort all instances of the grid control by Monogram or MonogramC(a calculated field) AND by Reviewed(a boolean) OR just filter the specific Grid under one of the tabs the Grid is named MedicationOrderDetails5.

    How do I do this I am not sure about even the code to use I have thought of adding the following to the screen code. How would you code something like this?

    using System;
    using System.Linq;
    using System.IO;
    using System.IO.IsolatedStorage;
    using System.Collections.Generic;
    using Microsoft.LightSwitch;
    using Microsoft.LightSwitch.Framework.Client;
    using Microsoft.LightSwitch.Presentation;
    using Microsoft.LightSwitch.Presentation.Extensions;
    //added to alow OLE DB data set code
    using System.Data;
    //using System.Data.OleDb;
    //added for Process Start statement
    using System.Diagnostics;
    using System.Linq.Expressions;
    
    namespace LightSwitchApplication
    {
        public partial class TimesAndMARs
        {
            partial void TimesAndMARs_InitializeDataWorkspace(List<IDataService> saveChangesTo)
            {
                // Write your code here.
                //MedicationOrderDetails5
            }
            
            partial void Reviewed_Filter(ref Expression<Func<MedicationOrderDetail, bool>> filter)
            {
                filter = e => e.Reviewed != true;
            }
    
            partial void OrderedByMonoramCalculatedField_PreprocessQuery
                (short? MonogramC, ref IQueryable<MedicationOrderDetail> query)
            {
                query = (from myOrder in query
                         where myOrder.MonogramC.Count() > 0
                         orderby myOrder.MonogramC ascending
                         select myOrder);
            }
        }
    }


    • Edited by reigh7 Wednesday, March 4, 2015 7:22 PM
    Wednesday, March 4, 2015 7:20 PM
  • For some reason it is still not sorting right I added a screen query but it always wants to sort by ID which I did not specify before it sorts by Monogrram.TradeGenericName
    Wednesday, March 4, 2015 9:17 PM
  • This is the code I tried for a reset button.

            partial void ResetReviewedSort_Execute()
            {
                // Write your code here.
    
                var p = VsExportProviderService.GetExportedValue<IServiceProxy>();
                string name;
    
                name = "MedicationOrderDetails.Monogram.TradeGenericNames.SortSettings";
                p.UserSettingsService.GetSetting<SortDescriptionCollection>(name);
                p.UserSettingsService.ResetSetting(name);
    
                name = "MedicationOrderDetails.Monogram.TradeGenericNames.ColumnSettings";
                p.UserSettingsService.GetSetting<List<ColumnSetting>>(name);
                p.UserSettingsService.ResetSetting(name);
    
                name = "SearchProducts.TradeGenericNames.SortSettings";
                p.UserSettingsService.GetSetting<SortDescriptionCollection>(name);
                p.UserSettingsService.ResetSetting(name);
    
                name = "SearchProducts.grid.ColumnSettings";
                p.UserSettingsService.GetSetting<List<ColumnSetting>>(name);
                p.UserSettingsService.ResetSetting(name); 
    
    
            }

    Wednesday, March 4, 2015 10:40 PM
  • I changed to a passed parameter Query and am now having much different problems. See Post
    Saturday, March 14, 2015 1:46 AM
  • I got the query working but now I can't show the screen in the tasks section of screen browsing because it now requires a passed parameter from the order so the only navigation is to it is from adding a new order and then it filters out all other patients. I will have to duplicate this screen and make a version without the Revived By tab or better yet split the screen design into two screens one Times and one MAR Creation. Possibly considering a Third for those who only do review and not generating MARS called the Review Screen for Professionals such as Nurse Administrators or Pharmacy .
    • Marked as answer by reigh7 Monday, March 16, 2015 1:01 AM
    Monday, March 16, 2015 1:01 AM
  • You could make the parameter optional and check for nulls before using it to have a dual purpose screen.

    Dave


    Dave Baker | AIDE for LightSwitch | Xpert360 blog | twitter : @xpert360 | Xpert360 website | Opinions are my own. For better forums, remember to mark posts as helpful/answer.

    • Marked as answer by reigh7 Monday, March 16, 2015 7:18 PM
    Monday, March 16, 2015 9:18 AM
  • How do I make a parameter optional?

    I have mainly been using the LightSwitch RAD environment to create parameters but do know you can write them in code just not sure where all to include them. I am still studying the syntax here.

    Monday, March 16, 2015 7:18 PM
  • I can also do this so that only people with permissions to review can see un reviewed medications. see this video
    • Marked as answer by reigh7 Thursday, March 19, 2015 10:54 PM
    Thursday, March 19, 2015 10:54 PM