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

Source: Internet
Author: User

@ 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]
<Table id = "tt" style = "width: 600px; height: auto"
Title = "Editable DataGrid with Calculated Column" iconCls = "icon-edit" singleSelect = "true"
IdField = "itemid" url = "data/datagrid_data.json">
<Thead>
<Tr>
<Th field = "itemid" width = "80"> Item ID </th>
<Th field = "listprice" width = "80" align = "right" editor = "{type: 'numberbox', options: {precision: 1 }}"> List Price </th>
<Th field = "amount" width = "80" align = "right" editor = "{type: 'numberbox', options: {precision: 0 }}"> Amount </th>
<Th field = "unitcost" width = "80" align = "right" editor = "numberbox"> Unit Cost </th>
<Th field = "attr1" width = "150" editor = "text"> Attribute </th>
<Th field = "status" width = "60" align = "center" editor = "{type: 'checkbox', options: {on: 'P', off: ''}}"> Status </th>
</Tr>
</Thead>
</Table>

<Table id = "tt" style = "width: 600px; height: auto"
Title = "Editable DataGrid with Calculated Column" iconCls = "icon-edit" singleSelect = "true"
IdField = "itemid" url = "data/datagrid_data.json">
<Thead>
<Tr>
<Th field = "itemid" width = "80"> Item ID </th>
<Th field = "listprice" width = "80" align = "right" editor = "{type: 'numberbox', options: {precision: 1 }}"> List Price </th>
<Th field = "amount" width = "80" align = "right" editor = "{type: 'numberbox', options: {precision: 0 }}"> Amount </th>
<Th field = "unitcost" width = "80" align = "right" editor = "numberbox"> Unit Cost </th>
<Th field = "attr1" width = "150" editor = "text"> Attribute </th>
<Th field = "status" width = "60" align = "center" editor = "{type: 'checkbox', options: {on: 'P', off: ''}}"> Status </th>
</Tr>
</Thead>
</Table> when a user clicks a row, an edit action is started.


[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.