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

Issues with placement of new row when using default sorting

6 Answers 193 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Karen Grise
Top achievements
Rank 1
Karen Grise asked on 24 Aug 2011, 06:42 PM
I have a grid that I'm binding to an ObservableItemCollection and a separate toolbar that allows the user to perform Add, Delete, etc. operations on the data within the grid. The data going into the collection is not sorted. I'm setting the default sort on a column in the code behind. When I add a new row using the toolbar button or hitting Insert the new row is added underneath the last record in the ObservableItemCollection, not the end of the grid where I'd expect it to be. So the new row could show up anywhere within the grid. If I don't set the default sorting, it puts the row at the end. Is there a way to force the row to be inserted after the last record within the grid?

Also, I noticed when I don't set a default sort, then sort the grid on the client side I'm getting the same behavior. The insert it happening wherever the last item was put into the collection.

Thanks,
Karen

6 Answers, 1 is accepted

Sort by
0
Karen Grise
Top achievements
Rank 1
answered on 31 Aug 2011, 03:24 PM
No one has ran into this? I wouldn't think that I would have to sort the observable collection or rebind when sorting within the code. That seems to be overkill. What I really need to know is how do I force the grid to insert a new record under the last row within the grid?

Any help would be appreciated...

Thanks,
Karen
0
Nedyalko Nikolov
Telerik team
answered on 03 Sep 2011, 12:19 PM
Hello Karen Grise,

RadGridView has special UI for adding new row, but it is over the rows just below the header row. You can easily show this row by setting RadGridView.ShowInsertRow = true. Unfortunately there is no way to move this row after the last item.
Let me know if you need further assistance.

Greetings,
Nedyalko Nikolov
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Karen Grise
Top achievements
Rank 1
answered on 16 Sep 2011, 11:46 PM
Thank you, Nedyalko, for your response. I don't want to display the ShowInsertRow. The way the user interacts with the grid is through a toolbar above the grid. When the 'Add' button is clicked, a new row gets inserted into the grid calling the BeginInsert() method. I don't want to move the ShowInsertRow to the last item. I just want to insert a new row at the bottom of the grid and when default sorting is set, it inserts the new row randomly. Is there anything else I can try?

Thanks,
Karen
0
Accepted
Nedyalko Nikolov
Telerik team
answered on 26 Sep 2011, 01:52 PM
Hi Karen Grise,

Sorry for the late reply.
Unfortunately there is no way to this out-of-the box. There is a possible solution, which is a little bit tricky.
The problem comes from the fact that RadGridView reacts on every NotifyCollectionChanged with respect to sorting and grouping, therefore item is displayed on its correct position (according to sorting) (indeed this could looks like random position but it is not). Keeping this in mind you can workaround this by sorting your data manually and use RadGridView just to show current sorting (without RadGridView to be sorted). Then you will achieve the desired "insert" behavior.
For such example you can take a look at this online help topic.
Let me know if this doesn't help.

All the best,
Nedyalko Nikolov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Karen Grise
Top achievements
Rank 1
answered on 28 Sep 2011, 07:15 PM
Hi Nedyalko,

Thank you for responding. I understand what you're saying and you're right, the new row isn't randomly inserted. It would just appear to be this way to the user. As of right now, they're ok with it. I'll keep in mind yoyr suggestion and know that I have a workaround if the user's aren't happy with it.

Thanks again,
Karen
0
Jason
Top achievements
Rank 1
answered on 13 Jan 2012, 04:21 PM
I've had a similar issue.  When I add a new row to a grid bound to an EntityObservableCollection and call OnPropertyChanged for the collection, the row sort order is not respected.  If a call SortDescriptors.Reset() the proper sort order gets applied, but I'm not sure what is the best event to handle to call this.
Tags
GridView
Asked by
Karen Grise
Top achievements
Rank 1
Answers by
Karen Grise
Top achievements
Rank 1
Nedyalko Nikolov
Telerik team
Jason
Top achievements
Rank 1
Share this question
or