datagrid 新增,并行内编辑,提交保存
<a class="mini-button" iconCls="icon-add" onclick="addRow()" plain="true" tooltip="增加...">增加</a> <a class="mini-button" iconCls="icon-remove" onclick="removeRow()" plain="true">删除</a> <a class="mini-button" iconCls="icon-remove" onclick="save()" plain="true">保存</a>
<div id="datagrid1"class="mini-datagrid" url="${ctx}/lYCOMPANYFJH/query" autoload="false"dataField="rows" allowResize="false" sortField="LC" sortOrder="asc"pageSize="20" allowCellEdit="true"allowCellSelect="true" multiSelect="true" editNextOnEnterKey="true" editNextRowCell="true"style="width: 100%; height: 100%; border:0;"> <div property="columns"> <div field="LC" width="120" align="center" headeralign="center">楼层 <input property="editor" id="LC1"onclick="onLC(1)" class="mini-combobox" style="width:100%;" required="true"/> </div> <div field="FJH" width="120" align="center" headeralign="center">房间号 <input property="editor"id="FJH1"onclick="onFJH(1)"class="mini-combobox" style="width:100%;" required="true"/> </div> </div> </div>
js代码
var datagrid1=mini.get("datagrid1"); function addRow() { var newRow = { name: "New Row" }; datagrid1.addRow(newRow, 0); datagrid1.beginEditCell(newRow, "LoginName"); } function removeRow() { var rows = datagrid1.getSelecteds(); if (rows.length > 0) { if (confirm("确定删除此记录?")) { var row = rows[0]; datagrid1.loading("删除中,请稍后......"); $.ajax({ url: "${ctx}/lYCOMPANYFJH/delete?&ID=" + row.ID, success: function (text) { datagrid1.reload(); }, error: function () { } }); } } } function save(){ //形式为[{"":""."":""}] var json = mini.encode(datagrid1.getChanges()); mini.get("QYMJ").setValue(json); $('#editForm').submit(); }
java代码
String QYMJ=getPara("QYMJ"); List<JSONObject> list= JSON.parseArray(QYMJ,JSONObject.class); for(JSONObject li:list){ System.out.println(li.get("ID")); }