您好,登錄后才能下訂單哦!
神馬是easyui
jQuery EasyUI是一組基于jQuery的UI插件集合,而jQuery EasyUI的目標就是幫助web開發者更輕松的打造出功能豐富并且美觀的UI界面。開發者不需要編寫復雜的javascript,也不需要對css樣式有深入的了解,開發者需要了解的只有一些簡單的html標簽。
jQuery EasyUI為我們提供了大多數UI控件的使用,如:accordion,combobox,menu,dialog,tabs,tree,validatebox,window等等。
下面通過代碼看下easyui datagird編輯行刪除行功能,具體代碼如下所示:
function init(){ var editRow = undefined; var oldMoney = undefined; $("#dg").datagrid({ url:"../foreignexchange/fexLedgerManager.do?method=queryApplyData&parentId="+parentId, fitColumns:false,//自適應寬度,占滿,不能和凍結列同時設置成true striped:true, //斑馬線效果 singleSelect:false, //是否單選 pagination:false, height:140, columns:[[ {field:"id", title:"主鍵", width:'10', align:"center",hidden:true}, {field:"applyNo", title:"申報單號", width:'250', align:"center",editor: { type: 'validatebox', options: { required: true } }}, {field:"exeMoneyString", title:"執行金額", width:'200', align:"center",editor: { type: 'moneybox', options: {precision:2, required: true } }}, {field:"exchangeRate", title:"執行匯率(%)", width:'210', align:"center",editor: { type: 'numberbox', options: {precision:5, required: true } }}, {field:"submitDate", title:"提交日期", width:'190', align:"center",editor: { type: 'datebox', options: { required: true } }}, {field:"executeDate", title:"執行日期", width:'190', align:"center",editor: { type: 'datebox', options: { required: true } }} ]], toolbar: [{ text: '添加', iconCls: 'icon-add', handler: function () { if (editRow != undefined) { $("#dg").datagrid('endEdit', editRow); } if (editRow == undefined) { var submitDate = $("#submitDate").val(); $("#dg").datagrid('insertRow', { index: 0, row: {submitDate:submitDate} }); $("#dg").datagrid('beginEdit', 0); editRow = 0; } } }, /*'-', { text: '撤銷', iconCls: 'icon-redo', handler: function () { editRow = undefined; $("#dg").datagrid('rejectChanges'); $("#dg").datagrid('unselectAll'); } },*/ '-', { text: '刪除', iconCls: 'icon-remove', handler: function () { var row = $("#dg").datagrid('getSelected'); if(row){ var index = $("#dg").datagrid("getRowIndex",row); $("#dg").datagrid('deleteRow',index); }else{ $("#dg").datagrid('endEdit', 0); $("#dg").datagrid('deleteRow',0); editRow = undefined; } } }, '-', { text: '修改', iconCls: 'icon-edit', handler: function () { var row = $("#dg").datagrid('getSelected'); oldMoney = row.exeMoneyString; if (row !=null) { if (editRow != undefined) { $("#dg").datagrid('endEdit', editRow); } if (editRow == undefined) { var index = $("#dg").datagrid('getRowIndex', row); $("#dg").datagrid('beginEdit', index); editRow = index; $("#dg").datagrid('unselectAll'); } } else { } } }, '-', { text: '保存', iconCls: 'icon-save', handler: function () { var opeRow = editRow; $("#dg").datagrid('endEdit', editRow); var rows = $("#dg").datagrid('getChanges'); if(!rows ||rows.length==0){ alert("無修改數據,無需保存!"); return false; } var allRows = $("#dg").datagrid('getData'); var executeMoney = $("#executeMoney").val(); var sum = 0; var money = 0; $.each(allRows.rows,function(i,row){ row.parentId = parentId; money = formatMeony(row.exeMoneyString); sum+=money; }); if(sum>executeMoney){ alert("執行金額超出臺賬登記執行金額!"); if(oldMoney){ $("#dg").datagrid('updateRow', { index: opeRow, row: {exeMoneyString:oldMoney} }); } $("#dg").datagrid('beginEdit', opeRow); $("#dg").datagrid('unselectAll'); return false; } //新增 var addRows = $("#dg").datagrid('getChanges','inserted'); //修改 var updateRows = $("#dg").datagrid('getChanges','updated'); //刪除 var delRows = $("#dg").datagrid('getChanges','deleted'); var addOrUpdate = $.merge(addRows,updateRows); var addOrUpdateStr = JSON.stringify(addOrUpdate); var delRowsStr = JSON.stringify(delRows); $.ajax({ type:'post', url:'../foreignexchange/fexLedgerManager.do', data : { "method" : $("#method").val(), "addOrUpdateStr" : addOrUpdateStr, "delRowsStr" : delRowsStr }, cache:false, dataType:'json', success:function(data){ if(data.success){ alert(data.msg); init(); }else{ alert(data.msg); } } }); } }], onAfterEdit: function (rowIndex, rowData, changes) { editRow = undefined; }, onDblClickRow:function (rowIndex, rowData) { if (editRow != undefined) { $("#dg").datagrid('endEdit', editRow); } if (editRow == undefined) { $("#dg").datagrid('beginEdit', rowIndex); editRow = rowIndex; var row = $("#dg").datagrid('getSelected'); oldMoney = row.exeMoneyString; } }, onClickRow:function(rowIndex,rowData){ if (editRow != undefined) { $("#dg").datagrid('endEdit', editRow); } } }); } function formatMeony(value){ var money =value; var temp = money.split(","); var result = ""; var value = 0; var size = temp.length; for (var j = 0; j < size; j++) { result = result + temp[j]; } value = parseFloat(result); return value; }
總結
以上所述是小編給大家介紹的jQuery easyui datagird編輯行刪除行功能的實現代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對億速云網站的支持!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。