jQuery EasyUI DataGrid - Enabling Inline Editing
The editable feature was recently added to the datagrid. It allows users to add a new row to the datagrid. Users can also update one or more rows.
This tutorial shows you how to create a datagrid and inline editors.
Create the DataGrid
$(function(){
$('#tt').datagrid({
title:'Editable DataGrid',
iconCls:'icon-edit',
width:660,
height:250,
singleSelect:true,
idField:'itemid',
url:'datagrid_data.json',
columns:[[
{field:'itemid',title:'Item ID',width:60},
{field:'productid',title:'Product',width:100,
formatter:function(value){
for(var i=0; i
To enable inline editing in the datagrid, you should add an editor property to a column. The editor tells the datagrid how to edit a field and how to save the field value. As you can see, we define three editors: text, combobox, and checkbox.
function getRowIndex(target){
var tr = $(target).closest('tr.datagrid-row');
return parseInt(tr.attr('datagrid-row-index'));
}
function editrow(target){
$('#tt').datagrid('beginEdit', getRowIndex(target));
}
function deleterow(target){
$.messager.confirm('Confirm','Are you sure?',function(r){
if (r){
$('#tt').datagrid('deleteRow', getRowIndex(target));
}
});
}
function saverow(target){
$('#tt').datagrid('endEdit', getRowIndex(target));
}
function cancelrow(target){
$('#tt').datagrid('cancelEdit', getRowIndex(target));
}