Easyui DataGrid Component Extension, displaying statistics on current page information

Source: Internet
Author: User
Tags eval
Turn on statistical functions for the DataGrid
02 $ (' #list '). DataGrid ({
03 ...//The code here is slightly
04 Showfooter:true,
05 Onloadsuccess:function () {
06 $ (' #list '). DataGrid (' statistics ');
07 }
08 });
09 Statistics a column (Reference amount column)
10 <table id= "List" >
11 <thead>
12 <tr>
13 <th field= "No" Width= "No." > Serial number </th>
14 <th field= "Data" width= "> Date </th>
15 <th field= "Money" width= "100"
16 Formatter= "Formatmoney" align= "right"
17 Sum= "true" avg= "true" min= "true" max= "true" > Amount (Yuan) </th>
18 <th field= "status" width= "sortable=" "true" > Active status </th>
19 </tr>
20 </thead>
21st </table>
2. [Image] Effect demo 3. [File] easyui.plugin.js ~ 3KB Download ($)
001 $.extend ($.fn.datagrid.methods, {
002 Statistics:function (JQ) {
003 var opt=$ (JQ). DataGrid (' Options '). columns;
004 var rows = $ (JQ). DataGrid ("GetRows");
005
006 var footer = new Array ();
007 footer[' Sum ' = "";
008 footer[' avg '] = "";
009 footer[' max '] = "";
010 footer[' min '] = "";
011
012 for (var i=0; i<opt[0].length; i++) {
013 if (opt[0][i].sum) {
014 footer[' sum ' = footer[' sum '] + sum (opt[0][i].field) + ', ';
015 }
016 if (OPT[0][I].AVG) {
017 footer[' avg '] = footer[' avg '] + AVG (Opt[0][i].field) + ', ';
018 }
019 if (Opt[0][i].max) {
020 footer[' max '] = footer[' max ' + max (Opt[0][i].field) + ', ';
021 }
022 if (opt[0][i].min) {
023 footer[' min '] = footer[' min '] + min (opt[0][i].field) + ', ';
024 }
025 }
026
12V var footerobj = new Array ();
028
029 if (footer[' sum ']! = ") {
030 var tmp = ' {' + footer[' sum '].substring (0,footer[' sum '].length-1) + '} ';
031 var obj = eval (' (' + tmp + ') ');
032 if (obj[opt[0][0].field] = = undefined) {
033 footer[' sum ' + = ' "' + Opt[0][0].field + '": "<b> when page totals:</b>" ";
034 obj = eval (' ({' + footer[' sum '] + '} ');
035 }else{
036 Obj[opt[0][0].field] = "<b> when page totals:</b>" + Obj[opt[0][0].field];
037 }
038 Footerobj.push (obj);
039 }
040
041 if (footer[' avg ']! = "") {
042 var tmp = ' {' + footer[' avg '].substring (0,footer[' avg '].length-1) + '} ';
043 var obj = eval (' (' + tmp + ') ');
044 if (obj[opt[0][0].field] = = undefined) {
045 footer[' avg '] + = ' "' + Opt[0][0].field + '": "<b> when page mean value:</b>" ';
046 obj = eval (' ({' + footer[' avg '] + '} ');
047 }else{
048 Obj[opt[0][0].field] = "<b> when page mean:</b>" + Obj[opt[0][0].field];
049 }
050 Footerobj.push (obj);
051 }
052
053 if (footer[' max ']! = "") {
054 var tmp = ' {' + footer[' Max '].substring (0,footer[' Max '].length-1) + '} ';
055 Var

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.