我想在我的 JQGrid 中有删除功能来删除多行。我的代码如下所示:
{height:180,mtype:"POST",closeAfterDel:true, url:'gridedit.jsp',reloadAfterSubmit:true,
onclickSubmit: function (options, rowid) {
var rowData = jQuery(this).jqGrid('getRowData', rowid);
var params ={amount:rowData.amount,account:rowData.account.replace(/-/g,"")};
return params;
},
afterSubmit: function () {
$(this).jqGrid('setGridParam', {datatype:'json'});
return [true,''];
}
}
我想根据列rowData.account的值进行删除
问题是当我选择多行时,我可以看到网格将所有 rowid 传递回编辑 URL,但只传递第一行的 rowData.account 值!
有没有办法让网格传回所有的值?我无法根据后端的行 ID 删除,因为我的数据库没有任何行 ID。
请帮忙。
这是我的网格代码:
jQuery(document).ready(function(){
jQuery("#list").jqGrid({
datatype: 'json',
url:'gridfeeder.jsp?ctlSelectedDate=<%= request.getParameter("ctlSelectedDate")%>',
colNames: ['Date', 'Account ', 'Amount', 'Code'],
colModel: [
//First Column, DATE
{name: 'adate', index: 'adate', width: 300, sorttype: 'date', align: 'center',datefmt: 'Y-m-d',
editable:true, formatter: myLinkFormatter, editoptions:{
dataInit:function(elem)
{
jQuery(elem).datepicker({
showButtonPanel: true,
changeMonth: true,
changeYear: true
});
}}, search:true, stype:'text',searchoptions:{
dataInit:function(elem)
{
jQuery(elem).datepicker({
showButtonPanel: true,
changeMonth: true,
changeYear: true
});
}
}
},
//Second Column, ACCOUNT
{ name: 'account', index: 'account', width: 300, align: 'center', sorttype: 'string', editable:true,
search:true, stype:'text',editrules:{custom:true, custom_func:
//Validation for this column for editing
function(value, colname) {
if (value.length<9 || value.length>11)
return [false,"Invalid Input"];
else
return [true,""];
}
},
searchrules:{custom:true, custom_func:
//验证此列以进行搜索
function(val, colname) {
if (val.length<9 || val.length>11)
return [false,"Invalid Input"];
else
return [true,""];
}
}
},
//Third Column, AMOUNT
{ name: 'amount', index: 'amount', width: 300, align: 'center', sorttype: 'float', editable:true,
editrules:{number:true}, search:true, stype:'text'
},
//Fourth Column, CODE
{ name: 'code', index: 'code', width: 300, align: 'center', sorttype: 'float', editable:true,
search:true, stype:'text'
}
],
pager: "#pager", //Identifying the navigation bar
rowNum: 500, // how many rows to display on page 1
rowList: [500,1000, 2000, 3000,4000], //values for the dropdown which specifies how many rows to show
sortorder: "desc", //the order of sorting by default
viewrecords: true, // displays total number of rows
gridview: true,
autoencode: true,
height:400, //height of the grid
ignoreCase:true,// case insensitive search
multiselect:true, // checkboxes before each row
multiboxonly: true,
loadonce:true, //for client side sorting, searching and pagination
caption:"This is me" // caption for the grid header
这是导航网格部分:
}).navGrid('#pager',{edit:true,add:true,del:true,search:true,refresh:true},
// Options for EDIT
{height:280,mtype: "POST",closeAfterEdit: true,reloadAfterSubmit:true, url:'gridedit.jsp',
recreateForm: true,
//set some properties beofre the dialog box is seen by the user
beforeShowForm: function(form) {
/*$('#adate',form).attr('readonly','readonly');
$('#account',form).attr('readonly','readonly');*/
$('#adate',form).hide();
$('#account',form).hide();
},
// what happens when the user clicks submit. passing extra parameters
onclickSubmit: function (options, postdata) {
var rowid = postdata[this.id + "_id"]; // postdata.list_id
var dataF = jQuery('#list').jqGrid ('getCell', rowid, 'account');
return {account:dataF.replace(/-/g,"")};
},
// changing the datatype
afterSubmit: function () {
$(this).jqGrid("setGridParam", {datatype: 'json'});
return [true,''];
}
},
//ADD options
{height:280,mtype:"POST", closeAfterAdd:true, reloadAfterSubmit:true, url:'gridedit.jsp',
beforeShowForm: function(form) {
/*var cm = jQuery("#list").jqGrid('getColProp','adate');
alert(cm);
cm.editable = false;
$('#adate',form).attr('readonly','readonly');
$('#account',form).attr('readonly','readonly');*/
$('#adate',form).show();
$('#account',form).show();
},
//Change the datatype
afterSubmit: function () {
$(this).jqGrid("setGridParam", {datatype: 'json'});
return [true, ""];
}
},
{height:180,mtype:"POST",closeAfterDel:true, url:'gridedit.jsp',reloadAfterSubmit:true,
/* onclickSubmit: function (options, rowid) {
var rowData = jQuery(this).jqGrid('getRowData', rowid);
var params ={account:rowData.account.replace(/-/g,"")};
return params;
},*/
delData: {
account: function() {
var sel_id = $("#list").jqGrid('getGridParam', 'selrow');
var value = $("#list").jqGrid('getCell', sel_id, 'account');
return value.replace(/-/g,"");
}
},
afterSubmit: function () {
$(this).jqGrid('setGridParam', {datatype:'json'});
return [true,''];
}
}
);
function myLinkFormatter(cellvalue, options, rowObject) {
return "<a href='account094act.jsp?GETDATE=" + cellvalue + "&GETACC=" + rowObject[1] + "'>" + cellvalue + "</a>";
}
jQuery("#refresh_list").click(function(){
jQuery("#list").setGridParam({datatype: 'json'});
jQuery("#list").trigger("reloadGrid");
});
});