参考: [url]http://www.debugease.com/javascript/200760.html[/url]
[size=large][color=red]开始处理方式[/color][/size]
1. 工具栏方式, 定义navGrid变量的时候,
下面配置删除后处理配置:
{
......
del: true,
delicon: 'icon-trash red',
......
}
......
{
//delete record form
recreateForm: true,
/*beforeShowForm: function (e) {
var form = $(e[0]);
if (form.data('styled')) return false;
form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('');
$.GridUtils.style_delete_form(form);
form.data('styled', true);
},*/
beforeShowForm: $.GridUtils.beforeDeleteCallback,
afterSubmit:function(data,postdata){
alert("afterSubmit");
return [true,""]; //返回0表示正常
},
afterComplete:function(data,postdata){
alert("afterComplete");
//这里不用返回
}
}
2. 如果是colModel里面配置:
{
name: 'myac', index: '', width: 80, fixed: true, sortable: false, resize: false,
formatter: 'actions',
formatoptions: {
keys: true,
delOptions: {recreateForm: true, beforeShowForm: $.GridUtils.beforeDeleteCallback,afterSubmit:function(data,postdata){
alert("afterSubmit1");
return [true,""]; //返回0表示正常
},
afterComplete:function(data,postdata){
alert("afterComplete1");
//这里不用返回
}},
editformbutton:true, editOptions:{recreateForm: true, beforeShowForm:$.GridUtils.beforeEditCallback,afterShowForm:$.GridUtils.afterEditCallback}
}
}
[size=large][color=red]非改源码扩展[/color][/size]
1. 在初始化表格的配置加上自定义的方法
afterSubmit:function(data,postdata){
alert("afterSubmit");
return [true,""];//原样返回.
},
afterComplete:function(data,postdata){
alert("afterComplete");
}
2. 重写事件后要处理的方法
function afterSubmitCallback(data,postdata){
//用于提交事件完成后处理
alert("afterSubmitCallback");
var $t=this;
if($.isFunction($t.p.afterSubmit)){
return $t.p.afterSubmit(data,postdata);
}else{
return [true,""];//原样返回.
}
}
function afterCompleteCallback(data,postdata){
//用于提交事件完成后处理
alert("afterCompleteCallback");
var $t=this;
if($.isFunction($t.p.afterComplete)){
$t.p.afterComplete(data,postdata);
}
}
3. 改变调用的地方, 让他们调用同一处地方
工具条
{
//delete record form
recreateForm: true,
/*beforeShowForm: function (e) {
var form = $(e[0]);
if (form.data('styled')) return false;
form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('');
$.GridUtils.style_delete_form(form);
form.data('styled', true);
},*/
beforeShowForm: $.GridUtils.beforeDeleteCallback,
afterSubmit: afterSubmitCallback,
afterComplete:afterCompleteCallback
}
colModel:
{
name: 'myac', index: '', width: 80, fixed: true, sortable: false, resize: false,
formatter: 'actions',
formatoptions: {
keys: true,
delOptions: {recreateForm: true, beforeShowForm: $.GridUtils.beforeDeleteCallback,afterSubmit: afterSubmitCallback,
afterComplete:afterSubmitCallback},
editformbutton:true, editOptions:{recreateForm: true, beforeShowForm:$.GridUtils.beforeEditCallback,afterShowForm:$.GridUtils.afterEditCallback,afterSubmit: afterSubmitCallback,
afterComplete:afterCompleteCallback}
}
}
[size=large][color=red]如果后台要返回自己定义的成功或者错误信息, 那又如何显示呢?[/color][/size]
1. controller返回一个对象:
@RequestMapping(value = "/saveGrid.do")
@ResponseBody
public ControllerContext saveGrid(HttpServletRequest request, @RequestBody Map
params) {
System.out.println(JSONUtil.toJSONString(params));
ControllerContext context=new ControllerContext();
context.addMessage("保存成功.");
context.setSuccess(true);
context.setStatus(168);
return context;
}
2. 这个返回的信息保存在:data.responseJSON, data.responseText里面, 可以自己使用.