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

Sorting Issues

6 Answers 272 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rick
Top achievements
Rank 1
Rick asked on 06 Jan 2012, 12:59 AM
Version:  5.3.11.1116
Grid properties in aspx:
<telerik:RadGrid runat="server" ID="Grid" PageSize="20" Width="100%" EnableViewState="false" CssClass="basicList">
<MasterTableView  AutoGenerateColumns="false" AllowPaging="true" AllowCustomPaging="true" AllowSorting="true" DataKeyNames="ID">

We are using custom sorting and paging, and filtering.  We retrieve data via a stored procedure that returns the data sorted (but then the grid also sorts... see #2). 

We are experiencing two problems:
1)
Event sequence is causing 2-3 calls to the database on sorting or filtering -- first from NeedDataSource, and then from the sort or filter.  This raises scalability concerns.  How can we resolve?  When I use the following in the NeedDataSourc event as suggested in another post, the sort doesn't happen:
      if (e.RebindReason != GridRebindReason.PostbackViewStateNotPersisted)
            {
                LoadData(false);
            }
How can we retrieve data once and only once in all scenarios (initial load, sorting, fitlering, page size change, page index change, etc.)?

2)  In addition to reloading the data on sort, we are seeing an incorrect sort in at least one scenario.  Our default sort is descending on a datetimeoffset datatype column.  On page load, sort appears to be correct.  When one clicks on that column header, it correctly sorts ascending on those dates.  But when the column is clicked again to sort descending, it does not sort correctly --
e.g., it sorts a range from 12/08/2011 5:05 PM down to  12/05/2011 3:39 PM
then a range from  12/29/2011 3:33 PM down to  11/11/2011 4:58 PM,
and then a range from 01/04/2012 2:36 PM down to 01/04/2012 2:31 PM
The database is returning the data correctly sorted, so the grid is clearly resorting. 
Clicking again then correclty sorts by our default descending sort.  In this third state, the column now shows no sorting icon, so it's presumably correct because the grid is not resorting incorrectly at this point. 
But I haven't been able to find where or why.
How can we eliminate this incorrect sort?  Why & where/when (what event) is it happening?


Our LoadData() method accepts a boolean rebind parameter and calls Grid.Rebind() if true.

We have coded to the following events:
Grid.PageIndexChanged:  Calls LoadData(true) 
Grid.PageSizeChanged:  Calls LoadData(true)
Grid.SortCommand:  Calls LoadData(true)
Grid.ItemCommand: Calls LoadData(false) and Grid.Rebind()
Grid.ItemDataBound
Grid.NeedDataSource: Calls LoadData(false)

Page_Load: If not a postback, calls LoadData(false)

I can send this page code privately if needed.


Thank you.

6 Answers, 1 is accepted

Sort by
0
Johny
Top achievements
Rank 1
answered on 06 Jan 2012, 07:48 AM
I've had problems with grid's own filtering - it may be the same case as sorting i think (i also have a stored procedure that returns sorted, filtered and paged data). The grid's own filtering is wrongly implemented and sometimes results in case, that data you got from DB are not rendered in grid because it filters them out (this happens especially with datetime data type). I have a workaround to set Grid.mastertableview.filterexpression = string.Empty; before assigning the datasource to the grid and it works ok, all data I got from DB are displayed... Maybe you should try to clear the grid column's sorting properties before assigning the data source (and then change it back, because the columns wouldn't display they are being filtered)
0
Srivathsan
Top achievements
Rank 1
answered on 25 Jan 2012, 05:58 PM
We are also experiencing the same weird behavior while sorting which you have clearly mentioned. Hope someone from Telerik gives a solution/workaround to this issue.
0
Marcus
Top achievements
Rank 1
answered on 27 Jan 2012, 03:37 PM
We're also experiencing sort of this behaviour, but I'm not sure if you're doing it right :).

We're trying to upgrade our application to .NET 4 and latest version of Telerik. Before this the opposite scenario you're describing, i.e.

if (e.RebindReason != GridRebindReason.PostbackViewStateNotPersisted)
{
   LoadData(true);
}

was actually populating the datasource property correctly, but before this happened the needdatasource was called where the above statement evaluated to false and events for sorting, filtering and paging was raised and after that needdatasource event was fired again where the data was fetched and loaded into the datasource property.

According to my investigations these problems was introduced in the 2011.2.712 together with a lot of other changes which resulted in a lot of weird behaviours in our application.

Can someone from Telerik explain what changes you may have done in the 2011.2.712 release that affected the behaviour of my described scenario in regards to enableviewstate=false, GridRebindReason.PostbackViewStateNotPersisted and customer sorting, paging and filtering.
0
Veli
Telerik team
answered on 30 Jan 2012, 09:32 AM
Hi guys,

RadGrid will always sort your data by default. Sorting depends on the data type of the data field you are sorting. If you retrieve your data sorted every time and want to prevent built-in sorting in RadGrid, you have to disable it by setting RadGrid.MasterTableView.AllowCustomSorting = true. For more information on custom sorting in RadGrid, you can refer to the following online help topic:

Applying custom sort criteria

Veli
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
0
Marcus
Top achievements
Rank 1
answered on 30 Jan 2012, 09:54 AM
Hi,

We're already using AllowCustomSorting=true. Looking at your online help topic, it probably works, but it will hit the database multiple times when for example sorting, i.e. first NeedDataSource are called and then SortCommand are called. If DataSource property not are set in NeedDataSource the SortCommand won't be triggered!

I've submitted a ticket (506003) where I've included two sample applications which demonstrates above problem, please take a look at that for more information.

Thank you
0
Veli
Telerik team
answered on 30 Jan 2012, 10:33 AM
Hi Marcus,

As replied in the ticket, RadGrid requires proper databinding with disabled ViewState. Thus, when NeedDataSource fires on postback, you need to provide the grid with the same data the control used during the previous page life cycle. This will ensure the control is properly recreated and functions as expected. Failure to provide the appropriate data source to the control when it requires will cause improper control behavior and is not a supported scenario.

Veli
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
Rick
Top achievements
Rank 1
Answers by
Johny
Top achievements
Rank 1
Srivathsan
Top achievements
Rank 1
Marcus
Top achievements
Rank 1
Veli
Telerik team
Share this question
or