Avoid sorting when adding row

2 posts, 0 answers
  1. QuizzBox
    QuizzBox avatar
    93 posts
    Member since:
    Jan 2011

    Posted 18 Jun 2018 Link to this post

    Hi Telerik team :)

    I have a gridview with a list of persons.

    I sort this list on the name of persons when i click on column header.

    Now, when i click on a row to add a new person, when i end-edit the row, the new person is automaticaly sorted with the rest of the list.

    I don't want this behavior.

    I'll prefer that the new person stays in bottom of list with the list already sorted.

    So is there a way to avoid the sort when add a row without modifying the current list display (even if sorted) ?






  2. Dess | Tech Support Engineer, Sr.
    Dess | Tech Support Engineer, Sr.  avatar
    4127 posts

    Posted 19 Jun 2018 Link to this post

    Hello, Jean-Marc,  

    Let me please explain in details how the editing mechanism in RadGridView works. By default, no editor is available in the grid. If you double click a cell or press F2 when a certain cell is selected, RadGridView activates the relevant editor for that cell and RadGridView enters edit mode. After you enter the desired value in the editor you can commit the value by pressing the Enter key or navigate to another cell. Pressing the Escape key will cancel the edit operation. Note that once the editor's value is committed, the underlying DataBoundItem is updated accordingly. This is the designed behavior. Have in mind that once the grid is sorted by a certain column, it orders the rows considering the applied SortDescriptor and the cells' values belonging to this column. The SortDescriptor is responsible for keeping the available rows sorted according to the applied criteria. That is why when you add a new row or edit an existing one, they are placed at the correct index according to the applied sorting.

    A possible solution is to use the custom sorting functionality where you can fully manage how the rows are ordered:  https://docs.telerik.com/devtools/winforms/gridview/sorting/custom-sorting. Alternatively, RadGridView allows you to prevent the built-in data sorting operation but keep the sorting life cycle as it is, e.g. UI indication, SortDescriptors and events remain. This is controlled by the MasterTemplate.DataView.BypassSort property which default value is false. This means that RadGridView won't perform the sorting if you set it to true. This may be suitable for cases in which you bound the grid to a DataTable and you want to apply the sort direction to the DataTable, not to the grid itself. A sample code snippet is available in the following help article: https://docs.telerik.com/devtools/winforms/gridview/sorting/basic-sorting 

    I hope this information helps. If you have any additional questions, please let me know. 

    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top