EasyUI calculates the values of the two columns in the Editable datagrid.

Source: Internet
Author: User
@ AuthorYHC in this tutorial, you will learn how to include an operation column in an editable datagrid. An operation column usually contains some operation values from one or more other columns. view the Demo. First, create an editable datagrid. This is some of the Editable columns we have created, & amp; #39; list... syntaxHighligh

@ Author YHC

In this tutorial, you will learn how to include an operation column in an editable datagrid. An operation column usually contains some operation values from one or more other columns.

 


View Demo


First, create an editable datagrid, which is some of the Editable columns we have created. The 'listprice', 'amount', and 'unitcost' columns are defined as the numberbox editing type, the operation column is the 'unitcost' field,

Returns the result of multiplying listprice by the amount column.


[Html]

Title = "Editable DataGrid with Calculated Column" iconCls = "icon-edit" singleSelect = "true"
IdField = "itemid" url = "data/datagrid_data.json">


Item ID
List Price
Amount
Unit Cost
Attribute
Status


Title = "Editable DataGrid with Calculated Column" iconCls = "icon-edit" singleSelect = "true"
IdField = "itemid" url = "data/datagrid_data.json">
 
 
Item ID 
List Price 
Amount 
Unit Cost 
Attribute 
Status 
 
 
When a user clicks a row, we start an editing action.


[Javascript]
Var lastIndex;
$ ('# Tt'). datagrid ({
OnClickRow: function (rowIndex ){
If (lastIndex! = RowIndex ){
$ ('# Tt'). datagrid ('enabled', lastIndex );
$ ('# Tt'). datagrid ('ineinedit', rowIndex );
SetEditing (rowIndex );
}
LastIndex = rowIndex;
}
});

Var lastIndex;
$ ('# Tt'). datagrid ({
OnClickRow: function (rowIndex ){
If (lastIndex! = RowIndex ){
$ ('# Tt'). datagrid ('enabled', lastIndex );
$ ('# Tt'). datagrid ('ineinedit', rowIndex );
SetEditing (rowIndex );
}
LastIndex = rowIndex;
}
}); Create an operational relationship between some columns. We should get editors and bind some events to them.


[Javascript]
Function setEditing (rowIndex ){
Var editors = $ ('# tt'). datagrid ('geteditor', rowIndex );
Var priceEditor = editors [0];
Var amountEditor = editors [1];
Var costEditor = editors [2];
PriceEditor.tar get. bind ('change', function (){
Calculate ();
});
AmountEditor.tar get. bind ('change', function (){
Calculate ();
});
Function calculate (){
Var cost = priceEditor.tar get. val () * amountEditor.tar get. val ();
Values (costeditor.tar get). numberbox ('setvalue', cost );
}
}
Author: yhc13429826359
 

Related Article

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.