How to calculate the total of a column in webgrid on the client

Source: Internet
Author: User

Add the following JS functions to the page:
// Calculate the total of one column
// Grid is the ID of webgrid, and cell is the object of a cell in the column you want to calculate
Function sumcolumn (gridid, cell)
{
VaR rows = igtbl_getgridbyid (gridid). Rows;

// If you do not pass the cell object, you can also pass the cellid to get its cell object.
// Var cell = igtbl_getcellbyid (cellid );
 
VaR column = cell. column;

var coltotal = 0;
If (rows. length >=1.0)
{< br>
for (VAR I = 0; I {< br> coltotal + = rows. getrow (I ). getcellbycolumn (column ). getvalue ();
}< br>
var element = cell. element;
If (element. parentnode. parentnode. nextsibling)
{< br> var footer = element. parentnode. parentnode. nextsibling. childnodes [0]. childnodes [element. cellindex];
footer. innertext = igtbl_mask (gridid, coltotal. tostring (), 14, "¥ ###,###,## 0.00");
}< BR >}

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.