jqgrid行编辑

ondblClickRow: function(id){
	if(id && id !== lastsel){
		var rowData = $("#jqGridId").jqGrid("getRowData", id); 
		$('#jqGridId').jqGrid('restoreRow',lastsel);
		$('#jqGridId').jqGrid('editRow',id,{
			keys : true,		//这里按[enter]保存
			url: s2web.appURL + "jq/save.action",
			mtype : "POST",
			restoreAfterError: true,
			extraparam: {
				"ware.id": rowData.id,
				"ware.warename": $("#"+id+"_name").val(),
				"ware.createDate": $("#"+id+"_date").val(),
				"ware.number": $("#"+id+"_amount").val(),
				"ware.valid": $("#"+id+"_type").val()
			},
			oneditfunc: function(rowid){
				console.log(rowid);
			},
			succesfunc: function(response){
				alert("save success");
				return true;
			},
			errorfunc: function(rowid, res){
				console.log(rowid);
				console.log(res);
			}
		});
	}
}


 

jQuery("#grid_id").jqGrid('editRow',rowid, keys, oneditfunc, succesfunc, url, extraparam, aftersavefunc,errorfunc, afterrestorefunc);


 

jQuery("#grid_id").jqGrid('editRow',rowid,  {
	"keys" : false,
	"oneditfunc" : null,
	"successfunc" : null,
	"url" : null,
        	"extraparam" : {},
	"aftersavefunc" : null,
	"errorfunc": null,
	"afterrestorefunc" : null,
	"restoreAfterError" : true,
	"mtype" : "POST"
});


 

这里对以上各个参数的意思做一个简单的描述
  • rowid:当前编辑的rowid
  • succesfunc:如果定义了改函数,将会在请求成功调用后立即返回,该函数签名包括server返回的数据。同时该函数需要返回tue/false
  • url: 如果定义了改值,将会覆盖jqGrid中的editurl(当然,如果没有url和editurl是会报错的)。如果url="clientArray" 那么就不会向server端触发请求,可在后期手动调用修改
  • extraparam:请求参数列表{name:value, name:value},将会append到requestData中向server端发送
  • aftersavefunc:如果定义了改函数,将会在数据向server端保存后立即调用,该函数接受rowid、response参数。同样如果是上面的url="clientArray"该函数同样执行
  • errorfunc:如果定义了改函数,将会在数据向server端保存后调用,该函数接受rowid、response参数
  • afterrestorefunc:如果定义了改函数,将在restoreRow后调用,接受rowid作为参数
http://www.trirand.com/jqgridwiki/doku.php?id=wiki:inline_editing 中对于innerEdit主要有以下几个方法:
写道
editRow //在用户出发edit事件时调用该方法
saveRow //用户不需要调用该方法,在edit时会自动调用
restoreRow //回滚当前editRow
addRow //新增row
inlineNav

 

 

$("#addBtn").bind("click", function() {
		$("#jqGridId").jqGrid('addRow',{
			rowID : "new_row",
		    initdata : {},
		    position :"first",
		    useDefValues : true,
		    useFormatter : true,
		    addRowParams : {extraparam:{
		    	
		    }}
		});
		//当前新增id进入可编辑状态
		$('#jqGridId').jqGrid('editRow','new_row',{
			keys : true,		//这里按[enter]保存
			url: s2web.appURL + "jq/save.action",
			mtype : "POST",
			restoreAfterError: true,
			extraparam: {
			},
			oneditfunc: function(rowid){
				console.log(rowid);
			},
			succesfunc: function(response){
				alert("save success");
				return true;
			},
			errorfunc: function(rowid, res){
				console.log(rowid);
				console.log(res);
			}
		});
	
}); 


 

转自 http://mj4d.iteye.com/blog/1633462
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
您好,针对您的问题,我可以给您提供一些思路和代码示例,希望能帮到您。 首先,要实现 jqgrid编辑和单元格下拉框选择功能,您需要引入以下两个插件: 1. jqGrid:这是一个 jQuery 插件,用于实现表格的展示和编辑功能。 2. select2:这是一个 jQuery 插件,用于实现下拉框的选择和搜索功能。 接下来,您需要在 jqGrid 中定义一个列模型,其中包含需要编辑的列和下拉框列。例如: ``` colModel: [ { name: 'id', index: 'id', editable: false, width: 50 }, { name: 'name', index: 'name', editable: true, edittype: 'text', width: 100 }, { name: 'gender', index: 'gender', editable: true, edittype: 'select', editoptions: { value: 'M:Male;F:Female', dataInit: function(elem) { $(elem).select2({ width: '100%' }); } }, width: 100 } ] ``` 在上面的代码中,第一列是 ID 列,不可编辑;第二列是姓名列,可以编辑编辑类型为文本框;第三列是性别列,可以编辑编辑类型为下拉框,下拉框的选项值为 M:Male 和 F:Female,同时使用 select2 插件进渲染。 最后,在 jqGrid 中启用编辑功能和单元格编辑功能,例如: ``` editurl: 'server.php', cellEdit: true, cellsubmit: 'clientArray', rownumbers: true, rownumWidth: 40, pager: '#pager', viewrecords: true, caption: 'My first grid', height: 'auto', width: 'auto', ``` 在上面的代码中,editurl 属性指定了提交数据的 URL,cellEdit 属性启用了单元格编辑功能,cellsubmit 属性指定了提交数据的方式,rownumbers 属性启用了号列,pager 属性指定了分页控件的 ID,viewrecords 属性启用了记录总数和分页信息的显示,caption 属性指定了表格的标题,height 和 width 属性指定了表格的高度和宽度。 以上就是实现 jqGrid 编辑和单元格下拉框选择的思路和代码示例,希望能对您有所帮助。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值