Sort w/ TempTableAdapter
 
Forums / SmartComponent Library - Developer Forum / Sort w/ TempTableAdapter

Sort w/ TempTableAdapter

7 posts, 0 answered
  1. Roger Blanchard
    Roger Blanchard avatar
    413 posts
    Registered:
    29 Jun 2018
    15 Aug 2019
    Link to this post
    We are using the following code to try and sort by LastName and FirstName.

    The QuerySort does not appear to do anything. I added the UpdateSortIndicator and now the records are sorted by LastName. 

    What does the QuerySort actually do?

    Is there a way to force sorting by multiple columns?

    CustomerTempTableAdapter:QuerySort = "BY eCustomer.LastName BY eCustomer.FirstName".
    CustomerDataBrowser:UpdateSortIndicator ("eCustomer.LastName").
      
    CustomerTempTableAdapter:TempTableHandle = CustomerTable:Customer_TableHandle.
    CustomerTempTableAdapter:RetrieveData().
  2. Mike Fechner
    Mike Fechner avatar
    342 posts
    Registered:
    14 Sep 2016
    16 Aug 2019 in reply to Roger Blanchard
    Link to this post
    Hi Roger, after the initialization of the SmartTempTableAdapter (e.g. calling RetrieveData) setting QuerySort will cause the Query to be ordered by the provided criteria.

    https://youtu.be/CJ6ceITC8L4

    I cannot follow why you needed to call the UpdateSortIndicator to get data sorted. We don't let the Grid sort at all - so the sort indicator is just an ... indicator for the user. As you can see on my video, when I click the buttons that update the QuerySort property the sort indicators on the grid are not updating - but the data is sorted. 

    I have played with adding the call to the UpdateSortIndicator to the SmartTempTableAdapter. This seems to work. So I may be having this added to a future release (this is not yet in the video). 

    Have you done anything to enforce that the grid is sorting? 

    By default we're doing this here in SmartDataBrowser to ensure the query in the Adapter is solely responsible for sorting.

    THIS-OBJECT:DisplayLayout:Override:HeaderClickAction = HeaderClickAction:ExternalSortMulti .
  3. Roger Blanchard
    Roger Blanchard avatar
    413 posts
    Registered:
    29 Jun 2018
    16 Aug 2019 in reply to Mike Fechner
    Link to this post
    Let me take another look. From what I was seeing the QuerySort was not doing anything. Maybe it is where it is being called. I was calling it after RetrieveData but in the FormLoad event. Maybe I should move that to the form constructor.

    I will also look at the HeaderClickAction and confirm it is set to ExternalSort

    Thanks

  4. Roger Blanchard
    Roger Blanchard avatar
    413 posts
    Registered:
    29 Jun 2018
    16 Aug 2019 in reply to Mike Fechner
    Link to this post
    Okay, it looks like when you drop a SmartDataBrowser onto a form the SortIndicator is automatically set for the column that makes up the unique primary index. When the form is opened at runtime the sort indicator for that column is automatically setting the QuerySort of the adapter. In my case the unique primary index is CustomerNum so the querysort was set to BY eCustomer.CustomerNum. If I then try to set QuerySort at runtime it is being ignored...I am guessing it is overwritten by the column with the sort indicator set.

    I then went into the designer and made sure the SortIndicator was set to None. Now, at runtime if I set QuerySort = "BY eCustomer.LastName BY eCustomer.FirstName" it does sort by that but the QuerySort is still overwritten with "BY eCustomer.LastName BY eCustomer.FirstName BY eCustomer.CustomerNum".

    For some reason the field that makes up the primary index is appended to the query sort. Does this sound like correct behavior?

    In watching your video it does not appear to do this.

  5. Roger Blanchard
    Roger Blanchard avatar
    413 posts
    Registered:
    29 Jun 2018
    16 Aug 2019 in reply to Roger Blanchard
    Link to this post
    As a follow up. Once I click a column to sort the QuerySort is set by that event and then assigning the QuerySort in code is ignored.
  6. Mike Fechner
    Mike Fechner avatar
    342 posts
    Registered:
    14 Sep 2016
    16 Aug 2019 in reply to Roger Blanchard
    Link to this post
    Any chance you can produce a reproducible? That would require debugging. But I really don't see why the default index sort should be appended to the QuerySort string. 
  7. Roger Blanchard
    Roger Blanchard avatar
    413 posts
    Registered:
    29 Jun 2018
    16 Aug 2019 in reply to Mike Fechner
    Link to this post
    I will work on a repro. 

    >>But I really don't see why the default index sort should be appended to the QuerySort string

    I do not think it does. I did not update the post. That was due to the column being setup with a Sort Indicator.

    The bigger issue is once you sort a column by clicking a column header the QuerySort no longer does anything. I have to clear the SortIndicator by calling UpdateSortIndicator and passing a blank.

    /* Roger Blanchard / Osprey Retail Aug 16, 2019
       Clear out any SortIndicator or our QuerySort will be ignored
      */  
    CustomerDataBrowser:UpdateSortIndicator("").
      /* Roger Blanchard / Osprey Retail Aug 16, 2019
       Lets force the record to be sorted BY LastName, FirstName and then CustomerNum
      */
    CustomerTempTableAdapter:QuerySort = "BY eCustomer.LastName BY eCustomer.FirstName BY eCustomer.CustomerNum".
7 posts, 0 answered