使用EasyUI的Datagrid的Editor进行行编辑,Enter回车结束编辑,并开启新的一行。
//新增數(shù)據(jù)
function add() {
if (Index == undefined) {
row = { move_date: '', start_time: '', end_time: '', start_place: '', arrival_place: '', move_vehicle: '' };
$('#dg').datagrid('appendRow', row);
Index = $('#dg').datagrid('getRows').length - 1;
$('#dg').datagrid('selectRow', Index).datagrid('beginEdit', Index);
}//新建行結(jié)束
//回車時(shí)結(jié)束編輯,并開啟新一行放在datagrid的onBeginEdit事件里
onBeginEdit: function (Index, row) {
var stayPlace = $("#dg_StaySchedule").datagrid('getEditor', { index: Index, field: 'stay_place' });
var stayAmount = $("#dg_StaySchedule").datagrid('getEditor', { index: Index, field: 'stay_amount' });
$(stayPlace.target).textbox('options').onChange = function (newValue, lodValue) {
//開啟等待
MaskUtil.mask();
$.ajax({//根據(jù)條件值獲取數(shù)據(jù)
type: "POST",
url: "url?stay_place=" + newValue + "&emp_title=" + $('#emp_title').textbox('getValue'),
dataType: 'json',
success: function (msg) {
//關(guān)閉等待
MaskUtil.unmask();
stayData = 0;
stayData = JSON.parse(msg.stay);
$(stayAmount.target).textbox('setValue', stayData);//查詢的數(shù)據(jù)給列賦值
}
})
}
//回車時(shí)結(jié)束編輯,并開啟新一行
$('.datagrid-editable .textbox,.datagrid-editable .datagrid-editable-input,.datagrid-editable .textbox-text').bind('keypress', function (e) {
var code = e.keyCode || e.which;
f (code == 13) {
//保存更改 第一次編輯可能不會(huì)改變值
var b = $('#dg').datagrid('validateRow', Index);
if (b == false) {
$('#dg').datagrid('selectRow', Index).datagrid('beginEdit', Index);
return;
}
$('#dg').datagrid('acceptChanges');
$('#dg').datagrid('endEdit', Index);
if (stayData > 0 && row.stay_amount > stayData) {
$.messager.confirm('操作提示', "提交的住宿費(fèi)已超標(biāo)準(zhǔn)費(fèi)用,標(biāo)準(zhǔn)住宿費(fèi)用是:" + stayData + "元,是否繼續(xù)?", function (r) {
if (r) {
$('#dg').datagrid('unselectRow', Index);
Index= undefined;
add();//新增方法
}
else {
$('#dg').datagrid('beginEdit', Index);
}
})
} else {
Index= undefined;
add();//新增方法
}
}
});
}
轉(zhuǎn)載于:https://www.cnblogs.com/lijl/p/9759923.html
總結(jié)
以上是生活随笔為你收集整理的使用EasyUI的Datagrid的Editor进行行编辑,Enter回车结束编辑,并开启新的一行。的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 洛谷P4199 万径人踪灭(manach
- 下一篇: mac 中登陆mysql忘记密码解决办法