Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested answer

How to disable sorting on form grid

(0) ShareShare
ReportReport
Posted on by 115

Hi Everyone, 

                     I am working on a form where end user can add a new item in the form grid by clicking on 'Add New Line' button. The problem is when multiple items are added on the grid and the price of one of the items are changed, the grid re-sorts itself on the basis of ascending order. I want to disable this sorting feature. 

I have come across coding examples where we can sort fields according to ascending or descending order, but there is not a single one code snippet for disabling this feature. 

There is one override method called 'sort' but this method is no use of me as it only enables or disables the field header sorting. 

Then there is this following code which can be used for ascending descending sorting:

public void init()
{
    super();

    salesLine_ds.query().dataSourceTable(tableNum(SalesLine)).addSortField(fieldNum(SalesLine,         ConfirmedDLV), SortOrder::Ascending);
}

I want to disable sorting. please help !!!

  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 231,409 Most Valuable Professional on at
    RE: How to disable sorting on form grid

    Yes, you'll need a field with such a sequence. Creating a table index is a good idea, because it's benefitial for performance and it may be needed for other features mentioned below.

    When creating a new record, you'll need to provide a value for the field. One (easier) option is using CounterField property on the data source (see Form Data Source Properties for more information). Another option is assigning a value explicitly by yourself.

    Then you'll need to sort the data by this field. You can use Index property (on the data source), or you can add sorting in code.

  • 00030000036294D5 Profile Picture
    00030000036294D5 115 on at
    RE: How to disable sorting on form grid

    3. If you want to always show records in the order in which they're inserted, you need a field with such a sequence and sort by this field (instead of by ItemId).

    I think this is what I am looking for. What will I have to do for this ? Will I need to add a new field in the table and set it as my index. Currently, there is no index set on the table. The table is a custom table.

  • Martin Dráb Profile Picture
    Martin Dráb 231,409 Most Valuable Professional on at
    RE: How to disable sorting on form grid

    That's a different scenario - it's rather about what I mentioned in my first reply.

    You need to decide what you want to achieve.

    1. If you want to sort items by ItemId but not to re-execute the query (= sort items) when a price is updated, you need to stop re-executing the query. It's not clear why you're doing it.
    2. If you want items sorted by ItemId and you must re-run the query when updating a price, you need to explain that to users.
    3. If you want to always show records in the order in which they're insterted, you need a field with such a sequence and sort by this field (instead of by ItemId).
  • 00030000036294D5 Profile Picture
    00030000036294D5 115 on at
    RE: How to disable sorting on form grid

    Martin, let us understand the scenario once again.

    Suppose the end user adds three random items in the grid without keeping in mind their chronological order named 001, 005 and 003.

    The user updates the price of item 003 and press enter. As, he presses enter, the items resort themselves according to the ascending order. The item 001 sets itself on the first row, followed by items 003 and 005.

    The end user complains that this behavior is confusing for him. He wants that if the item 003 was at third row before updating the price, then it should have been at third place even after the value was updated.

    I simply want a solution for this problem, be it through sorting, or if you have a better solution through which I can achieve this. It would be highly appreciating Martin. I hope you have understood the scenario and problem now.

  • Martin Dráb Profile Picture
    Martin Dráb 231,409 Most Valuable Professional on at
    RE: How to disable sorting on form grid

    You confirmed that my understanding was correct but then you're claim something else.

    If my description above is correct, you want the same sorting that was used when then form was opened. You don't want to show the records any order that the database server decide to use at the moment, because that could be different.

    You should abandon the idea of "no sorting", because it doesn't make a good sense. You should rather think about what order you actually want. All we know so far is the one that you don't want.

  • 00030000036294D5 Profile Picture
    00030000036294D5 115 on at
    RE: How to disable sorting on form grid

    Yes Martin, I do not want them to be sorted after the form has been refreshed. Yes, They are sorted by ItemId.

  • Martin Dráb Profile Picture
    Martin Dráb 231,409 Most Valuable Professional on at
    RE: How to disable sorting on form grid

    If I understand it correctly, you're saying that if you open the form, items are sorted in a different way than after a refresh. You didn't mention any field, so let me assume that they're sorted by ItemId.

    When the form is refreshed, the query sorts items by ItemId, while you would like to use the sorting that was used when the form was open.

    Is that a correct description of your situation?

  • 00030000036294D5 Profile Picture
    00030000036294D5 115 on at
    RE: How to disable sorting on form grid

    Hi Martin,

                   Thank you very much for replying !  Martin, let me explain the scenario. This form is a customization for changing item costs and cost charges. There are two grids on the form. The left hand side grid is where we add items and their site, and the right hand grid is where the item prices and cost charges are populated.

    Suppose, there are three items on the left hand grid and the user has just updated a price of one of the items on the left hand side grid. As soon as, the price is updated, the screen refreshes and as screen refreshes, all items are sorted on the basis of ascending order.

    My task is to prevent this behavior. I want when the prices are updated, the items do not re-sorts and stays on the place where they were before updating prices.

  • Martin Dráb Profile Picture
    Martin Dráb 231,409 Most Valuable Professional on at
    RE: How to disable sorting on form grid

    It seems to me that you're asking a wrong question. You don't want a random order of records - I think you want a particular order, e.g. the order in which lines were created. Therefore you need a suitable field to sort by, e.g. something like the line number in order lines.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,409 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans