Grid re-sorts itself after item in grid is selected

Certified Senior Developer

I have a simple interface rule that displays a grid of items sorted by an expiration date. The grid uses a query rule and a CDT for the items listed. My issue is that once the user selects one of the items, that item drops to the bottom of the list. Any idea why it would do this? I don't have any errors; the query rule does not include a 'sort by' and the selection part works just fine. I would also like the user to be able to sort on the other columns (which doesn't work now) but the most troubling issue is that the selected item moves to the bottom of the grid.

GridResortIssue.txt

OriginalPostID-225683

OriginalPostID-225683

  Discussion posts and replies are publicly visible

  • 0
    Certified Lead Developer
    As far as I remember, the issue with items shifting around on a paging grid when using the grid controls has something to do either with the data set not containing a unique ID (ie PKID), and/or no default SortInfo. To help yourself gain more insight into what's happening "in the gears", I always suggest adding a "DEBUG" paragraph field right above the paging grid, and point the "value:" at your dataSubset, so you can observe how it changes when items are selected.

    As far as sorting on your columns, I don't see any obvious issues in your current setup (but only after a quick look), though I need to point out that it's really intended to be run where the dataSubset is itself a live query which passes through the pagingInfo variable, instead of what you've done where the whole data set is loaded in one variable and then "datasubsetized" into a different one. That being said, if it's required to be that way you should be able to get it to work. The trick I mentioned above might help with this too.

    And an unsolicited suggestion: I notice you're validating against the user selecting more than one entry. I've developed the following trick to automate (as much as possible) the selection of just one row in the first place, so that you shouldn't need any validation in the future. This works in pretty much every SAIL paging grid I've tried it in: screencast.com/.../vSAewTmo77
  • 0
    Certified Lead Developer
    I'd recommend paying particular attention to mschmitt's last paragraph and the example provided. If you add a debug field pointing to your local!gridSelection you will probably notice that selecting a row will wipe the pagingInfo and therefore your sort order will reset to that of the original query. I've seen this behaviour for many years and assume it is on a bug list somewhere....
  • 0
    Certified Senior Developer
    Thanks for the great suggestions! I'm not quite sure how to add a DEBUG paragraph but I understand what you're saying. I'll give it a try.
  • 0
    Certified Lead Developer
    This is literally just a!paragraphField(value: local!datasubset) somewhere on your interface. You can also add fields to show your gridSelection value. Sometimes it makes more sense when you can see your data and how it behaves for each re-evaluation.
  • 0
    Certified Lead Developer
    Yup, i just meant an a!paragraphField, and in my case i always make the label something hard to miss like "DEBUG:" - something eyecatching to help you remember to comment it out later.
  • 0
    Certified Senior Developer
    Just updated my SAIL code as suggested and the selected item is still resorting. I initially had an 'ORDER by agreementdescription, expiredDate' in my view which I thought was conflicting with my 'sortInfo' in the interface rule so I removed that from my view - but the grid still resorts. Is there a way to force it to stay sorted by the expireddate? The PK on the table used in the view is on the id. Do I need to add an index on the table?
  • 0
    Certified Senior Developer
    Finally stopped the grid from resorting after a selection (added back the ORDER by in my view - but switched it so the records in the view sorted by expireddate first and then description). I can't enable any sorting on the grid by the user now but at least it's not resorting after a selection. Trial and error....
  • 0
    Certified Lead Developer
    Out of curiosity - did you try passing the pagingInfo directly into the query, as opposed to pre-querying and then doing toDataSubset? Depending on the situation I'm guessing this could affect the outcome. If you want to see what it would do before dramatically editing your code, though, you might consider just doing the query in a new/unsaved Expression Rule to see the direct output.
  • 0
    Certified Lead Developer
    You should try passing your pagingInfo (that includes your sort) to your query rule call in load. Your original dataset will then match the sorting in your todatasubset() call.... hopefully
  • 0
    Certified Senior Developer
    I did but kept getting errors so I went back to my last version. Thanks again for your help though!