View Single Post
  #8 (permalink)  
Old July 28th, 2008, 12:52 AM
Imar's Avatar
Imar Imar is offline
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Quote:
quote:Why???? I certainly would never do that. Why would you want to do that??? (Or is Imar specifically talking about the techniques used in the links he posted? That is, that's a limitation of the code he shows?)
It's not a limitation of my code, but of the concept. Consider this data:

A 1
A 2
A 3
B 1
B 2
B 3

Let's say the default sort order for the stored procedure is on the first column (if you don't sort at all it'll be in an unpredictable order which would work fine for this example as well). Now, let's say my page size is 3 and I want the first page. What I get is this:

A 1
A 2
A 3

If I then sort descending on the second column (and stay on the first page in the GridView) at the client or in ASP.NET, what I then get is this:

A 3
A 2
A 1

However, I want to sort the entire set. So what I really need is this:

A 3
B 3
A 2

So, in order to get the right page with sorted records, you have to do all in one place: first sort, then grab the requested page from the result set.
Quote:
quote:Now, if that set of records is small enough, then the right thing to do is sort them in the browser, without ever going back to the server. Yes, even if the set of records is paged.
Not when they are paged; or at least not when they are server side / database paged. You need the entire result set in order to determine how to sort.
Quote:
quote:To give an example: 100 records, shown via 10 records per page. Absolutely no reason not to do all paging *AND* all sorting completely in the browser, completely in JavaScript.
One very good reason to do so: you get incorrect results otherwise. See above.
Quote:
quote:Takes the load off the server. And it's really not hard to do. I thought I had a demo of that, but all I have is a demo of sorting, no paging. Still, take a peek here:
They probably do client side sorting on the full set only (which is fine is that what you need) for the above mentioned reasons.... ;)

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.