Dialog between list and page sharer

Source: Internet
Author: User

[Introduction]
Few applications do not involve displaying set data. to present the set data, you need to use "list (list, list )". for example, the list of all members is displayed. when too much data is displayed at a time, if all the data is fully listed, it will cause difficulties for users to read. in this case, you need to list the data by page. give users the confidence to control data. to put yourself in the correct place, consider it as a user.ProgramStaff, design personnel should have attention.

The following describes the author's feelings, opinions, or skills for "Data Set paging" during application development. For your reference.

[Problem origin]
We have many choices to present the set of data. in ASP. net category, a core concept is "binding ". that is, the collection object instance carrying data is bound to the list control through a simple "databind ()" method. this process can even write a line without actually writing it.CodeImplementation. The actual process is nothing more than obtaining a data set by querying the database. Then, you can select a "data binding control" and set the datasource attribute. It would be great to call the databind () method.

In the data binding control that we can choose, the DataGrid seems to be unique. Some people even want to work hard for the rest of their lives.
The DataGrid can be automatically paged. The author has to lament that the DataGrid is so powerful.

However, in the first years of using the DataGrid, the author had no preference for the DataGrid. the reason is: The DataGrid is too powerful. too many features. it is said that there must be a short length of expertise. after all, the application is inconvenient. in addition, the paging principle is based on the environment with low performance requirements. to a certain extent, the DataGrid cannot meet our special output needs.

In many cases, we only need to display the set data. and can be paged. auto create columns, sorting, editable, delete, and other functions are not required. some lightweight data binding controls with strong style customization will enter our selection range. repeater is an ideal choice. besides, it is sometimes necessary to compile paging programs.

In this way, the problem arises: how to implement paging. and how to reasonably arrange the paging logic. this topic is the dialog between the list and the page splitter. it is both a dialogue and must be between two subjects. the author designs two objects: Data Representation and paging control. how to organize the call relationship and message mechanism between two subjects is the main content discussed in this article.

[Design idea]
Why design the page splitter and list as two objects? Design is an object, and it is necessary to design its interface for communicating with the container. usually increase the design workload. however, in the long run, the presentation logic of the page splitter may be very complicated. has a certain cohesion. it is also reusable to a certain extent (the page splitter is applied to different lists ).

In fact, paginator is not a real name. It is called a page splitter, but it does not perform any operations on data. operating data is a list of your own tasks. the page splitter only determines how to display the page based on the data on the current page. and report the location to the list after the user makes the operation.

Let's analyze the page splitter carefully:
1. The page splitter needs to know the following data: Total number of records, total page capacity (the number of records per page), current displayed page times.
2. The page splitter must send a notification list with a certain mechanism when the user sends an operation request (page feed ).
3. The current page must be displayed

The paging data is controlled by the list. the page splitter knows nothing about this before it is notified. in addition, the list must be able to respond to the paging commands of the page splitter. in addition, the new status will be notified to the page splitter. this is the dialog between the list and the page splitter.

Let me explain in detail. starting from the initial status: the list obtains data. the programmer sets the list to display 15 lines per page. A total of 81 pieces of data to be bound are calculated from the list. in this case, we need to divide it into 81/15 = 5 + 6. it should be divided into 6 pages. the last page is not satisfied. in this way, the list notification page splitter: I have 81 pieces of data and 15 pieces of data are displayed on each page. A total of 6 pages are required. (write property ). the page splitter starts initialization. it outputs 1 2 3 4 5 6 numbers sequentially. each number can be clicked with the mouse. and add a line below 1 to indicate that the current display is the first page. this completes the page sending process.

If you want to directly jump to page 4th. so he clicked 4. therefore, the message "4 clicked" must be sent back to the backend in a certain process. the backend is the page sharer first obtains the 4 data. the page splitter sends the data as an event.

The list can directly capture events sent by the page sharer. for example, the event name is pagechange. now that the list is ready, you must switch to page 4 immediately. so we started to process the data. get Page 4 (from 46-60) to bind to yourself. then set the page sharer status again. set the current page to 4. in this way, the page splitter adds a line to the output 4 numbers. the user can see that. the data has changed (3 pages forward), and the page splitter re-instructs the current page.

[Implementation]
Design list:
The following public APIs (C #) must be implemented #):
Public int recordcount // total number of records
Public int pagecount // total number of pages
Public int pagesize // page size
Public int currentpage // current page times
Private method: Implement paging computing
Private void pageme ()

Design the page splitter:
The following public APIs must be implemented:
Public int pagecount // total number of pages
Public int pointedpage // current indicator page
Public event pagechange ()
(The pagechange event must contain an integer. It is used as the data for page switching of the notification list.

So designed. each object has a clear division of labor and clear logic. in addition, the interface is relatively standard and suitable for transplantation and reuse. in addition, you can place the page splitter in any place between the front, back, and left. you only need to make the list control available.

[Extended features]
1. The page splitter cannot simply output all pages. If the number of pages exceeds a certain number, it should be displayed in a friendly way. For example, it is similar to the Google Display Search Result paging mode.
2. but set a paging critical point. for example, more than 40 data records are paged. otherwise, it is displayed on the page. it's hard to think that when a user moves to the second page, there is only one piece of data.
3. The page splitter can display the previous page, the next page, the first page, and the last page so that you can move forward and backward.
4. The page splitter can create many styles and control them with public attributes.

In addition to the fourth item, the above are all implemented in the project of the author, and the author finds that to be flexible and robust, you must pay attention to many problems.Source codeThe announcement is shared with everyone.

The list item paging mechanism allows you to directly use the DataGrid paging method and process data by yourself. the author applied the server short data cache to relieve the burden on the database. I have the opportunity to write some comments.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.