我遇到了 jqGrid 数据网格的问题。我需要使用“删除”按钮删除一行或多行。这是我的代码:
$grid.navGrid('#pager', { edit: false, add: false, del: false, search: false });
$grid.navButtonAdd('#pager', {
caption: "Delete",
buttonicon: "ui-icon-del",
position: "last",
onClickButton: function() {
alert("Deleting Row");
row_ids = $grid.getGridParam('selarrrow');
$grid.delGridRow(row_ids, {
dataType: 'json',
mtype: 'GET',
url: '<?php echo $_SERVER['PHP_SELF'].'?app=my_app&action=record_delete'; ?>'
});
}
});
这段代码将所选行的 id/s 发送到“url:”选项(它有效)。该 url 以 json 格式返回一个响应。这个答案说明操作是否成功。我需要显示带有该消息的警报,我该怎么做?而且,另一个问题是,当我单击“删除”按钮(在 jqGrid 底部)时,它会显示一个带有问题“您要删除选定项目吗?”的 ajax 窗口,带有“是”输入和“否” “ 输入。当我单击“是”时,此 ajax 窗口将不会关闭!
谢谢!
但丁
编辑 [1] && [2]
$(document).ready(function()
{
$grid = $("#list");
fixPositionsOfFrozenDivs = function() {
if (typeof this.grid.fbDiv !== "undefined") {
$(this.grid.fbDiv).css($(this.grid.bDiv).position());
}
if (typeof this.grid.fhDiv !== "undefined") {
$(this.grid.fhDiv).css($(this.grid.hDiv).position());
}
};
$grid.jqGrid({
url: '<?php echo $_SERVER['PHP_SELF'].'?app=my_app&option=get_records'; ?>',
datatype: 'json',
mtype: 'GET',
height: 'auto',
width: window.innerWidth-35, //width: '1225',
colNames: ['ID', 'Column A', 'Column B', 'Column C', 'Column D'],
colModel: [
{ name: 'id', index: 'id', width: 130, align: 'center', search: true,
sortable: true, frozen: true, editable: true, edittype: 'text', formatter: 'showlink',
editoptions: { size: 130, maxlength: 50 }, stype: 'text' },
{ name: 'col_a', index: 'col_a', width: 250, align: 'left', search: true,
sortable: true, frozen: false, editable: true, edittype: 'text',
editoptions: { size: 250, maxlength: 40 }, stype: 'text' },
{ name: 'col_b', index: 'col_b', width: 120, align: 'left', search: true,
sortable: true, frozen: false, editable: true, edittype: 'text',
editoptions: { size: 120, maxlength: 40 }, stype: 'text' },
{ name: 'col_c', index: 'col_c', width: 100, align: 'right', search: true,
sortable: true, frozen: false, editable: true, edittype: 'text',
editoptions: { size: 100, maxlength: 40 }, stype: 'text' },
{ name: 'col_d', index: 'col_d', width: 100, align: 'right', search: true,
sortable: true, frozen: false, editable: true, edittype: 'text',
editoptions: { size: 100, maxlength: 6 }, stype: 'text' }
],
caption: 'Objects',
pager: '#pager',
sortname: 'id',
sortorder: 'ASC',
rowNum: 25,
rowList: [25, 50, 100, 200, <?php echo $totrecords; ?>],
loadonce: true,
gridview: true,
viewrecords: true,
rownumbers: true,
rownumWidth: 40,
toppager: true,
multiselect: true,
autoencode: true,
ignoreCase: true,
shrinkToFit: false,
loadComplete: function() {
$("option[value=<?php echo $totrecords; ?>]").text('All');
},
editurl: '<?php echo $_SERVER['PHP_SELF'].'?app=my_app&option=delete_records'; ?>'
});
$grid.jqGrid('filterToolbar', {multipleSearch: false, stringResult: false, searchOnEnter: false, defaultSearch: 'cn'});
$grid.navGrid('#pager', { edit: false, add: false, del: false, search: false });
$grid.navButtonAdd('#pager', {
caption: "Delete",
buttonicon: "ui-icon-del",
position: "last",
onClickButton: function() {
row_ids = $grid.getGridParam('selarrrow');
$grid.delGridRow(row_ids, {
closeOnEscape: true,
mtype: 'POST',
afterSubmit: function(data_from_server, array_data) {
var result = data_from_server.responseText;
var message = eval('(' + result + ')');
alert(message.query);
}
});
}
});
$grid.jqGrid('setFrozenColumns');
$grid[0].p._complete.call($grid[0]);
fixPositionsOfFrozenDivs.call($grid[0]);
});