I have searched the internet several times, but I have not found my own requirements. So I 'd like to find it myself.
In fact, the content here is quite simple. The main meaning is to get a row or several lines on your current page, or get the data on the current page.
I was asked to perform query export, export select items, export the current page, and so on in the header of yesterday. I will check the effect and check whether it will be used later. to be honest, for Ext, I am also an out-of-the-box layman. Although there are many contacts, there are too many content in total. so you have to learn it slowly.
I won't say much about the waste of time that I am crazy about.
It is mainly about how to obtain the requirements mentioned above.
All are obtained from ext API.
1. Obtain the total data on the current page. DS. getcount (); returns the total data of the current page. I use Ext. data. groupingstore, which will be checked and found: gets the number of cached records. to put it simply, it is to get the number of cache records, and the rest will be explained in Chinese, that is, if there is a page, it is simply to get the sum of the current page. instead of getting the total data (this total data may make this page have several page flip data ). so,
Second, obtain the total data. DS. gettotalcount (); let's say, here we get the total amount of the current page and the total amount of all data. Here we don't just search for the groupingstore API, we will know, the data class, or other classes have these methods. well, that's what we use, so it's not necessary to try one by one. omitted.
Third, the total amount is obtained, that is, the data needs to be obtained. let's talk about the data on the current page when there is no option. to obtain the data on the current page, you need to obtain the data one by one. to list the simple points, I can get the total number of primary keys.
Function download () {// write a function for normalization. <br/> var pagecount = Ds. getcount (); // get the total data on the current page <br/> var allcount = Ds. gettotalcount (); // obtain the sum of all data <br/> If (allcount> pagesize) {// you can only determine whether the total is greater than the page size. If the total is greater than the page size, to export the current page. <br/> // The page looks the same as the standard text, so the ext message box is used in a unified manner with Ext. <br/> var confir1 = ext. messageBox. confirm ('export selection prompt box ',' select "yes" to export all data, and select "no" to export data on the current page! ', Onbutton); // select YES to export the selected row; otherwise, all rows will be exported. <br/>}< br/> function onbutton (BTN) {// select the button to export different content <br/> If (BTN = 'yes') {// export all. <br/> // For the sake of overall appearance, I still provided the parameters passed in. It is not difficult to understand. The first one is whether to export the options, and the last two are to determine which ones to export. there are two reasons, because the first parameter is also passed when there are options. <br/> // maybe I am too arrogant. Haha, there are more words than programs. <br/> url = '<% = webapp %>/servlet/serverattr? Action = download & down1 = svrid & downn = svrid ''; // here I use servlet, so just give an example. You can fill it out as needed, it can be used based on the import and export I wrote several times. <br/> window. location = URL; <br/>}< br/> else {<br/> var downcount = Ds. getcount (); // obtain the number of data entries on the page. if it is the last page, it will be taken if it is not set to pagesize. <br/> var dataarray = new array (); // Save the array of the page data <br/> for (VAR I = 0; I <downcount; I ++) {<br/> dataarray [I] = Ds. getat (I ). get ('svri'); // obtain the primary key and pass it back. the getat (number); method is used directly. you can use Getbyid (string ID):. <br/>}< br/> var url1 = '<% = webapp %>/servlet/serverattrservlet? Action = download & down1 = svrid1 & downn = '+ downn; // you can understand from here. Why are these parameters used. <br/> window. location = url1; <br/>}< br/>}
At this point, when no items are selected, it is time to export all the items on the current page, and write the items. as I wrote above, the most important thing here is not to write, import, export, but to get the page data and the data you want.
Next, let's see the above. Here we first need a selection box, that is, a checkboxselectionmodel. If not, let's talk about it here.
The overall program is provided.
Function download () {// write a function for normalization. <br/> var down = grid. getselections (); // obtain the option. </P> <p> var pagecount = Ds. getcount (); // get the total data on the current page <br/> var allcount = Ds. gettotalcount (); // get the total data </P> <p> If (down. length = 0 & selectedrow! = NULL) {// This method is used when no options are available here. <br/> If (allcount> pagesize) {// you can only determine whether the total amount is greater than the page size, if it is greater than the page size, the option to export the current page is provided. <br/> // The page looks the same as the standard text, so the ext message box is used in a unified manner with Ext. <br/> var confir1 = ext. messageBox. confirm ('export selection prompt box ',' select "yes" to export all data, and select "no" to export data on the current page! ', Onbutton); // select YES to export the selected row; otherwise, all rows will be exported. <br/>} else {// if this is not the case, export all data directly. <br/> window. location = '<% = webapp %>/servlet/serverattr? Action = download & down1 = svrid & downn = svrid ''; <br/>}< br/>} When else {// has options, another judgment is made. <br/> var confir2 = ext. messageBox. confirm ('export selection prompt box ',' select "yes" to export all data, and select "no" to export the data you selected! ', Onbutton2); <br/>}</P> <p >}< br/> function onbutton (BTN) {// select the button to export different content <br/> If (BTN = 'yes') {// export all. <br/> // For the sake of overall appearance, I still provided the parameters passed in. It is not difficult to understand. The first one is whether to export the options, and the last two are to determine which ones to export. there are two reasons, because the first parameter is also passed when there are options. <br/> // maybe I am too arrogant. Haha, there are more words than programs. <br/> url = '<% = webapp %>/servlet/serverattr? Action = download & down1 = svrid & downn = svrid ''; // here I use servlet, so just give an example. You can fill it out as needed, it can be used based on the import and export I wrote several times. <br/> window. location = URL; <br/>}< br/> else {<br/> var downcount = Ds. getcount (); // obtain the number of data entries on the page. if it is the last page, it will be taken if it is not set to pagesize. <br/> var dataarray = new array (); // Save the array of the page data <br/> for (VAR I = 0; I <downcount; I ++) {<br/> dataarray [I] = Ds. getat (I ). get ('svri'); // obtain the primary key and pass it back. the getat (number); method is used directly. you can use Getbyid (string ID):. <br/>}< br/> var url1 = '<% = webapp %>/servlet/serverattr? Action = download & down1 = svrid1 & downn = '+ dataarray; // you can understand from here. Why are these parameters used. <br/> window. location = url1; <br/>}< br/> function onbutton2 () {<br/> var down = grid. getselections (); // obtain the option <br/> If (down. length = 0 & selectedrow! = NULL) {// judge <br/> down [0] = selectedrow; <br/>}< br/> var dataarray = new array (); // export the selected content. <br/> for (VAR df = 0; df <down. length; df ++) {<br/> dataarray [DF] = down [DF]. get ('svri'); <br/>}< br/> If (BTN = 'yes ') {// export all <br/> var url = '<% = webapp %>/servlet/serverattr? Action = download & down1 = svrid & downn = svrid '; // The returned export information and conditions. The Initialization is to export all data, so the following is only a condition for judging the export part. <br/> window. location = URL; <br/>}else {// export options <br/> var url = '<% = webapp %>/servlet/serverattr? Action = download & down1 = '+ dataarray +' & downn = null'; <br/> window. Location = URL; <br/>}< br/>}
Well, it's just a piece of cake. because the main frameworks are provided. is to solve the problem. because there are too many other contents, we will not give them. You can refer to my previous article about ext import and export operations.