Connecting Tech Pros Worldwide Forums | Help | Site Map

Pagination in my UI

dheerajjoshim's Avatar
Needs Regular Fix
 
Join Date: Jul 2009
Location: Bangalore, INDIA
Posts: 268
#1: 4 Weeks Ago
Hi all,

I have a list view in which i populate data from data base. Now i want only 10 data displayed in my list view and next 10 when i click on next page icon and so on.

I thought of a solution and it goes like this:

If there are 100 data in database count the number of data and divide it in to group of 10. So now we have 10 groups(Considering 100 data). Insert each 10 data into a hash table. So we get 10 Hash table. Now create array list of hash table.

Now count number of items in array list and display the numbers(It represent the page number). so clicking on that number(say 5 for example) hash table in array list position 5 will get displayed.

Is there any smarter way to approach this problem than what i thought. Inputs are appreciated.

Regards
Dheeraj Joshi

tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,779
#2: 4 Weeks Ago

re: Pagination in my UI


Not sure why you need to added layer of a hash table.
The math for what to display is straightforward:
10 items per page * your page number + item on that page

Expand|Select|Wrap|Line Numbers
  1. for (int Index = 0; Index < PerPage; Index++)
  2. {
  3.    DIsplay(MyData[(CurrentPage*PerPage) + Index];
  4. }
dheerajjoshim's Avatar
Needs Regular Fix
 
Join Date: Jul 2009
Location: Bangalore, INDIA
Posts: 268
#3: 4 Weeks Ago

re: Pagination in my UI


Quote:

Originally Posted by tlhintoq View Post

Not sure why you need to added layer of a hash table.
The math for what to display is straightforward:
10 items per page * your page number + item on that page

Expand|Select|Wrap|Line Numbers
  1. for (int Index = 0; Index < PerPage; Index++)
  2. {
  3.    DIsplay(MyData[(CurrentPage*PerPage) + Index];
  4. }

Oh... Yeah... Sounds like a good answer. I will implement it in same way.

Now Got a design question.

Now if i want to make pagination as separate component.(So many list views can use same pagination idea). How to strip pagination logic from List view. So pagination will be separate thing.So from list view what need to be passes to pagination component, and what to return. I am not getting any idea to make pagination as a widget.

Regards
Dheeraj Joshi
tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,779
#4: 4 Weeks Ago

re: Pagination in my UI


I like where you thinking is going with that. I like making re-usable code in the form of components, as often as I can.

I don't do much with grid views, grid controls etc., so I don't see an idea for a control that will handle 1 column or 10, 20 rows or 2000 - that doesn't look so generic it would be boring - and I hate boring.

You could create a seperate navigation pallet that could be reused though. Some thing with "first, last, next previous, search bar, etc." Maybe if that took your entire table of data it could become self contain???
Reply