js--easyUI----jQuery easyui datagrid 點選某個單元格即進入編輯狀態,焦點移開後,儲存資料
阿新 • • 發佈:2019-01-23
以上為轉載內容,以下為自己驗證程式碼:
function _createTable(data){
//對漢字進行轉碼
$.each(data.data, function(i, obj){
var eventName = unescape(obj.eventName);
var levelName = unescape(obj.levelName);
obj.eventName = eventName;
obj.levelName = levelName;
});
//資料處理
var column = [
{title:'ID',field:'id',width:100,align:'left'},
{title:'級別編號',field:'levelNum',width:100,align:'left'},
{title:'級別名稱',field:'levelName',width:100,align:'left',
formatter:function(data){
if(data == 'null'){
return "";
}else{
return data;
}
},editor:{type:'text'}
},
{title:'活動id',field:'eventId',width:60,align:'left',rowspan:1, hidden:true},
{title:'建立人id',field:'createUid',width:100,align:'left'},
{title:'建立時間',field:'createDate',width:150,align:'left'}
];
var root = listToDataGrid(data);
var title = "頭像列表";
_getDataGrid("eventListTable", title, 'id', column).datagrid('loadData', root);
}
function _getDataGrid(id, aTitle, pk, columns){
var el = $('#' + id + '');
if (el.data('datagridInit') !== 'finished'){
var lastIndex;
el.datagrid({
columns:[columns],
title:aTitle,
width:1000,
nowrap: false,
idField:pk,
rownumbers:true,
striped:true,
singleSelect: true,
collapsible:true,
sortName: 'levelNum',
pagination:false,
pageSize: pageSize,
sortOrder: 'asc',
remoteSort: false,
idField:'id',
rownumbers:true,
toolbar:[{
id:'btnmodify',
text:'修改',
iconCls:'icon-cut',
handler:_showDialog(id)
},'-',{
id:'btnremove',
text:'刪除',
iconCls:'icon-cancel',
handler:_removeEvent(id)
}],
onDblClickCell:function(rowIndex, field, value){
lastIndex=rowIndex;
$('#'+id).datagrid('endEdit',rowIndex);
$('#'+id).datagrid('beginEdit',rowIndex);
var oldordering = value;
$("input.datagrid-editable-input").val(oldordering).bind("blur",function(evt){
debugger;
var dataArry = $('#'+id).datagrid('getSelections');
eventPlayer.setLevelName($(this).val(), dataArry[0].id);
$('#'+id).datagrid('endEdit',lastIndex);
}).bind("keypress",function(evt){
if(evt.keyCode==13){
debugger;
var dataArry = $('#'+id).datagrid('getSelections');
eventPlayer.setLevelName($(this).val(), dataArry[0].id);
$('#'+id).datagrid('endEdit',lastIndex);
}
}).focus();
lastIndex=rowIndex;
}
});
//註冊分頁查詢方法
var p = $('#' + id).datagrid('getPager');
$pagination(p, {
onSelectPage: function(pageNumber, pageSize1){
getEventPlayerDataList();
}
});
el.data('datagridInit', 'finished');
}
function _createTable(data){
//對漢字進行轉碼
$.each(data.data, function(i, obj){
var eventName = unescape(obj.eventName);
var levelName = unescape(obj.levelName);
obj.eventName = eventName;
obj.levelName = levelName;
});
//資料處理
var column = [
{title:'ID',field:'id',width:100,align:'left'},
{title:'級別編號',field:'levelNum',width:100,align:'left'},
{title:'級別名稱',field:'levelName',width:100,align:'left',
formatter:function(data){
if(data == 'null'){
return "";
}else{
return data;
}
},editor:{type:'text'}
},
{title:'活動id',field:'eventId',width:60,align:'left',rowspan:1, hidden:true},
{title:'建立人id',field:'createUid',width:100,align:'left'},
{title:'建立時間',field:'createDate',width:150,align:'left'}
];
var root = listToDataGrid(data);
var title = "頭像列表";
_getDataGrid("eventListTable", title, 'id', column).datagrid('loadData', root);
}
function _getDataGrid(id, aTitle, pk, columns){
var el = $('#' + id + '');
if (el.data('datagridInit') !== 'finished'){
var lastIndex;
el.datagrid({
columns:[columns],
title:aTitle,
width:1000,
nowrap: false,
idField:pk,
rownumbers:true,
striped:true,
singleSelect: true,
collapsible:true,
sortName: 'levelNum',
pagination:false,
pageSize: pageSize,
sortOrder: 'asc',
remoteSort: false,
idField:'id',
rownumbers:true,
toolbar:[{
id:'btnmodify',
text:'修改',
iconCls:'icon-cut',
handler:_showDialog(id)
},'-',{
id:'btnremove',
text:'刪除',
iconCls:'icon-cancel',
handler:_removeEvent(id)
}],
onDblClickCell:function(rowIndex, field, value){
lastIndex=rowIndex;
$('#'+id).datagrid('endEdit',rowIndex);
$('#'+id).datagrid('beginEdit',rowIndex);
var oldordering = value;
$("input.datagrid-editable-input").val(oldordering).bind("blur",function(evt){
debugger;
var dataArry = $('#'+id).datagrid('getSelections');
eventPlayer.setLevelName($(this).val(), dataArry[0].id);
$('#'+id).datagrid('endEdit',lastIndex);
}).bind("keypress",function(evt){
if(evt.keyCode==13){
debugger;
var dataArry = $('#'+id).datagrid('getSelections');
eventPlayer.setLevelName($(this).val(), dataArry[0].id);
$('#'+id).datagrid('endEdit',lastIndex);
}
}).focus();
lastIndex=rowIndex;
}
});
//註冊分頁查詢方法
var p = $('#' + id).datagrid('getPager');
$pagination(p, {
onSelectPage: function(pageNumber, pageSize1){
getEventPlayerDataList();
}
});
el.data('datagridInit', 'finished');
}