EasyUI-Editable DataGrid(可编辑数据表格)

 可以直接在表格上直接编辑操作,并批量保存到后台的功能。


使用案例

HTML标签里面创建数据表格

title=”Editable DataGrid”

singleSelect=”true”>


创建编辑器
$(‘#tt').edatagrid({

url: ‘datagrid_data.json',

saveUrl: …,

updateUrl: …,

destroyUrl: …

});  

现在你可以通过双击数据表格的行开始编辑操作。你也可以设置saveUrl,updateUrl,destroyUrl 属性来自动从客户端同步数据到端。

属性

可编辑表格控件的熟悉扩展自DataGrid(数据表格),可编辑表格控件新增的属性如下:

属性名

属性值类型

描述

默认值

destroyMsg

object

销毁行的时候显示的确认对话框消息。

destroyMsg:{

    norecord:{    // 在没有记录选择的时候执行

        title:'Warning',

        msg:'No record is selected.'

    },

    confirm:{       // 在选择一行的时候执行
title:'Confirm',

        msg:'Are you sure you want to delete?'

    }

}

url

string

通过URL检索数据。

null

saveUrl

string

通过URL保存数据到并返回添加的行。

null

updateUrl

string

通过URL更新数据到并返回更新的行。

null

destroyUrl

string

通过URL‘id'参数发送到以销毁行。

null

tree

selector

树选择器指示相对应的树控件。

null

treeUrl

string

通过URL检索树控件数据。

null

treeDndUrl

string

通过URL处理拖拽操作。

null

treeTextField

string

定义树的文本字段名称。

name

treeParentField

string

定义树的父节点字段名。

parentId

事件

可编辑表格的事件扩展自DataGrid(数据表格),可编辑表格新增的事件如下:

事件名

参数

描述

onAdd

index,row

在添加新行的时候触发。

onEdit

index,row

在编辑一行数据的时候触发。

onBeforeSave

index

在保存一行记录之前触发,返回false可以取消保存操作。

onSave

index,row

在保存一行记录时触发。

onDestroy

index,row

在销毁一样记录时触发。

方法

可编辑表格的方法扩展自DataGrid(数据表格),可编辑表格新增或重写的方法如下:

方法名

参数

描述

options

none

返回属性对象。

enableEditing

none

启用数据表格编辑。

disableEditing

none

禁用数据表格编辑。

editRow

index

编辑指定行。

addRow

none

添加一个新的空行。

saveRow

none

保存编辑行并发送到服务器。

cancelRow

none

取消编辑行。

destroyRow

none

销毁当前选择的行。

实例:实现批量保存数据的表格

$(‘#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; iSave ‘;
var c = ‘Cancel';
return s+c;
} else {
var e = ‘Edit ‘;
var d = ‘Delete';
return e+d;
}
}
}
]],
onBeforeEdit:function(index,row){
row.editing = true;
$(‘#tt').datagrid(‘refreshRow', index);
},
onAfterEdit:function(index,row){
row.editing = false;
$(‘#tt').datagrid(‘refreshRow', index);
},
onCancelEdit:function(index,row){
row.editing = false;
$(‘#tt').datagrid(‘refreshRow', index);
}
});
function editrow(index){
$(‘#tt').datagrid(‘beginEdit', index);
}
function deleterow(index){
$.messager.confirm(‘Confirm','Are you sure?',function(r){
if (r){
$(‘#tt').datagrid(‘deleteRow', index);
}
});
}
function saverow(index){
$(‘#tt').datagrid(‘endEdit', index);  //该方法是将数据保存起来,显然,通过前端技术与上下文会话实现了和后台的交互

}
function cancelrow(index){
$(‘#tt').datagrid(‘cancelEdit', index);
}

声明: 除非转自他站(如有侵权,请联系处理)外,本文采用 BY-NC-SA 协议进行授权 | 智乐兔
转载请注明:转自《EasyUI-Editable DataGrid(可编辑数据表格)
本文地址:https://www.zhiletu.com/archives-2611.html
关注公众号:智乐兔

赞赏

wechat pay微信赞赏alipay pay支付宝赞赏

上一篇
下一篇

相关文章

在线留言

你必须 登录后 才能留言!

在线客服
在线客服 X

售前: 点击这里给我发消息
售后: 点击这里给我发消息

智乐兔官微