imd*_*sen 5 jquery modal-dialog jqgrid
我用Jquery模式对话框为Delete创建了JQGrid.如果我把它留空并且按下提交它将弹出消息请输入名字但是问题是Inbuilt Popup消息和我的jquery模式对话框看起来太不同了,需要内联编辑和一个字段的Jqgrid.
内置JQGrid模态对话框:

JQuery模态对话框
码:
function createGrid() {
jQuery("#list").jqGrid({
url: '@Url.Action("JQGridGetGridData", "TabMaster")',
datatype: 'json',
mtype: 'GET',
colNames: ['col ID', 'First Name', 'Last Name', ''],
colModel: [{ name: 'colID', index: 'colID', width: 100, align: 'left', searchoptions: { sopt: ['eq', 'ne', 'cn']} },
{ name: 'FirstName', index: 'FirstName', width: 150, align: 'left', editable: true, editrules: { required: true} },
{ name: 'LastName', index: 'LastName', width: 150, align: 'left', editable: true, editrules: { required: true} },
{ name: 'act', index: 'act', width: 60, sortable: false}],
pager: jQuery('#pager'),
hidegrid: false,
rowNum: 100,
rowList: [10, 50, 100, 150],
sortname: 'colID',
sortorder: "asc",
viewrecords: true,
multiselect: false,
width: 500,
height: "250px",
imgpath: '@Url.Content("~/Scripts/themes/steel/images")',
caption: 'Tab Master Information',
editurl: '@Url.Action("JQGridEdit", "TabMaster")',
gridComplete: function () {
var ids = jQuery("#list").getDataIDs();
for (var i = 0; i < ids.length; i++) {
var id = ids[i];
be = "<a href='#'><div title='Edit' id='action_edit_" + id + "' class='actionEdit' onclick='inlineEdit(" + id + ");'></div></a>";
de = "<a href='#'><div title='Delete' id='action_delete_" + id + "' class='actionDelete' onclick='inlineDelete(" + id + ");'></div></a>";
se = "<a href='#'><div title='Save' style='display:none' id='action_save_" + id + "' class='actionSave' onclick='inlineSave(" + id + ");'></div></a>";
ce = "<a href='#'><div title='Cancel' style='display:none' id='action_cancel_" + id + "' class='actionCancel' onclick='inlineCancel(" + id + ");'></div></a>";
jQuery("#list").setRowData(ids[i], { act: be + de + se + ce })
}
}
}).navGrid('#pager', { edit: false, add: false, del: false, search: false, refresh: false });
}
Run Code Online (Sandbox Code Playgroud)
如何为JQGrid内置对话框皮肤应用Jquery模态对话框?
谢谢,Imdadhusen
jqGrid 是 jQuery 插件,而不是 jQuery UI 小部件。所以它不使用 jQuery UI 对话框。相反,它使用$.jgrid.createModal、$.jgrid.viewModal和$.jgrid.hideModal方法。在某些情况下,使用简化版本$.jgrid.info_dialog 。许多人(包括我)希望下一个版本中的 jqGrid 将在内部使用更多 jQuery UI 控件,并且可能会是一个 jQuery UI 小部件,但现在如果您想以 jqGrid 样式创建对话框,您应该使用我介绍的方法。以上所列。
作为函数使用的示例,我建议使用以下示例,该示例使用delGridRow方法创建与 jqGrid 相同的对话框。我在演示中包含了“删除”导航按钮来显示,如果您首先使用创建对话框的“删除所选行”按钮,然后使用“删除”导航按钮,jqGrid 将不会创建新对话框。相反,将使用我们的自定义对话框。
对应的代码如下:
var grid = $("#list"),
gID = grid[0].id, //grid[0].p.id,
IDs = {
themodal:'delmod'+gID,
modalhead:'delhd'+gID,
modalcontent:'delcnt'+gID,
scrollelm:'DelTbl_'+gID
},
hideDialog = function() {
$.jgrid.hideModal("#"+IDs.themodal,{gb:"#gbox_"+gID,jqm:true, onClose: null});
},
rowId,
createDeleteDialog = function() {
var dlgContent =
"<div id='"+IDs.scrollelm+"' class='formdata' style='width: 100%; overflow: auto; position: relative; height: auto;'>"+
"<table class='DelTable'>"+
"<tbody>"+
"<tr id='DelError' style='display: none'>"+
"<td class='ui-state-error'></td>"+
"</tr>"+
"<tr id='DelData' style='display: none'>"+
"<td>"+rowId+"</td>"+ // it has not so much sense
"</tr>"+
"<tr>"+
"<td class='delmsg' style='white-space: pre;'>"+$.jgrid.del.msg+"</td>"+
"</tr>"+
"<tr>"+
"<td> </td>"+
"</tr>"+
"</tbody>"+
"</table>"+
"</div>"+
"<table cellspacing='0' cellpadding='0' border='0' class='EditTable' id='"+IDs.scrollelm+"_2'>"+
"<tbody>"+
"<tr>"+
"<td>"+
"<hr class='ui-widget-content' style='margin: 1px' />"+
"</td>"+
"</tr>"+
"<tr>"+
"<td class='DelButton EditButton'>"+
"<a href='javascript:void(0)' id='dData' class='fm-button ui-state-default ui-corner-all'>Delete</a>"+
" <a href='javascript:void(0)' id='eData' class='fm-button ui-state-default ui-corner-all'>Cancel</a>"+
"</td>"+
"</tr>"+
"</tbody>"+
"</table>";
if ($('#'+IDs.themodal).length===0) {
// dialog not yet exist. we need create it.
$.jgrid.createModal(
IDs,
dlgContent,
{
gbox: "#gbox_"+gID,
caption: $.jgrid.del.caption,
jqModal: true,
left: 12,
top: 44,
overlay: 10,
width: 240,
height: 'auto',
zIndex: 950,
drag: true,
resize: true,
closeOnEscape: true,
onClose: null
},
"#gview_"+gID,
$("#gview_"+gID)[0]);
$("#dData","#"+IDs.scrollelm+"_2").click(function(){
// "Delete" button is clicked
var rowId = grid.jqGrid('getGridParam', 'selrow');
grid.jqGrid('delRowData',rowId);
//$.jgrid.hideModal("#"+IDs.themodal,{gb:"#gbox_"+gID,jqm:true, onClose: null});
hideDialog();
});
$("#eData", "#"+IDs.scrollelm+"_2").click(function(){
// "Cancel" button is clicked
//$.jgrid.hideModal("#"+IDs.themodal,{gb:"#gbox_"+gID,jqm:true, onClose: null});
hideDialog();
//return false;
});
}
$.jgrid.viewModal("#"+IDs.themodal,{gbox:"#gbox_"+gID,jqm:true, overlay: 10, modal:false});
};
grid.jqGrid({/*jqGrid options*/});
$("#delgridrow").click(function() {
rowId = grid.jqGrid('getGridParam', 'selrow');
if (rowId === null) {
$.jgrid.viewModal("#alertmod",{gbox:"#gbox_"+grid[0].p.id,jqm:true});
$("#jqg_alrt").focus();
} else {
createDeleteDialog();
}
return false;
});
Run Code Online (Sandbox Code Playgroud)