:
Copy codeThe Code is as follows:
<! DOCTYPE html PUBLIC "-// W3C // dtd html 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd">
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
<Title> jQuery EasyUI </title>
<Link rel = "stylesheet" type = "text/css" href = "../themes/default/easyui.css">
<Link rel = "stylesheet" type = "text/css" href = "../themes/icon.css">
<Script type = "text/javascript" src = "../jquery-1.4.2.min.js"> </script>
<Script type = "text/javascript" src = ".../jquery. easyui. min. js"> </script>
<Script>
Var users = {total: 6, rows :[
{No: 1, name: 'user 1', addr: 'shandong Jinan ', email: 'user1 @ 163.com', birthday: '2017/123 '},
{No: 2, name: 'user 2', addr: 'shandong Jinan ', email: 'user2 @ 163.com', birthday: '2017/123 '},
{No: 3, name: 'user 3', addr: 'shandong Jinan ', email: 'user3 @ 163.com', birthday: '2017/123 '},
{No: 4, name: 'user 4', addr: 'shandong Jinan ', email: 'user4 @ 163.com', birthday: '2017/123 '},
{No: 5, name: 'user 5', addr: 'shandong Jinan ', email: 'user5 @ 163.com', birthday: '2017/123 '},
{No: 6, name: 'user 6', addr: 'shandong Jinan ', email: 'user6 @ 163.com', birthday: '2017/123 '}
]};
$ (Function (){
$ ('# Tt'). datagrid ({
Title: 'editable DataGrid ',
IconCls: 'icon-edit ',
Width: 530,
Height: 250,
SingleSelect: true,
Columns :[[
{Field: 'no', title: 'number', width: 50, editor: 'numberbox '},
{Field: 'name', title: 'name', width: 60, editor: 'text '},
{Field: 'addr ', title: 'address', width: 100, editor: 'text '},
{Field: 'email ', title: 'email', width: 100,
Editor :{
Type: 'validatebox ',
Options :{
ValidType: 'email'
}
}
},
{Field: 'birthday', title: 'birthday', width: 80, editor: 'datebox '},
{Field: 'action', title: 'operation', width: 70, align: 'center ',
Formatter: function (value, row, index ){
If (row. editing ){
Var s = '<a href = "#" onclick = "saverow (' + index + ')"> Save </a> ';
Var c = '<a href = "#" onclick = "cancelrow (' + index + ')"> cancel </a> ';
Return s + c;
} Else {
Var e = '<a href = "#" onclick = "editrow (' + index + ')"> edit </a> ';
Var d = '<a href = "#" onclick = "deleterow (' + index + ')"> Delete </a> ';
Return e + d;
}
}
}
],
Toolbar :[{
Text: 'add ',
IconCls: 'icon-add ',
Handler: addrow
},{
Text: 'save ',
IconCls: 'icon-save ',
Handler: saveall
},{
Text: 'cancel ',
IconCls: 'icon-cancel ',
Handler: cancelall
}],
OnBeforeEdit: function (index, row ){
Row. editing = true;
$ ('# Tt'). datagrid ('refreshrow', index );
Editcount ++;
},
OnAfterEdit: function (index, row ){
Row. editing = false;
$ ('# Tt'). datagrid ('refreshrow', index );
Editcount --;
},
OnCancelEdit: function (index, row ){
Row. editing = false;
$ ('# Tt'). datagrid ('refreshrow', index );
Editcount --;
}
}). Datagrid ('loaddata', users). datagrid ('acceptchanges ');
});
Var editcount = 0;
Function editrow (index ){
$ ('# Tt'). datagrid ('ineinedit', index );
}
Function deleterow (index ){
$. Messager. confirm ('confirmed', 'Are you sure you want to delete it? ', Function (r ){
If (r ){
$ ('# Tt'). datagrid ('delterow', index );
}
});
}
Function saverow (index ){
$ ('# Tt'). datagrid ('enabled', index );
}
Function cancelrow (index ){
$ ('# Tt'). datagrid ('canceledit', index );
}
Function addrow (){
If (editcount> 0 ){
$. Messager. alert ('Warning ',' There are currently '+ editcount +' records being edited, and records cannot be added. ');
Return;
}
$ ('# Tt'). datagrid ('appendrow ',{
No :'',
Name :'',
Addr :'',
Email :'',
Birthday :''
});
}
Function saveall (){
$ ('# Tt'). datagrid ('acceptchanges ');
}
Function cancelall (){
$ ('# Tt'). datagrid ('rejectchanges ');
}
</Script>
</Head>
<Body>
<H1> Editable DataGrid <Table id = "tt"> </table>
</Body>
</Html>