?? grid.base.js
字號:
if( t.p.altRows === true ) {
if (pos == "last") {
if (t.rows.length % 2 == 1) {$(row).addClass('alt');}
} else {
$(t.rows).slice(1).each(function(i){
if(i % 2 ==1) {$(this).addClass('alt');}
else {$(this).removeClass('alt');}
});
}
}
try {t.p.afterInsertRow(row.id,data); } catch(e){}
t.updatepager();
success = true;
});
}
return success;
};
$.fn.hideCol = function(colname) {
return this.each(function() {
var $t = this,w=0, fndh=false, gtw;
if (!$t.grid ) {return;}
if( typeof colname == 'string') {colname=[colname];}
$(this.p.colModel).each(function(i) {
if ($.inArray(this.name,colname) != -1 && !this.hidden) {
w = parseInt($("tr th:eq("+i+")",$t.grid.hDiv).css("width"),10);
$("tr th:eq("+i+")",$t.grid.hDiv).css({display:"none"});
$($t.rows).each(function(j){
$("td:eq("+i+")",$t.rows[j]).css({display:"none"});
});
$t.grid.cols[i].style.width = 0;
$t.grid.headers[i].width = 0;
$t.grid.width -= w;
this.hidden=true;
fndh=true;
}
});
if(fndh===true) {
gtw = Math.min($t.p._width,$t.grid.width);
$("table:first",$t.grid.hDiv).width(gtw);
$("table:first",$t.grid.bDiv).width(gtw);
$($t.grid.hDiv).width(gtw);
$($t.grid.bDiv).width(gtw);
if($t.p.pager && $($t.p.pager).hasClass("scroll") ) {
$($t.p.pager).width(gtw);
}
if($t.p.caption) {$($t.grid.cDiv).width(gtw);}
if($t.p.toolbar[0]) {$($t.grid.uDiv).width(gtw);}
$t.grid.hDiv.scrollLeft = $t.grid.bDiv.scrollLeft;
}
});
};
$.fn.showCol = function(colname) {
return this.each(function() {
var $t = this, w = 0, fdns=false, gtw, ofl;
if (!$t.grid ) {return;}
if( typeof colname == 'string') {colname=[colname];}
$($t.p.colModel).each(function(i) {
if ($.inArray(this.name,colname) != -1 && this.hidden) {
w = parseInt($("tr th:eq("+i+")",$t.grid.hDiv).css("width"),10);
$("tr th:eq("+i+")",$t.grid.hDiv).css("display","");
$($t.rows).each(function(j){
$("td:eq("+i+")",$t.rows[j]).css("display","").width(w);
});
this.hidden=false;
$t.grid.cols[i].style.width = w;
$t.grid.headers[i].width = w;
$t.grid.width += w;
fdns=true;
}
});
if(fdns===true) {
gtw = Math.min($t.p._width,$t.grid.width);
ofl = ($t.grid.width <= $t.p._width) ? "hidden" : "auto";
$("table:first",$t.grid.hDiv).width(gtw);
$("table:first",$t.grid.bDiv).width(gtw);
$($t.grid.hDiv).width(gtw);
$($t.grid.bDiv).width(gtw).css("overflow-x",ofl);
if($t.p.pager && $($t.p.pager).hasClass("scroll") ) {
$($t.p.pager).width(gtw);
}
if($t.p.caption) {$($t.grid.cDiv).width(gtw);}
if($t.p.toolbar[0]) {$($t.grid.uDiv).width(gtw);}
$t.grid.hDiv.scrollLeft = $t.grid.bDiv.scrollLeft;
}
});
};
$.fn.setGridWidth = function(nwidth, shrink) {
return this.each(function(){
var $t = this, chw=0,w,cw,ofl;
if (!$t.grid ) {return;}
if(typeof shrink != 'boolean') {shrink=true;}
var testdata = getScale();
if(shrink !== true) {testdata[0] = Math.min($t.p._width,$t.grid.width); testdata[2]=0;}
else {testdata[2]= testdata[1]}
$.each($t.p.colModel,function(i,v){
if(!this.hidden && this.name != 'cb' && this.name!='subgrid') {
cw = shrink !== true ? $("tr:first th:eq("+i+")",$t.grid.hDiv).css("width") : this.width;
w = Math.floor((IENum(nwidth)-IENum(testdata[2]))/IENum(testdata[0])*IENum(cw));
chw += w;
$("table thead tr:first th:eq("+i+")",$t.grid.hDiv).css("width",w+"px");
$("table:first tbody tr:first td:eq("+i+")",$t.grid.bDiv).css("width",w+"px");
$t.grid.cols[i].style.width = w;
$t.grid.headers[i].width = w;
}
if(this.name=='cb' || this.name == 'subgrid'){chw += IENum(this.width);}
});
if(chw + testdata[1] <= nwidth || $t.p.forceFit === true){ ofl = "hidden"; tw = nwidth;}
else { ofl= "auto"; tw = chw + testdata[1];}
$("table:first",$t.grid.hDiv).width(tw);
$("table:first",$t.grid.bDiv).width(tw);
$($t.grid.hDiv).width(nwidth);
$($t.grid.bDiv).width(nwidth).css("overflow-x",ofl);
if($t.p.pager && $($t.p.pager).hasClass("scroll") ) {
$($t.p.pager).width(nwidth);
}
if($t.p.caption) {$($t.grid.cDiv).width(nwidth);}
if($t.p.toolbar[0]) {$($t.grid.uDiv).width(nwidth);}
$t.p._width = nwidth; $t.grid.width = tw;
if($.browser.safari || $.browser.opera ) {
$("table tbody tr:eq(1) td",$t.grid.bDiv).each( function( k ) {
$(this).css("width",$t.grid.headers[k].width+"px");
$t.grid.cols[k] = this;
});
}
$t.grid.hDiv.scrollLeft = $t.grid.bDiv.scrollLeft;
function IENum(val) {
val = parseInt(val,10);
return isNaN(val) ? 0 : val;
}
function getScale(){
var testcell = $("table tr:first th:eq(1)", $t.grid.hDiv);
var addpix = IENum($(testcell).css("padding-left")) +
IENum($(testcell).css("padding-right"))+
IENum($(testcell).css("border-left-width"))+
IENum($(testcell).css("border-right-width"));
var w =0,ap=0;
$.each($t.p.colModel,function(i,v){
if(!this.hidden) {
w += parseInt(this.width);
ap += addpix;
}
});
return [w,ap,0];
}
});
};
$.fn.setGridHeight = function (nh) {
return this.each(function (){
var ovfl, ovfl2, $t = this;
if(!$t.grid) {return;}
if($t.p.forceFit === true) { ovfl2='hidden'; } else {ovfl2=$($t.grid.bDiv).css("overflow-x");}
ovfl = (isNaN(nh) && $.browser.mozilla && (nh.indexOf("%")!=-1 || nh=="auto")) ? "hidden" : "auto";
$($t.grid.bDiv).css({height: nh+(isNaN(nh)?"":"px"),"overflow-y":ovfl,"overflow-x": ovfl2});
$t.p.height = nh;
});
};
$.fn.setCaption = function (newcap){
return this.each(function(){
this.p.caption=newcap;
$("table:first th",this.grid.cDiv).html(newcap);
$(this.grid.cDiv).show();
});
};
$.fn.setLabel = function(colname, nData, prop, attrp ){
return this.each(function(){
var $t = this, pos=-1;
if(!$t.grid) {return;}
if(isNaN(colname)) {
$($t.p.colModel).each(function(i){
if (this.name == colname) {
pos = i;return false;
}
});
} else {pos = parseInt(colname,10);}
if(pos>=0) {
var thecol = $("table:first th:eq("+pos+")",$t.grid.hDiv);
if (nData){
$("div",thecol).html(nData);
}
if (prop) {
if(typeof prop == 'string') {$(thecol).addClass(prop);} else {$(thecol).css(prop);}
}
if(typeof attrp == 'object') {$(thecol).attr(attrp);}
}
});
};
$.fn.setCell = function(rowid,colname,nData,cssp,attrp) {
return this.each(function(){
var $t = this, pos =-1;
if(!$t.grid) {return;}
if(isNaN(colname)) {
$($t.p.colModel).each(function(i){
if (this.name == colname) {
pos = i;return false;
}
});
} else {pos = parseInt(colname,10);}
if(pos>=0) {
var ind = $($t).getInd($t.rows,rowid);
if (ind>=0){
var tcell = $("td:eq("+pos+")",$t.rows[ind]);
if(nData != "") {
$t.formatter(tcell, $t.rows[ind], nData, pos,'edit');
}
if (cssp){
if(typeof cssp == 'string') {$(tcell).addClass(cssp);} else {$(tcell).css(cssp);}
}
if(typeof attrp == 'object') {$(tcell).attr(attrp);}
}
}
});
};
$.fn.getCell = function(rowid,col) {
var ret = false;
this.each(function(){
var $t=this, pos=-1;
if(!$t.grid) {return;}
if(isNaN(col)) {
$($t.p.colModel).each(function(i){
if (this.name == col) {
pos = i;return false;
}
});
} else {pos = parseInt(col,10);}
if(pos>=0) {
var ind = $($t).getInd($t.rows,rowid);
if(ind>=0) {
ret = $.htmlDecode($("td:eq("+pos+")",$t.rows[ind]).html());
}
}
});
return ret;
};
$.fn.clearGridData = function() {
return this.each(function(){
var $t = this;
if(!$t.grid) {return;}
$("tbody tr:gt(0)", $t.grid.bDiv).remove();
$t.p.selrow = null; $t.p.selarrrow= []; $t.p.savedRow = [];
$t.p.records = '0';$t.p.page='0';$t.p.lastpage='0';
$t.updatepager();
});
};
$.fn.getInd = function(obj,rowid,rc){
var ret =false;
$(obj).each(function(i){
if(this.id==rowid) {
ret = rc===true ? this : i;
return false;
}
});
return ret;
};
$.htmlDecode = function(value){
if(value==' ' || value==' ') {value = "";}
return !value ? value : String(value).replace(/&/g, "&").replace(/>/g, ">").replace(/</g, "<").replace(/"/g, '"');
};
return this.each( function() {
if(this.grid) {return;}
this.p = p ;
if(this.p.colNames.length === 0) {
for (var i=0;i<this.p.colModel.length;i++){
this.p.colNames[i] = this.p.colModel[i].label || this.p.colModel[i].name;
}
}
if( this.p.colNames.length !== this.p.colModel.length ) {
alert($.jgrid.errors.model);
return;
}
if(this.p.imgpath !== "" ) {this.p.imgpath += "/";}
$("<div class='loadingui' id=lui_"+this.id+"><div class='msgbox'>"+this.p.loadtext+"</div></div>").insertBefore(this);
$(this).attr({cellSpacing:"0",cellPadding:"0",border:"0"});
var ts = this,
bSR = $.isFunction(this.p.beforeSelectRow) ? this.p.beforeSelectRow :false,
onSelectRow = $.isFunction(this.p.onSelectRow) ? this.p.onSelectRow :false,
ondblClickRow = $.isFunction(this.p.ondblClickRow) ? this.p.ondblClickRow :false,
onSortCol = $.isFunction(this.p.onSortCol) ? this.p.onSortCol : false,
loadComplete = $.isFunction(this.p.loadComplete) ? this.p.loadComplete : false,
loadError = $.isFunction(this.p.loadError) ? this.p.loadError : false,
loadBeforeSend = $.isFunction(this.p.loadBeforeSend) ? this.p.loadBeforeSend : false,
onRightClickRow = $.isFunction(this.p.onRightClickRow) ? this.p.onRightClickRow : false,
afterInsRow = $.isFunction(this.p.afterInsertRow) ? this.p.afterInsertRow : false,
onHdCl = $.isFunction(this.p.onHeaderClick) ? this.p.onHeaderClick : false,
beReq = $.isFunction(this.p.beforeRequest) ? this.p.beforeRequest : false,
onSC = $.isFunction(this.p.onCellSelect) ? this.p.onCellSelect : false,
sortkeys = ["shiftKey","altKey","ctrlKey"];
if ($.inArray(ts.p.multikey,sortkeys) == -1 ) {ts.p.multikey = false;}
var IntNum = function(val,defval) {
val = parseInt(val,10);
if (isNaN(val)) { return (defval) ? defval : 0;}
else {return val;}
};
var formatCol = function (elem, pos){
var ral = ts.p.colModel[pos].align;
if(ral) { $(elem).css("text-align",ral);}
if(ts.p.colModel[pos].hidden) {$(elem).css("display","none");}
};
var resizeFirstRow = function (t,er){
$("tbody tr:eq("+er+") td",t).each( function( k ) {
$(this).css("width",grid.headers[k].width+"px");
grid.cols[k] = this;
});
};
var addCell = function(t,row,cell,pos) {
var td;
td = document.createElement("td");
formatter($(td,t),row,cell,pos,'add');
row.appendChild(td);
formatCol($(td,t), pos);
};
var formatter = function (elem, row, cellval , colpos, act){
var cm = ts.p.colModel[colpos];
if(cm.formatter) {
var opts= {rowId: row.id, colModel:cm,rowData:row};
if($.isFunction( cm.formatter ) ) {
cm.formatter(elem,cellval,opts,act);
} else if($.fmatter){
$(elem).fmatter(cm.formatter, cellval,opts, act);
} else {
$(elem).html(cellval || ' ');
}
}else {
$(elem).html(cellval || ' ');
}
elem[0].title = elem[0].textContent || elem[0].innerText;
};
var addMulti = function(t,row){
var cbid,td;
td = document.createElement("td");
cbid = "jqg_"+row.id;
$(td,t).html("<input type='checkbox'"+" id='"+cbid+"' class='cbox'/>");
formatCol($(td,t), 0);
row.appendChild(td);
};
var reader = function (datatype) {
var field, f=[], j=0, i;
for(i =0; i<ts.p.colModel.length; i++){
field = ts.p.colModel[i];
if (field.name !== 'cb' && field.name !=='subgrid') {
f[j] = (datatype=="xml") ? field.xmlmap || field.name : field.jsonmap || field.name;
j++;
}
}
return f;
};
var addXmlData = function addXmlData (xml,t, rcnt) {
if(xml) { var fpos = ts.p.treeANode || 0; rcnt=rcnt ||0; if(fpos===0 && rcnt===0) {$("tbody tr:gt(0)", t).remove();} } else { return; }
var v,row,gi=0,si=0,cbid,idn, getId,f=[],rd =[],cn=(ts.p.altRows === true) ? 'alt':'';
if(!ts.p.xmlReader.repeatitems) {f = reader("xml");}
if( ts.p.keyIndex===false) {
idn = ts.p.xmlReader.id;
if( idn.indexOf("[") === -1 ) {
getId = function( trow, k) {return $(idn,trow).text() || k;};
}
else {
getId = function( trow, k) {return trow.getAttribute(idn.replace(/[\[\]]/g,"")) || k;};
}
} else {
getId = function(trow) { return (f.length - 1 >= ts.p.keyIndex) ? $(f[ts.p.keyIndex],trow).text() : $(ts.p.xmlReader.cell+":eq("+ts.p.keyIndex+")",trow).text(); };
}
$(ts.p.xmlReader.page,xml).each(function() {ts.p.page = this.textContent || this.text ; });
$(ts.p.xmlReader.total,xml).each(function() {ts.p.lastpage = this.textContent || this.text ; } );
$(ts.p.xmlReader.records,xml).each(function() {ts.p.records = this.textContent || this.text ; } );
$(ts.p.xmlReader.userdata,xml).each(function() {ts.p.userData[this.getAttribute("name")]=this.textContent || this.text;});
$(ts.p.xmlReader.root+" "+ts.p.xmlReader.row,xml).each( function( j ) {
row = document.createElement("tr");
row.id = getId(this,j+1);
if(ts.p.multiselect) {
addMulti(t,row);
gi = 1;
}
if (ts.p.subGrid) {
try {$(ts).addSubGrid(t,row,gi,this);} catch (e){}
si= 1;
}
if(ts.p.xmlReader.repeatitems===true){
$(ts.p.xmlReader.cell,this).each( function (i) {
v = this.textContent || this.text;
addCell(t,row,v,i+gi+si);
rd[ts.p.colModel[i+gi+si].name] = v;
});
} else {
for(var i = 0; i < f.length;i++) {
v = $(f[i],this).text();
addCell(t, row, v , i+gi+si);
rd[ts.p.colModel[i+gi+si].name] = v;
}
}
if(j%2 == 1) {row.className = cn;} $(row).addClass("jqgrow");
if( ts.p.treeGrid === true) {
try {$(ts).setTreeNode(rd,row);} catch (e) {}
ts.p.treeANode = 0;
}
$(ts.rows[j+fpos+rcnt]).after(row);
if(afterInsRow) {ts.p.afterInsertRow(row.id,rd,this);}
rd=[];
});
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -