This is a migrated thread and some comments may be shown as answers.

Avoid sorting when adding row

1 Answer 19 Views
GridView
This is a migrated thread and some comments may be shown as answers.
QuizzBox
Top achievements
Rank 1
QuizzBox asked on 18 Jun 2018, 12:52 PM

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) ?

Thanks

Regards 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 19 Jun 2018, 10:23 AM
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. 

Regards,
Dess
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.
Tags
GridView
Asked by
QuizzBox
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or