在我的Jqgrid我有一个删除链接的列,一切都很完美,除了删除确认框一直弹出左上角.我想在jqgrid的中心有一个确认框,而不是在左上角.
{ name: 'act', index: 'act', width: 150, align: 'center', sortable: false}],
gridComplete: function () {
var rows = jQuery("#list").jqGrid('getGridParam','selrow');
var ids = jQuery("#list").jqGrid('getDataIDs');
var gr = jQuery('#list'); gr.setGridHeight("auto", true);
for (var i = 0; i < ids.length; i++) {
var cl = ids[i];
be = "<a href='#' style='height:25px;width:120px;' type='button' value='Slet' onclick=\"jQuery('#list').jqGrid('delGridRow','" + cl + "',{reloadAfterSubmit:false, url:'@Url.Action("deleteRow")'}); return false;\">Slet </>";
jQuery("#list").jqGrid('setRowData', ids[i], { act: be });
}
},
Run Code Online (Sandbox Code Playgroud)
UPDATE
be = "<a href='#' style='height:25px;width:120px;' type='button' value='Slet' onclick=\"jQuery('#list').jqGrid('delGridRow','" + cl + "', myDelParameters); return false;\">Slet </>";
Run Code Online (Sandbox Code Playgroud)
我的全局变量的代码:
myDelParameters = {reloadAfterSubmit:false, url:'@Url.Action("deleteRow")', beforeShowForm: function(form) {
// "editmodlist"
var dlgDiv = jQuery("#list").jqGrid("#delmodlist" + grid[0].id);
var parentDiv = dlgDiv.parent(); // div#gbox_list
var dlgWidth = dlgDiv.width();
var parentWidth = parentDiv.width();
var dlgHeight = dlgDiv.height();
var parentHeight = parentDiv.height();
// TODO: change parentWidth and parentHeight in case of the grid
// is larger as the browser window
dlgDiv[0].style.top = Math.round((parentHeight-dlgHeight)/2) + "px";
dlgDiv[0].style.left = Math.round((parentWidth-dlgWidth)/2) + "px";
}};
Run Code Online (Sandbox Code Playgroud)
您已经设置了delGridRow方法的一些参数(请参见{reloadAfterSubmit:false, url:...代码)。
我建议您在delGridRowafterShowForm参数列表中使用。的实现可能与旧答案类似,但使用( , where ) 而不是。afterShowForm"#delmodlist""#delmod" + grid[0].idvar grid = $("#list")$("#editmod" + grid[0].id)
另一种更简短的实现形式可能是关于jQuery UI Position:
afterShowForm = function ($form) {
$form.closest('div.ui-jqdialog').position({
my: "center",
of: $("#list").closest('div.ui-jqgrid')
});
}
Run Code Online (Sandbox Code Playgroud)
在演示中,我对所有添加/编辑和删除表单使用此类功能。
更新:在我看来,你有实施问题。我又制作了一个演示,您可以轻松修改为您想要的内容。我没有设置任何editurl,所以如果您按“删除”按钮,将会显示错误。<a>此外,您尝试放置在“act”列中的 HTML 片段是和设置的组合<button>。因为我不知道你想要什么,所以我把它放在<a>“行为”栏中。我希望现在您可以轻松修改我的演示以使您的程序正常运行。
以下是我的演示中的代码架构,您可以使用:
<script type="text/javascript">
//<![CDATA[
var myDelParameters = {
reloadAfterSubmit: false,
//url:'@Url.Action("deleteRow")',
afterShowForm: function ($form) {
'use strict';
$form.closest('div.ui-jqdialog').position({
my: "center",
of: $("#list").closest('div.ui-jqgrid')
});
}
};
$(document).ready(function () {
var grid = $("#list"),
centerForm = function ($form) {
$form.closest('div.ui-jqdialog').position({
my: "center",
of: grid.closest('div.ui-jqgrid')
});
},
getColumnIndexByName = function (mygrid, columnName) {
var cm = mygrid.jqGrid('getGridParam', 'colModel'), i = 0, l = cm.length;
for (; i < l; i += 1) {
if (cm[i].name === columnName) {
return i; // return the index
}
}
return -1;
};
grid.jqGrid({
colModel: [
...
{name: 'action', index: 'action', width: 70, align: 'center', sortable: false},
...
],
...
loadComplete: function () {
var iCol = getColumnIndexByName($(this), 'action'), iRow, row,
rows = this.rows,
cRows = rows.length;
for (iRow = 0; iRow < cRows; iRow += 1) {
row = rows[iRow];
if ($.inArray('jqgrow', row.className.split(' ')) > 0) {
$(row.cells[iCol]).html("<a href='#' style='height:25px;width:120px;' onclick=\"jQuery('#list').jqGrid('delGridRow','" +
row.id + "',myDelParameters); return false;\">Del</>");
}
}
});
});
//]]>
</script>
Run Code Online (Sandbox Code Playgroud)