当 easyui-datagrid 里面添加 editor 可编辑的行时无效,发现需要先将此 easyui-datagrid 设置为 enableCellEditing 可编辑状态。设置完之后才能使用 editor 进行对行的编辑。而这个方法在官方文档里却没提过 =_=|| ,好坑啊。。。
代码如下
html
<table id="dg" rownumbers="true" fitColumns="true" text-align="center" class="easyui-datagrid" style="width:100%;height:100%;"
data-options="url:'',loadMsg:'数据处理中,请稍后.....', singleSelect:true, scrollbarSize:0">
<thead>
<tr>
<th data-options="field:'name',width:145,align:'center'">名称</th>
<th data-options="field:'number',width:90,align:'center'" editor="{type:'numberbox',options:{min:1,max:999,value:0}}">数量</th>
</tr>
</thead>
</table>
js
<script type="text/javascript">
$(function() {
$("#dg").datagrid("enableCellEditing");
})
</script>
保存时结束对行的编辑
var index = $('#dg').datagrid('getRowIndex',$('#dg').datagrid('getSelected'));
$('#dg').datagrid('endEdit',index);