问题描述
jqgrid删除按钮出问题我写的代码如下:function getGrid(){ // 定义标题(列) var c_fild = new Array(); var colm = new Array(); c_fild = s_fild.split(","); for(i=0;i<c_fild.length;i++){ colm.push({display: c_fild[i],name : c_fild[i], width :120, sortable : true, align: 'center'}); } $(function(){jQuery("#list2").jqGrid({ url: 'post.jsp?s_table='+s_table+'&s_id='+s_id+'&s_fild='+s_fild+'&s_where='+s_where,datatype: "json",mtype: 'POST', /* colNames:['id','username', 'password', 'age','address'], colModel:[ {name:'id',index:'id', width:55}, {name:'username',index:'username', width:90}, {name:'password',index:'password', width:100}, {name:'age',index:'age', width:80, align:"right"}, {name:'address',index:'address', width:80, align:"right"} ], */ colModel:colm, rowNum:4, rowList:[4,20,30], pager: $('#pager2'), sortname: 'id', viewrecords: true, sortorder: "asc", //height:'500px', //width:'800px',jsonReader: {//jsonReader来跟服务器端返回的数据做对应 root: "rows", page: "page", total: "total", repeatitems : false }, caption:"JSON Example"}).navGrid('#pager2',{editfunc:doEdit,addfunc:doAdd,delfunc:doDel});});}var doEdit=function(rowid){alert(rowid);};var doAdd=function(){alert(126);};var doDel=function(){alert(123);}; 为什么选中行点删除的时候 没有123弹出,而是弹出默认的删除界面。而点增加修改时没有问题。请用过的人指点。谢谢了! 问题补充:谢了,你这样写是可以的,后面我也是这么写的。<br />但是我就不明白为什么其它两个方法可以那样写,删除就不可以了。<div class="quote_title">liukai 写道</div><div class="quote_div">写成<pre name="code" class="javascript">jq("#grid").navButtonAdd('#pager',{ caption:"Delete", buttonicon:"ui-icon-trash", onClickButton: deleteRow,position: "last", title:"", cursor: "pointer"} );function deleteRow() {// Get the currently selected row获得当前选择的选项 var row = jq("#grid").jqGrid('getGridParam','selrow'); var len = rows.length;if( rows != null ){jq("#grid").jqGrid( 'delGridRow', row, { url: '/spring3JqGrid/crud/delete', recreateForm: true, beforeShowForm: function(form) { //change title jq(".delmsg").replaceWith('<span style="white-space: pre;">' + 'Delete selected record?' + '</span>'); //hide arrows jq('#pData').hide(); jq('#nData').hide(); }, reloadAfterSubmit:false, closeAfterDelete: true, afterSubmit : function(response, postdata) { var result = eval('(' + response.responseText + ')');var errors = ""; if (result.success == false) {for (var i = 0; i < result.message.length; i++) {errors += result.message[i] + "<br/>";} } else { jq("#dialog").text('Entry has been deleted successfully');jq("#dialog").dialog( {title: 'Success',modal: true,buttons: {"Ok": function() {jq(this).dialog("close");} }}); } // only used for adding new records var new_id = null; return [result.success, errors, new_id];} }); }else{ jq( "#dialogSelectRow" ).dialog();}</pre><br /><br /></div><br />
解决方案
写成jq("#grid").navButtonAdd('#pager',{ caption:"Delete", buttonicon:"ui-icon-trash", onClickButton: deleteRow,position: "last", title:"", cursor: "pointer"} );function deleteRow() {// Get the currently selected row获得当前选择的选项 var row = jq("#grid").jqGrid('getGridParam','selrow'); var len = rows.length;if( rows != null ){jq("#grid").jqGrid( 'delGridRow', row, { url: '/spring3JqGrid/crud/delete', recreateForm: true, beforeShowForm: function(form) { //change title jq(".delmsg").replaceWith('<span style="white-space: pre;">' + 'Delete selected record?' + '</span>'); //hide arrows jq('#pData').hide(); jq('#nData').hide(); }, reloadAfterSubmit:false, closeAfterDelete: true, afterSubmit : function(response, postdata) { var result = eval('(' + response.responseText + ')');var errors = ""; if (result.success == false) {for (var i = 0; i < result.message.length; i++) {errors += result.message[i] + "<br/>";} } else { jq("#dialog").text('Entry has been deleted successfully');jq("#dialog").dialog( {title: 'Success',modal: true,buttons: {"Ok": function() {jq(this).dialog("close");} }}); } // only used for adding new records var new_id = null; return [result.success, errors, new_id];} }); }else{ jq( "#dialogSelectRow" ).dialog();}