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

How to save sorted state of detail view?

2 Answers 34 Views
Grid
This is a migrated thread and some comments may be shown as answers.
zel
Top achievements
Rank 1
zel asked on 14 Dec 2012, 06:32 AM
Hello Everyone,

Is there a way to save the sorted state of detail table?

I have 2 detail tables and AllowSorting is set to true and EditMode = Inplace. When I sort the detail table and edited one row, the detail table rebinds again and the row that I was trying to edit was not the original one.

Attached are the image for reference and code snippets for Sort Command.  
protected void gridCPDiag_SortCommand(object source, GridSortCommandEventArgs e)
        {
            GridTableView tableView = e.Item.OwnerTableView;
            if (e.Item.OwnerTableView.Name == "Detail2" && e.SortExpression == "VisitFrequency")
            {
                e.Canceled = true;
                GridSortExpression expression = new GridSortExpression();
                expression.FieldName = "VisitFrequency";
                if (tableView.SortExpressions.Count == 0 || tableView.SortExpressions[0].FieldName != "VisitFrequency")
                {
                    expression.SortOrder = GridSortOrder.Descending;
                }
                else if (tableView.SortExpressions[0].SortOrder == GridSortOrder.Descending)
                {
                    expression.SortOrder = GridSortOrder.Ascending;
                }
                else if (tableView.SortExpressions[0].SortOrder == GridSortOrder.Ascending)
                {
                    expression.SortOrder = GridSortOrder.None;
                }
                tableView.SortExpressions.AddSortExpression(expression);
                tableView.Rebind();
            }
        }

Any help is greatly appreciated. Please let me know what else you need from my code.

Thanks!
Zel

2 Answers, 1 is accepted

Sort by
0
zel
Top achievements
Rank 1
answered on 17 Dec 2012, 03:55 AM
Hello Everyone,

Any update or resolution on my issue. No one seems to notice this.

Thanks!
Zel 
0
Marin
Telerik team
answered on 18 Dec 2012, 11:44 AM
Hi,

 The grid keeps track of the index of the record in edit mode only for the current page. However when you perform sorting all the records are reordered and the record that is in edit mode may go on another page and no longer be visible. Between postbacks the grid knows that for example the third record on the current page is in edit mode. However when you sort the third record is no longer the same which causes the problem. That's why when you perform a sort operation the grid does not preserve the edited row by default. So after sorting no record should remain in edit mode because the detail rebinds and the records are recreated.
If you need you can manually persist the index of the record in edit mode and then place the record back in edit mode after the sort operation is executed. Of course in this case the edited record should be on the same other wise you will need to navigate to the relevant page if you need to show the same record in the mode.

Kind regards,
Marin
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
zel
Top achievements
Rank 1
Answers by
zel
Top achievements
Rank 1
Marin
Telerik team
Share this question
or