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...