1. 程式人生 > >easyui 雙擊datagrid編輯

easyui 雙擊datagrid編輯


$('#domainGrid').datagrid({
    onDblClickCell: function(index,field,value){
        $(this).datagrid('beginEdit', index);
        var ed = $(this).datagrid('getEditor', {index:index,field:field});
        $(ed.target).focus();
    }
});

$(document).ready(function (){
    change();
});

function change
(){
$("#domainGrid").datagrid({ columns:[[ {field:'domain_name',width:'80%',editor:'text',title:'領域標識'}, {field:'',width:'15%',title:'操作', formatter:function(value,row,index){ if (row.editing){ var a="'"+row.domain_name+"'"; var s = ''
,'+row.id+','+a+')">儲存 '; var c = '')">取消'; return s+c; }else { //var e = '編輯 '; var d = '','+row.id+')">刪除'; return d; } } } ]], onBeforeEdit:function(index,row)
{
row.editing = true; $('#domainGrid').datagrid('refreshRow', index); }, onAfterEdit:function(index,row,changes){ //當有endEdit時才觸發onAfterEdit; //alert("onafteredit:"+row.id); //alert(changes.domain_name); var domainBean={id:row.id,domain_name:changes.domain_name}; var entity=JSON.stringify(domainBean); $.post('/system/saveDomain',{entity:entity},function(data){ $('#domainGrid').datagrid('reload'); $.messager.alert('提示',data.message); // $('#systemForm').form('clear'); }); row.editing = false; $('#domainGrid').datagrid('refreshRow', index); }, onCancelEdit:function(index,row){ row.editing = false; $('#domainGrid').datagrid('refreshRow', index); } }) } function getRowIndex(target){ var tr = $(target).closest('tr.datagrid-row'); change(); return parseInt(tr.attr('datagrid-row-index')); } function saverow(index,mid,mvalue){ $('#domainGrid').datagrid("endEdit", index); $('#domainGrid').datagrid('endEdit', getRowIndex(index)); } function cancelrow(target){ $('#domainGrid').datagrid('cancelEdit', getRowIndex(target)); } function deleterow(target,mid){ $.messager.confirm('提示','確定刪除當前記錄?',function(r){ if(r){ $.get('/system/deleteDomain/'+mid,function(data){ $('#domainGrid').datagrid('reload'); $.messager.alert('提示',data.message); }); } }); }