2

I have a scenario where currently a telerik radgrid (webforms) is used on a page which currently allows telerik to control the paging, sorting, filtering etc. However I have noticed as this uses the default telerik behavior for these tasks it does it all in memory so nothing is lazy loaded.

In this instance there is a situation where upwards of 300,000 rows (1.2 million at one point), are returned and this seems to re-query every time it is paged, sorted etc which is cripplingly slow.

Now I want to push these concerns to the server side, as currently the db interactions happen via linq to sql so I would like to instead of just using the base (300k query) take the composable IQueryable and then add the filtering, sorting and paging logic in from the telerik control, as the data all seems to be there, I just dont know when I should be intercepting the controls data bindings to force it to only get the data it needs.

From my current investigating there is an OnSortCommand method, which seems to be triggered when a sort is requested, so I assume from there I can get the SortExpression and put that into the linq query, then there is also a FilterExpression which I can use to constrain the results in the query, and then finally there is the PageSize and CurrentPageIndex variables which allow me to work out how many pages I should be bringing back.

So all the data needed to constrain the queries exists there, however I dont know when I should be intercepting the binding process as currently if I were to intercept OnDataBinding and override the DataSource to take into account the filterexpression and paging details (as sorting is not available until a sorting command to my knowledge) then I would expect there to be only a query to pull back 50 rows (or whatever the page size is), however it seems to do the 300k query, then afterwards do the 50 row query, so I am confused as to if I should be intercepting another event or method.

If anyone could point me in a direction of what I should be intercepting/overriding I would be VERY grateful, as the documentation provided by telerik for this is not that great.

== Edit ==

Just to be a bit more specific about the scenario, I am not really wanting to internally create the datasource (advanced databinding) as they need to be re-usable components, so the control is created on the aspx page, then in the code behind on page load it will set the DataSource with an IQueryable object describing the query (the 300k one), then within this inherited control I want to be able to then use the filterexpression, sortexpression, pagesize and pageindex to append to the query. So the data source is provided external to this class.

== Edit 2 ==

Just to draw more attention to the crux of my confusion, one of the most baffling things for me currently is the fact that my grid is doing 3 queries:

  • one is to get the virtual row count from the IQueryable, that is fine returns the count as expected
  • the second is the unaltered 300k query, I dont have a clue why this is occuring
  • the third is the altered query which brings back 50 rows

As I have overridden the OnDataBinding method I do not know where else it is going to pull this data from, as the DataSource is updated before the end of the OnDataBinding to then have the altered IQueryable. So it is at some point doing something in Telerik Land to fetch this data when I dont want it to, as why do a huge query to get all data, then just query the minimal amount later? makes no sense...

Grofit
  • 17,693
  • 24
  • 96
  • 176

1 Answers1

1
  1. Custom Pagging
  2. Custom Sorting :- Please check "RadGrid2" in this link.
  3. Custom Filtering

To achieve this thing i should suggest do not use AdvanaceDataBinding because it is very hard to manage with this.

Please Try to bind Radgird as we bind asp:Gridview.

Jayesh Goyani
  • 11,008
  • 11
  • 30
  • 50
  • Thanks for the links, I have already viewed them and am basing some of the current implementation on that, however the examples are 1 specific scenario, such as accessing the sort criteria within a sorting event, what if I need to get the sort expression outside of that event? such as when the page index changes, and I dont have access to the events `SortExpression` data. Also I am inheriting my own LazyLoadedRadGrid from the original RadGrid so I am look at overriding methods not just intercepting the events, and that is where the documentation seemed to be lacking, +1 for concise links! – Grofit Jul 04 '13 at 14:05
  • 1
    For that you have to store this information in viewstate. For ex: we are save the sorting direction in viewstate in asp:girdview.http://stackoverflow.com/questions/702600/sorting-and-paging-with-gridview-asp-net – Jayesh Goyani Jul 04 '13 at 14:09
  • Oh right if that is the *best practice* will do that for the sorting. – Grofit Jul 04 '13 at 14:20
  • Is `OnDataBinding` the *ONLY* point where the radgrid goes to the DB? or can it occur at other points? (such as `OnSortCommand` and `OnPageIndexChanged`) As currently it seems to be doing 2 queries even though `OnDataBinding` is only been hit once, although I do then delegate to `base.OnDataBinding(e);` – Grofit Jul 04 '13 at 14:53
  • Can you please look in this link, may be it will help you?http://www.telerik.com/help/aspnet-ajax/grid-client-side-binding-to-wcf-service-adonet-dataservice.html Let me know if any concern. – Jayesh Goyani Jul 05 '13 at 08:56