📄 grid.formedit.js
字号:
}
return false;
});
$("#eData", "#"+dtbl).click(function(e){
hideModal("#"+IDs.themodal);
return false;
});
if(onBeforeShow) { p.beforeShowForm($("#"+dtbl)); }
viewModal("#"+IDs.themodal,{modal:p.modal});
if(onAfterShow) { p.afterShowForm($("#"+dtbl)); }
}
});
},
navGrid : function (elem, o, pEdit,pAdd,pDel,pSearch) {
o = $.extend({
edit: true,
editicon: "row_edit.gif",
add: true,
addicon:"row_add.gif",
del: true,
delicon:"row_delete.gif",
search: true,
searchicon:"find.gif",
refresh: true,
refreshicon:"refresh.gif",
refreshstate: 'firstpage',
position : "left",
closeicon: "ico-close.gif"
}, $.jgrid.nav, o ||{});
return this.each(function() {
var alertIDs = {themodal:'alertmod',modalhead:'alerthd',modalcontent:'alertcnt'};
var $t = this;
if(!$t.grid) { return; }
if ($("#"+alertIDs.themodal).html() == null) {
var vwidth;
var vheight;
if (typeof window.innerWidth != 'undefined') {
vwidth = window.innerWidth,
vheight = window.innerHeight
} else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
vwidth = document.documentElement.clientWidth,
vheight = document.documentElement.clientHeight
} else {
vwidth=1024;
vheight=768;
}
createModal(alertIDs,"<div>"+o.alerttext+"</div>",{imgpath:$t.p.imgpath,closeicon:o.closeicon,caption:o.alertcap,top:vheight/2-25,left:vwidth/2-100,width:200,height:50},$t.grid.hDiv,$t.grid.hDiv,true);
DnRModal("#"+alertIDs.themodal,"#"+alertIDs.modalhead);
}
var navTbl = $("<table cellspacing='0' cellpadding='0' border='0' class='navtable'><tbody></tbody></table>").height(20);
var trd = document.createElement("tr");
$(trd).addClass("nav-row");
var imp = $t.p.imgpath;
var tbd;
if (o.add) {
tbd = document.createElement("td");
$(tbd).append(" ").css({border:"none",padding:"0px"});
trd.appendChild(tbd);
tbd = document.createElement("td");
tbd.title = o.addtitle || "";
$(tbd).append("<table cellspacing='0' cellpadding='0' border='0' class='tbutton'><tr><td><img src='"+imp+o.addicon+"'/></td><td>"+o.addtext+" </td></tr></table>")
.css("cursor","pointer")
.addClass("nav-button")
.click(function(){
if (typeof o.addfunc == 'function') {
o.addfunc();
} else {
$($t).editGridRow("new",pAdd || {});
}
return false;
})
.hover(
function () {
$(this).addClass("nav-hover");
},
function () {
$(this).removeClass("nav-hover");
}
);
trd.appendChild(tbd);
tbd = null;
}
if (o.edit) {
tbd = document.createElement("td");
$(tbd).append(" ").css({border:"none",padding:"0px"});
trd.appendChild(tbd);
tbd = document.createElement("td");
tbd.title = o.edittitle || "";
$(tbd).append("<table cellspacing='0' cellpadding='0' border='0' class='tbutton'><tr><td><img src='"+imp+o.editicon+"'/></td><td valign='center'>"+o.edittext+" </td></tr></table>")
.css("cursor","pointer")
.addClass("nav-button")
.click(function(){
var sr = $($t).getGridParam('selrow');
if (sr) {
if(typeof o.editfunc == 'function') {
o.editfunc(sr);
} else {
$($t).editGridRow(sr,pEdit || {});
}
} else {
viewModal("#"+alertIDs.themodal);
}
return false;
})
.hover( function () {
$(this).addClass("nav-hover");
},
function () {
$(this).removeClass("nav-hover");
}
);
trd.appendChild(tbd);
tbd = null;
}
if (o.del) {
tbd = document.createElement("td");
$(tbd).append(" ").css({border:"none",padding:"0px"});
trd.appendChild(tbd);
tbd = document.createElement("td");
tbd.title = o.deltitle || "";
$(tbd).append("<table cellspacing='0' cellpadding='0' border='0' class='tbutton'><tr><td><img src='"+imp+o.delicon+"'/></td><td>"+o.deltext+" </td></tr></table>")
.css("cursor","pointer")
.addClass("nav-button")
.click(function(){
var dr;
if($t.p.multiselect) {
dr = $($t).getGridParam('selarrrow');
if(dr.length==0) { dr = null; }
} else {
dr = $($t).getGridParam('selrow');
}
if (dr) { $($t).delGridRow(dr,pDel || {}); }
else { viewModal("#"+alertIDs.themodal); }
return false;
})
.hover(
function () {
$(this).addClass("nav-hover");
},
function () {
$(this).removeClass("nav-hover");
}
);
trd.appendChild(tbd);
tbd = null;
}
if (o.search) {
tbd = document.createElement("td");
$(tbd).append(" ").css({border:"none",padding:"0px"});
trd.appendChild(tbd);
tbd = document.createElement("td");
if( $(elem)[0] == $t.p.pager[0] ) { pSearch = $.extend(pSearch,{dirty:true}); }
tbd.title = o.searchtitle || "";
$(tbd).append("<table cellspacing='0' cellpadding='0' border='0' class='tbutton'><tr><td class='no-dirty-cell'><img src='"+imp+o.searchicon+"'/></td><td>"+o.searchtext+" </td></tr></table>")
.css({cursor:"pointer"})
.addClass("nav-button")
.click(function(){
$($t).searchGrid(pSearch || {});
return false;
})
.hover(
function () {
$(this).addClass("nav-hover");
},
function () {
$(this).removeClass("nav-hover");
}
);
trd.appendChild(tbd);
tbd = null;
}
if (o.refresh) {
tbd = document.createElement("td");
$(tbd).append(" ").css({border:"none",padding:"0px"});
trd.appendChild(tbd);
tbd = document.createElement("td");
tbd.title = o.refreshtitle || "";
var dirtycell = ($(elem)[0] == $t.p.pager[0] ) ? true : false;
$(tbd).append("<table cellspacing='0' cellpadding='0' border='0' class='tbutton'><tr><td><img src='"+imp+o.refreshicon+"'/></td><td>"+o.refreshtext+" </td></tr></table>")
.css("cursor","pointer")
.addClass("nav-button")
.click(function(){
$t.p.search = false;
switch (o.refreshstate) {
case 'firstpage':
$t.p.page=1;
$($t).trigger("reloadGrid");
break;
case 'current':
var sr = $t.p.multiselect===true ? selarrrow : $t.p.selrow;
$($t).setGridParam({gridComplete: function() {
if($t.p.multiselect===true) {
if(sr.length>0) {
for(var i=0;i<sr.length;i++){
$($t).setSelection(sr[i]);
}
}
} else {
if(sr) {
$($t).setSelection(sr);
}
}
}});
$($t).trigger("reloadGrid");
break;
}
if (dirtycell) { $(".no-dirty-cell",$t.p.pager).removeClass("dirty-cell"); }
if(o.search) {
var gID = $("table:first",$t.grid.bDiv).attr("id");
$("#sval",'#srchcnt'+gID).val("");
}
return false;
})
.hover(
function () {
$(this).addClass("nav-hover");
},
function () {
$(this).removeClass("nav-hover");
}
);
trd.appendChild(tbd);
tbd = null;
}
if(o.position=="left") {
$(navTbl).append(trd).addClass("nav-table-left");
} else {
$(navTbl).append(trd).addClass("nav-table-right");
}
$(elem).prepend(navTbl);
});
},
navButtonAdd : function (elem, p) {
p = $.extend({
caption : "newButton",
title: '',
buttonimg : '',
onClickButton: null,
position : "last"
}, p ||{});
return this.each(function() {
if( !this.grid) { return; }
if( elem.indexOf("#") != 0) { elem = "#"+elem; }
var findnav = $(".navtable",elem)[0];
if (findnav) {
var tdb, tbd1;
var tbd1 = document.createElement("td");
$(tbd1).append(" ").css({border:"none",padding:"0px"});
var trd = $("tr:eq(0)",findnav)[0];
if( p.position !='first' ) {
trd.appendChild(tbd1);
}
tbd = document.createElement("td");
tbd.title = p.title;
var im = (p.buttonimg) ? "<img src='"+p.buttonimg+"'/>" : " ";
$(tbd).append("<table cellspacing='0' cellpadding='0' border='0' class='tbutton'><tr><td>"+im+"</td><td>"+p.caption+" </td></tr></table>")
.css("cursor","pointer")
.addClass("nav-button")
.click(function(e){
if (typeof p.onClickButton == 'function') { p.onClickButton(); }
e.stopPropagation();
return false;
})
.hover(
function () {
$(this).addClass("nav-hover");
},
function () {
$(this).removeClass("nav-hover");
}
);
if(p.position != 'first') {
trd.appendChild(tbd);
} else {
$(trd).prepend(tbd);
$(trd).prepend(tbd1);
}
tbd=null;tbd1=null;
}
});
},
GridToForm : function( rowid, formid ) {
return this.each(function(){
var $t = this;
if (!$t.grid) { return; }
var rowdata = $($t).getRowData(rowid);
if (rowdata) {
for(var i in rowdata) {
if ( $("[name="+i+"]",formid).is("input:radio") ) {
$("[name="+i+"]",formid).each( function() {
if( $(this).val() == rowdata[i] ) {
$(this).attr("checked","checked");
} else {
$(this).attr("checked","");
}
});
} else {
// this is very slow on big table and form.
$("[name="+i+"]",formid).val(rowdata[i]);
}
}
}
});
},
FormToGrid : function(rowid, formid){
return this.each(function() {
var $t = this;
if(!$t.grid) { return; }
var fields = $(formid).serializeArray();
var griddata = {};
$.each(fields, function(i, field){
griddata[field.name] = field.value;
});
$($t).setRowData(rowid,griddata);
});
}
});
})(jQuery);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -