Hi,
I'm using a RadGrid with advanced data binding, sorting and custom paging.
For the custom paging I dynamically build my query to the database (with Linq) so that only the results for the current page are retrieved.
But in order for the sorting to be correct when using paging the sorting has to be incorporated in the query as well (and before the paging). I also do this dynamically because the columns of the grid are created dynamically. So I read the lambda function to be used as an argument for the sorting from a data source.
So far everything is fine. But! As the column in question contains strings the grid knows how to order the page alphabetically on this column. And it does!, on top of the sorting I incorporated in the query...
For example, let's say I have a grid with only one column, containing first names. And let's say the only first names in the database are "Alice", "Bob" and "Claire" and that the page size of the grid is 2. I define the lambda function for ordering first names such that they are ordered by length rather than by alphabet (something like x => x.Length).
Now if I would let the grid be ordered in ascending order on the first names column I would like to have the following result:
1st page: Bob, Alice. 2nd page: Claire.
However, the result is:
1st page: Alice, Bob. 2nd page: Claire.
It may not be immediately clear from this small example, but the result is that per page the records on it are exactly the records I want, but the order within the page is wrong due to unwanted extra automatic sorting, in this case in alphabetic order.
To be clear, I only use the NeedDataSource event and when creating the query for the data source I take care of the sorting and paging. I do not use the SortCommand event. I have tried this but I still couldn't get rid of the unwanted automatic sorting (this could very well be my inexpertice) and I started to have problems with my own implemented sorting to be one step behind. So when ASCending was requested you would get NONE, when DESCending was requested you get ASCending and when NONE was requested you get DESCending. This hase something to do with me reading from MasterTable.SortExpressions what sort is requested and using this information to dynamically get the right lambda function.
It would be really great if I could leave everything as I have it and only turn of the automatic sorting, without having to use the SortCommand event, because we have set up the project such that almost all code for using the grid is in seperate classes (such as a child class of RadGrid) so that a page using the grid only has to have minimal code (such as telling wich columns should be displayed, making the base query for the data source and define the lambda functions for sorting).
If it is unavoidable to use the SortCommand event please be very specific how this event and the NeedDataSource have to work together to avoid the sorting to be one step behind.
I rather have some extra code in the classes that take care of most things around the grid than any extra code in the pages using the grid because then I only have to write this code once instead of each time I use the grid on a page (which is going to happen a lot!).
Regards,
Mink
I'm using a RadGrid with advanced data binding, sorting and custom paging.
For the custom paging I dynamically build my query to the database (with Linq) so that only the results for the current page are retrieved.
But in order for the sorting to be correct when using paging the sorting has to be incorporated in the query as well (and before the paging). I also do this dynamically because the columns of the grid are created dynamically. So I read the lambda function to be used as an argument for the sorting from a data source.
So far everything is fine. But! As the column in question contains strings the grid knows how to order the page alphabetically on this column. And it does!, on top of the sorting I incorporated in the query...
For example, let's say I have a grid with only one column, containing first names. And let's say the only first names in the database are "Alice", "Bob" and "Claire" and that the page size of the grid is 2. I define the lambda function for ordering first names such that they are ordered by length rather than by alphabet (something like x => x.Length).
Now if I would let the grid be ordered in ascending order on the first names column I would like to have the following result:
1st page: Bob, Alice. 2nd page: Claire.
However, the result is:
1st page: Alice, Bob. 2nd page: Claire.
It may not be immediately clear from this small example, but the result is that per page the records on it are exactly the records I want, but the order within the page is wrong due to unwanted extra automatic sorting, in this case in alphabetic order.
To be clear, I only use the NeedDataSource event and when creating the query for the data source I take care of the sorting and paging. I do not use the SortCommand event. I have tried this but I still couldn't get rid of the unwanted automatic sorting (this could very well be my inexpertice) and I started to have problems with my own implemented sorting to be one step behind. So when ASCending was requested you would get NONE, when DESCending was requested you get ASCending and when NONE was requested you get DESCending. This hase something to do with me reading from MasterTable.SortExpressions what sort is requested and using this information to dynamically get the right lambda function.
It would be really great if I could leave everything as I have it and only turn of the automatic sorting, without having to use the SortCommand event, because we have set up the project such that almost all code for using the grid is in seperate classes (such as a child class of RadGrid) so that a page using the grid only has to have minimal code (such as telling wich columns should be displayed, making the base query for the data source and define the lambda functions for sorting).
If it is unavoidable to use the SortCommand event please be very specific how this event and the NeedDataSource have to work together to avoid the sorting to be one step behind.
I rather have some extra code in the classes that take care of most things around the grid than any extra code in the pages using the grid because then I only have to write this code once instead of each time I use the grid on a page (which is going to happen a lot!).
Regards,
Mink