123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535 |
- /**
- * grid.
- * @param {Object} $
- * @memberOf {TypeName}
- * @return {TypeName}
- */
- (function($){
-
- $.addFlex = function(t,p)
- {
- if (t.grid) return false; //return if already exist
- // apply default properties
- p = $.extend({
- height: 300, //default height
- width: 'auto', //auto width
- striped: true, //apply odd even stripes
- novstripe: false,
- minwidth: 30, //min width of columns
- minheight: 80, //min height of columns
- resizable: false, //resizable table
- url: false, //ajax url
- method: 'POST', // data sending method
- dataType: 'json', // type of data loaded
- errormsg: 'Connection Error',
- usepager: false, //
- nowrap: true, //
- page: 1, //current page
- total: 1, //total rows
- useRp: true, //use the results per page select box
- rp: 15, // results per page
- rpOptions: [10,15,20,30,50,100],
- title: false,
- pagestat: '显示记录从 {from}—{to}, 总数 {total} 条',
- procmsg: '处理中, 请稍候 ...',
- query: '',
- qtype: '',
- nomsg: '没有符合条件的记录存在!',
- minColToggle: 1, //minimum allowed column to be hidden
- showToggleBtn: true, //show or hide column toggle popup
- hideOnSubmit: true,
- autoload: true,
- blockOpacity: 0.6,
- onToggleCol: false,
- onChangeSort: false,
- onSuccess: false,
- onSubmit: false, // using a custom populate function
- useAjax:true,
- pageName:'page',
- pageSizeName:'pageSize',
- realTime:false
- }, p);
-
- $(t)
- .show() //show if hidden
- .attr({cellPadding: 0, cellSpacing: 0, border: 0}) //remove padding and spacing
- .removeAttr('width') //remove width properties
- ;
-
- //create grid class
- var g = {
- hset : {},
- rePosDrag: function () {
- var cdleft = 0 - this.hDiv.scrollLeft;
- if (this.hDiv.scrollLeft>0) cdleft -= Math.floor(p.cgwidth/2);
- $(g.cDrag).css({top:g.hDiv.offsetTop+1});
- var cdpad = this.cdpad;
-
- $('div',g.cDrag).hide();
-
- $('thead tr:first th:visible',this.hDiv).each
- (
- function ()
- {
- var n = $('thead tr:first th:visible',g.hDiv).index(this);
-
- var cdpos = parseInt($('div',this).width());
- var ppos = cdpos;
- if (cdleft==0)
- cdleft -= Math.floor(p.cgwidth/2);
-
- cdpos = cdpos + cdleft + cdpad;
-
- $('div:eq('+n+')',g.cDrag).css({'left':cdpos+'px'}).show();
-
- cdleft = cdpos;
- }
- );
-
- },
- fixHeight: function (newH) {
- newH = false;
- if (!newH) newH = $(g.bDiv).height();
- var hdHeight = $(this.hDiv).height();
- $('div',this.cDrag).each(
- function ()
- {
- $(this).height(newH+hdHeight);
- }
- );
-
- var nd = parseInt($(g.nDiv).height());
-
- if (nd>newH)
- $(g.nDiv).height(newH).width(200);
- else
- $(g.nDiv).height('auto').width('auto');
-
- //$(g.block).css({height:newH,marginBottom:(newH * -1)});
-
- var hrH = g.bDiv.offsetTop + newH;
- if (p.height != 'auto' && p.resizable) hrH = g.vDiv.offsetTop;
- $(g.rDiv).css({height: hrH});
-
- },
- dragStart: function (dragtype,e,obj) { //default drag function start
-
- if (dragtype=='colresize') //column resize
- {
- $(g.nDiv).hide();$(g.nBtn).hide();
- var n = $('div',this.cDrag).index(obj);
- var ow = $('th:visible div:eq('+n+')',this.hDiv).width();
- $(obj).addClass('dragging').siblings().hide();
- $(obj).prev().addClass('dragging').show();
-
- this.colresize = {startX: e.pageX, ol: parseInt(obj.style.left), ow: ow, n : n };
- $('body').css('cursor','col-resize');
- }
- else if (dragtype=='vresize') //table resize
- {
- var hgo = false;
- $('body').css('cursor','row-resize');
- if (obj)
- {
- hgo = true;
- $('body').css('cursor','col-resize');
- }
- this.vresize = {h: p.height, sy: e.pageY, w: p.width, sx: e.pageX, hgo: hgo};
-
- }
- else if (dragtype=='colMove') //column header drag
- {
- $(g.nDiv).hide();$(g.nBtn).hide();
- this.hset = $(this.hDiv).offset();
- this.hset.right = this.hset.left + $('table',this.hDiv).width();
- this.hset.bottom = this.hset.top + $('table',this.hDiv).height();
- this.dcol = obj;
- this.dcoln = $('th',this.hDiv).index(obj);
-
- this.colCopy = document.createElement("div");
- this.colCopy.className = "colCopy";
- this.colCopy.innerHTML = obj.innerHTML;
- if ($.browser.msie)
- {
- this.colCopy.className = "colCopy ie";
- }
- $(this.colCopy).css({position:'absolute',styleFloat:'left',display:'none', textAlign: obj.align});
- $('body').append(this.colCopy);
- $(this.cDrag).hide();
- }
-
- $('body').noSelect();
-
- },
- dragMove: function (e) {
-
- if (this.colresize) //column resize
- {
- var n = this.colresize.n;
- var diff = e.pageX-this.colresize.startX;
- var nleft = this.colresize.ol + diff;
- var nw = this.colresize.ow + diff;
- if (nw > p.minwidth)
- {
- $('div:eq('+n+')',this.cDrag).css('left',nleft);
- this.colresize.nw = nw;
- }
- }
- else if (this.vresize) //table resize
- {
- var v = this.vresize;
- var y = e.pageY;
- var diff = y-v.sy;
-
- if (!p.defwidth) p.defwidth = p.width;
-
- if (p.width != 'auto' && !p.nohresize && v.hgo)
- {
- var x = e.pageX;
- var xdiff = x - v.sx;
- var newW = v.w + xdiff;
- if (newW > p.defwidth)
- {
- this.gDiv.style.width = newW + 'px';
- p.width = newW;
- }
- }
-
- var newH = v.h + diff;
- if ((newH > p.minheight || p.height < p.minheight) && !v.hgo)
- {
- this.bDiv.style.height = newH + 'px';
- p.height = newH;
- this.fixHeight(newH);
- }
- v = null;
- }
- else if (this.colCopy) {
- $(this.dcol).addClass('thMove').removeClass('thOver');
- if (e.pageX > this.hset.right || e.pageX < this.hset.left || e.pageY > this.hset.bottom || e.pageY < this.hset.top)
- {
- //this.dragEnd();
- $('body').css('cursor','move');
- }
- else
- $('body').css('cursor','pointer');
- $(this.colCopy).css({top:e.pageY + 10,left:e.pageX + 20, display: 'block'});
- }
-
- },
- dragEnd: function () {
- if (this.colresize)
- {
- var n = this.colresize.n;
- var nw = this.colresize.nw;
- $('th:visible div:eq('+n+')',this.hDiv).css('width',nw);
- $('tr',this.bDiv).each (
- function ()
- {
- $('td:visible div:eq('+n+')',this).css('width',nw);
- }
- );
- this.hDiv.scrollLeft = this.bDiv.scrollLeft;
- $('div:eq('+n+')',this.cDrag).siblings().show();
- $('.dragging',this.cDrag).removeClass('dragging');
- this.rePosDrag();
- this.fixHeight();
- this.colresize = false;
- }
- else if (this.vresize)
- {
- this.vresize = false;
- }
- else if (this.colCopy)
- {
- $(this.colCopy).remove();
- if (this.dcolt != null)
- {
- if (this.dcoln>this.dcolt)
- $('th:eq('+this.dcolt+')',this.hDiv).before(this.dcol);
- else
- $('th:eq('+this.dcolt+')',this.hDiv).after(this.dcol);
-
- this.switchCol(this.dcoln,this.dcolt);
- $(this.cdropleft).remove();
- $(this.cdropright).remove();
- this.rePosDrag();
- }
- this.dcol = null;
- this.hset = null;
- this.dcoln = null;
- this.dcolt = null;
- this.colCopy = null;
-
- $('.thMove',this.hDiv).removeClass('thMove');
- $(this.cDrag).show();
- }
- $('body').css('cursor','default');
- $('body').noSelect(false);
- },
- toggleCol: function(cid,visible) {
-
- var ncol = $("th[axis='col"+cid+"']",this.hDiv)[0];
- var n = $('thead th',g.hDiv).index(ncol);
- var cb = $('input[value='+cid+']',g.nDiv)[0];
- // alert(cb.checked);
-
- if (visible==null ) {
- visible = cb.checked;
- }
- if ($('input:checked',g.nDiv).length<p.minColToggle&&!visible) return false;
- // =======add by ls
- //var form = $(t).parents("form:first");
- // =======add by ls end
- if (visible)
- {
- ncol.hide = false;
- $(ncol).show();
- cb.checked = true;
- // =======add by ls
- //if (form && p.method.toLowerCase() == 'post') {
- //alert("可见");
- // $("#colHides"+parseInt(cid)).remove();
- //}
- // =======add by ls end
- }
- else {
- // =======add by ls
- //if (form && p.method.toLowerCase() == 'post') {
- // form.append($("<input type='hidden'>").attr({name:"colHides",value:cid,id:("colHides"+parseInt(cid))}));
- //alert("隐藏");
- //alert($("#colHides"+parseInt(cid)).attr("name"));
- //}
- // =======add by ls end
- ncol.hide = true;
- $(ncol).hide();
- cb.checked = false;
- }
-
- $('tbody tr',t).each(
- function ()
- {
- if (visible)
- $('td:eq('+n+')',this).show();
- else
- $('td:eq('+n+')',this).hide();
- }
- );
-
- this.rePosDrag();
-
- if (p.onToggleCol) p.onToggleCol(cid,visible);
- return visible;
- },
- switchCol: function(cdrag,cdrop) { //switch columns
-
- $('tbody tr',t).each
- (
- function ()
- {
- if (cdrag>cdrop)
- $('td:eq('+cdrop+')',this).before($('td:eq('+cdrag+')',this));
- else
- $('td:eq('+cdrop+')',this).after($('td:eq('+cdrag+')',this));
- }
- );
-
- //switch order in nDiv
- if (cdrag>cdrop)
- $('tr:eq('+cdrop+')',this.nDiv).before($('tr:eq('+cdrag+')',this.nDiv));
- else
- $('tr:eq('+cdrop+')',this.nDiv).after($('tr:eq('+cdrag+')',this.nDiv));
-
- if ($.browser.msie&&$.browser.version<7.0) $('tr:eq('+cdrop+') input',this.nDiv)[0].checked = true;
-
- this.hDiv.scrollLeft = this.bDiv.scrollLeft;
- },
- scroll: function() {
- this.hDiv.scrollLeft = this.bDiv.scrollLeft;
- this.rePosDrag();
- },
- addData: function (data) { //parse data
- if (p.preProcess)
- data = p.preProcess(data);
-
- if ($.isFunction(p.ajaxDataHandler)) {
- p.ajaxDataHandler.call(g, data, p);
- }
- $('.pReload',this.pDiv).removeClass('loading');
- this.loading = false;
-
- if (!data)
- {
- $('.pPageStat',this.pDiv).html(p.errormsg);
- return false;
- }
- if (p.dataType=='xml')
- p.total = +$('rows total',data).text();
- else
- p.total = data.total;
- if (p.total==0)
- {
- $('tr, a, td, div',t).unbind();
- $(t).empty();
- p.pages = 1;
- p.page = 1;
- this.buildpager();
- $('.pPageStat',this.pDiv).html(p.nomsg);
- return false;
- }
-
- p.pages = Math.ceil(p.total/p.rp);
-
- if (p.dataType=='xml')
- p.page = +$('rows page',data).text();
- else
- p.page = data.page;
-
- this.buildpager();
- //build new body
- var tbody = document.createElement('tbody');
-
- if (p.dataType=='json'){
- $.each(data.rows, function(i,row) {
- var tr = document.createElement('tr');
- if (i % 2 && p.striped) tr.className = 'erow';
- if (row.id) tr.id = 'row' + row.id;
- //add cell
- $('thead tr:first th',g.hDiv).each(function(i){
-
- var td = document.createElement('td');
- var field = $(this).attr('field');
-
- //add by ls
- var tdalign = this.getAttribute('tdalign');
- if (tdalign) td.align = tdalign;
- td.width = this.width;
- td.style.display = this.style.display;
- td.style.cssText = this.style.cssText;
-
- // var tempStyle = this.getAttribute('tempStyle');
- // if(tempStyle){
- // td.style.cssText += tempStyle;
- // }
- // td.align = this.align; //remove by ls
-
-
- if (typeof(field) != 'undefined') {
- var fieldData = row[field];
-
- if(String(fieldData) == 'true'){
- fieldData = '是';
- }else if(String(fieldData) == 'false'){
- fieldData = '否';
- }
-
- if (typeof(fieldData) != 'undefined') {
- td.innerHTML = fieldData == null ? "" : fieldData;
- } else {
- td.innerHTML = " ";
- }
- fieldData = null;
- }
- $(tr).append(td);
- td = null;
- });
- if ($('thead',this.gDiv).length<1){ //handle if grid has no headers
- for (var field in row) {
- var td = document.createElement('td');
- td.innerHTML = row[field];
- $(tr).append(td);
- td = null;
- }
- }
- $(tbody).append(tr);
- tr = null;
- });
-
- // $('thead tr:first th',g.hDiv).each(function(){
- // var thisDisplay = this.style.display;
- // this.setAttribute("tempStyle",this.style.cssText);
- // this.style.cssText = "";
- // this.style.display = thisDisplay;
- // });
-
-
- } else if (p.dataType=='xml') {
- i = 1;
- $("rows row",data).each
- (
-
- function ()
- {
-
- i++;
-
- var tr = document.createElement('tr');
- if (i % 2 && p.striped) tr.className = 'erow';
- var nid =$(this).attr('id');
- if (nid) tr.id = 'row' + nid;
-
- nid = null;
-
- var robj = this;
-
-
- $('thead tr:first th',g.hDiv).each
- (
- function ()
- {
-
- var td = document.createElement('td');
- var idx = $(this).attr('axis').substr(3);
- td.align = this.align;
- td.innerHTML = $("cell:eq("+ idx +")",robj).text();
- $(tr).append(td);
- td = null;
- }
- );
-
-
- if ($('thead',this.gDiv).length<1) //handle if grid has no headers
- {
- $('cell',this).each
- (
- function ()
- {
- var td = document.createElement('td');
- td.innerHTML = $(this).text();
- $(tr).append(td);
- td = null;
- }
- );
- }
-
- $(tbody).append(tr);
- tr = null;
- robj = null;
- }
- );
-
- } else if (p.dataType=='xhtml') {
- i = 1;
- $("table[id=" + t.id + "] tbody tr", data).each
- (
-
- function ()
- {
-
- i++;
-
- var tr = document.createElement('tr');
- if (i % 2 && p.striped) tr.className = 'erow';
- var nid =$(this).attr('id');
- if (nid) tr.id = 'row' + nid;
-
- nid = null;
-
- var robj = this;
-
-
- $('thead tr:first th',g.hDiv).each
- (
- function ()
- {
-
- var td = document.createElement('td');
- var idx = $(this).attr('axis').substr(3);
- td.align = this.align;
- td.innerHTML = $("td:eq("+ idx +")",robj).text();
- $(tr).append(td);
- td = null;
- }
- );
-
-
- if ($('thead',this.gDiv).length<1) //handle if grid has no headers
- {
- $('td',this).each
- (
- function ()
- {
- var td = document.createElement('td');
- td.innerHTML = $(this).text();
- $(tr).append(td);
- td = null;
- }
- );
- }
-
- $(tbody).append(tr);
- tr = null;
- robj = null;
- }
- );
- }
-
- $('tr',t).unbind();
- $(t).empty();
-
- $(t).append(tbody);
- this.addCellProp();
- this.addRowProp();
-
- //this.fixHeight($(this.bDiv).height());
-
- this.rePosDrag();
-
- tbody = null; data = null; i = null;
-
- if (p.onSuccess) p.onSuccess();
- if (p.hideOnSubmit) $(g.block).remove();//$(t).show();
-
- this.hDiv.scrollLeft = this.bDiv.scrollLeft;
- if ($.browser.opera) $(t).css('visibility','visible');
-
- if ($.isFunction(p.loadSuccessHandler)) {
- p.loadSuccessHandler.call(g,p);
- }
-
- },
- changeSort: function(th) { //change sortorder
-
- if (this.loading) return true;
-
- $(g.nDiv).hide();$(g.nBtn).hide();
-
- p.sortname= $(th).attr('abbr');
- if (p.sortname == $(th).attr('abbr'))
- {
- if (p.sortorder=='asc') p.sortorder = 'desc';
- else p.sortorder = 'asc';
- }
-
- $(th).addClass('sorted').siblings().removeClass('sorted');
- $('.sdesc',this.hDiv).removeClass('sdesc');
- $('.sasc',this.hDiv).removeClass('sasc');
- // alert(p.sortorder);
- // alert(p.sortname);
- $('div',th).addClass('s'+p.sortorder);
-
- if (p.onChangeSort)
- p.onChangeSort(p.sortname,p.sortorder);
- else
- this.populate();
-
- },
- buildpager: function(){ //rebuild pager based on new properties
-
- $('.pcontrol input',this.pDiv).val(p.page);
- $('.pcontrol span',this.pDiv).html(p.pages + " 页");
-
- var r1 = (p.page-1) * p.rp + 1;
- var r2 = r1 + p.rp - 1;
-
- if (p.total<r2) r2 = p.total;
-
- var stat = p.pagestat;
-
- stat = stat.replace(/{from}/,r1);
- stat = stat.replace(/{to}/,r2);
- stat = stat.replace(/{total}/,p.total);
-
- $('.pPageStat',this.pDiv).html(stat);
- },
- populate: function () { //get latest data
- if (this.loading) return true;
- if (p.onSubmit)
- {
- var gh = p.onSubmit();
- if (!gh) return false;
- }
-
- if (p.page>p.pages) p.page = p.pages;
- if (!p.newp) p.newp = p.page;
-
- //by ls
- if (!p.useAjax) {
- var form = $(t).parents("form:first");
- if (form && p.method.toLowerCase() == 'post') {
- form.append($("<input type='hidden'>").attr({name:"grid",value:$(t).attr("id")}));
- form.append($("<input type='hidden'>").attr({name:p.pageName,value:p.newp}));
- form.append($("<input type='hidden'>").attr({name:p.pageSizeName,value:p.rp}));
- // $(':hidden[name=' + p.pageName + ']', form).val(p.newp);
- // $(':hidden[name=' + p.pageSizeName + ']', form).val(p.rp);
-
- if (p.sortname){
- form.append($("<input type='hidden'>").attr({name:"sortname",value:p.sortname}));
- }
- if (p.sortorder){
- // =======add by ls
- if(p.sortorder == "asc"){
- $("#orderId").remove();
- p.sortorder == "desc";
- }else{
- $("#orderId").remove();
- p.sortorder == "asc";
- }
- // =======add by ls end
- form.append($("<input type='hidden'>").attr({name:"sortorder",value:p.sortorder}));
- }
-
- var gh = true;
- if (form.onsubmit) gh = form.onsubmit();
- if (gh) {
- if (p.url) $(form).attr("action", p.url);
- $(form).submit();
- }
- } else {
- var url = p.url ? p.url : window.location.href;
- var qsPos = url.indexOf("?");
- var qsParser;
- if (qsPos != -1) {
- qsParser = $.querystring(url.substr(qsPos + 1));
- url = url.substr(0, qsPos);
- } else {
- qsParser = $.querystring('');
- }
- qsParser.set('grid', $(t).attr("id")).set(p.pageName, p.newp)
- .set('pageSize', p.rp);
- if (p.sortname && p.sortname.length > 0)
- qsParser.set('sortname', p.sortname).set('sortorder', p.sortorder);
- if (p.qtype && p.qtype.length > 0 && p.query.length > 0)
- qsParser.set('filterValue', p.query).set('filterField', p.qtype);
- window.location.href = url + "?" + qsParser.toString();
- }
- return true;
- }
- if (!p.url) return false;
-
- this.loading = true;
-
-
- $('.pPageStat',this.pDiv).html(p.procmsg);
-
- $('.pReload',this.pDiv).addClass('loading');
-
- //block to prevent to operate the grid.
- var hDivOffset = $(g.hDiv).offset();
- $(g.block).css({
- top:hDivOffset.top,
- left:hDivOffset.left,
- height:$(g.hDiv).height() + $(g.bDiv).height(),
- width:$(g.hDiv).width()
- });
-
- if (p.hideOnSubmit && !p.realTime) $("body").append(g.block); //$(t).hide();
-
- if ($.browser.opera) $(t).css('visibility','hidden');
- //--------------
- //var param = {page:p.newp, rp: p.rp, sortname: p.sortname, sortorder: p.sortorder, query: p.query, qtype: p.qtype};
- var param = [
- { name : p.pageName, value : p.newp }
- ,{ name : p.pageSizeName, value : p.rp }
- ,{ name : 'sortname', value : p.sortname}
- ,{ name : 'sortorder', value : p.sortorder }
- ,{ name : 'filterValue', value : p.query}
- ,{ name : 'filterField', value : p.qtype}
- ];
- //alert(p.query);
- //alert(p.qtype);
- if (p.params)
- {
- for (var pi = 0; pi < p.params.length; pi++) param[param.length] = p.params[pi];
- }
-
-
- $.ajax({
- type: p.method,
- url: p.url,
- data: param,
- timeout : 20000,
- cache : false,
- dataType: p.dataType == 'xhtml' ? 'xml' : p.dataType,
- success: function(data){
- /**
- * 获取数据成功后的操作
- * 1.设置加载状态为:false,
- * 2.向grid中加入数据
- * 3.关掉grid遮罩
- */
- g.addData(data);
- if (p.hideOnSubmit) {
- if(g.loading == true){
- g.loading = false;
- //setTimeout(function(){$(g.block).remove();},1000);
- $(g.block).remove();
- }
- }
-
- // g.addData(data);
- // if (p.hideOnSubmit) {
- // $(g.block).remove();
- // }
- },
- error: function(req, status, e) {
- try {
- if (p.onError)
- p.onError(data);
- else
- alert('获取列表数据失败!\n' + req.status + ":" + req.statusText);
- } catch (e) {}
- if (p.hideOnSubmit) $(g.block).remove();
- }
- });
- },
- doSearch: function () {
- p.query = $('input[name=filterValue]',g.sDiv).val();
- p.qtype = $('select[name=filterField]',g.sDiv).val();
- p.newp = 1;
- this.populate();
- },
- changePage: function (ctype){ //change page
-
- if (this.loading) return true;
- switch(ctype)
- {
- case 'first': p.newp = 1; break;
- case 'prev': if (p.page>1) p.newp = parseInt(p.page) - 1; break;
- case 'next': if (p.page<p.pages) p.newp = parseInt(p.page) + 1; break;
- case 'last': p.newp = p.pages; break;
- case 'input':
- var nv = parseInt($('.pcontrol input',this.pDiv).val());
- if (isNaN(nv)) nv = 1;
- if (nv<1) nv = 1;
- else if (nv > p.pages) nv = p.pages;
- $('.pcontrol input',this.pDiv).val(nv);
- p.newp =nv;
- break;
- }
- if (typeof(p.newp) != 'number' || p.newp==p.page) return false;
-
- if (p.onChangePage)
- p.onChangePage(p.newp);
- else
- this.populate();
-
- },
- addCellProp: function ()
- {
-
- $('tbody tr td',g.bDiv).each
- (
- function ()
- {
- var tdDiv = document.createElement('div');
- var n = $('td',$(this).parent()).index(this);
- var pth = $('th:eq('+n+')',g.hDiv).get(0);
-
- if (pth!=null)
- {
- if (p.sortname==$(pth).attr('abbr')&&p.sortname)
- {
- this.className = 'sorted';
- }
- $(tdDiv).css({
- textAlign:this.getAttribute("align") ? this.align : pth.align,
- width: this.width.length > 0 ? this.width : $('div:first',pth)[0].style.width
- });
- if (pth.hide) $(this).css('display','none');
-
- if (p.nowrap==false || pth.noWrap == false) $(tdDiv).css('white-space','normal');
- } else {
- $(tdDiv).css({
- textAlign : this.getAttribute("align"),
- width : this.width + "px"
- });
- if (this.noWrap == false) $(tdDiv).css('white-space','normal');
- }
- if (this.innerHTML=='') this.innerHTML = ' ';
-
- //tdDiv.value = this.innerHTML; //store preprocess value
- //tdDiv.innerHTML = this.innerHTML;
-
- $(tdDiv).append($(this).contents());
-
- var prnt = $(this).parent()[0];
- var pid = false;
- if (prnt.id) pid = prnt.id.substr(3);
-
- if (pth!=null)
- {
- if (pth.process) pth.process(tdDiv,pid);
- }
-
- $(this).empty().append(tdDiv).removeAttr('width'); //wrap content
- //add editable event here 'dblclick'
- }
- );
-
- },
- getCellDim: function (obj) // get cell prop for editable event
- {
- var ht = parseInt($(obj).height());
- var pht = parseInt($(obj).parent().height());
- var wt = parseInt(obj.style.width);
- var pwt = parseInt($(obj).parent().width());
- var top = obj.offsetParent.offsetTop;
- var left = obj.offsetParent.offsetLeft;
- var pdl = parseInt($(obj).css('paddingLeft'));
- var pdt = parseInt($(obj).css('paddingTop'));
- return {ht:ht,wt:wt,top:top,left:left,pdl:pdl, pdt:pdt, pht:pht, pwt: pwt};
- },
- addRowProp: function()
- {
- $('tbody tr',g.bDiv).each
- (
- function ()
- {
- $(this)
- .click(
- function (e)
- {
- var obj = (e.target || e.srcElement); if (obj.href || obj.type) return true;
- $(this).toggleClass('trSelected');
- if (p.singleSelect) $(this).siblings().removeClass('trSelected');
- }
- )
- .mousedown(
- function (e)
- {
- if (e.shiftKey)
- {
- $(this).toggleClass('trSelected');
- g.multisel = true;
- this.focus();
- $(g.gDiv).noSelect();
- }
- }
- )
- .mouseup(
- function ()
- {
- if (g.multisel)
- {
- g.multisel = false;
- $(g.gDiv).noSelect(false);
- }
- }
- )
- .hover(
- function (e)
- {
- if (g.multisel)
- {
- $(this).toggleClass('trSelected');
- }
- },
- function () {}
- )
- ;
-
- if ($.browser.msie&&$.browser.version<7.0)
- {
- $(this)
- .hover(
- function () { $(this).addClass('trOver'); },
- function () { $(this).removeClass('trOver'); }
- )
- ;
- }
- }
- );
-
-
- },
- pager: 0
- };
-
- //create model if any
- if (p.colModel)
- {
- thead = document.createElement('thead');
- tr = document.createElement('tr');
-
- for (i=0;i<p.colModel.length;i++)
- {
- var cm = p.colModel[i];
- var th = document.createElement('th');
- th.innerHTML = cm.display;
-
- if (cm.name&&cm.sortable)
- $(th).attr('abbr',cm.name);
-
- //th.idx = i;
- $(th).attr('axis','col'+i);
-
- if (cm.align)
- th.align = cm.align;
-
- if (cm.width)
- $(th).attr('width',cm.width);
- if (cm.hide)
- {
- th.hide = true;
- }
-
- if (cm.process)
- {
- th.process = cm.process;
- }
- $(tr).append(th);
- }
- $(thead).append(tr);
- $(t).prepend(thead);
- } // end if p.colmodel
- //init divs
- g.gDiv = document.createElement('div'); //create global container
- g.mDiv = document.createElement('div'); //create title container
- g.hDiv = document.createElement('div'); //create header container
- g.bDiv = document.createElement('div'); //create body container
- if (p.freezeColumn > 0) {
- g.fhDiv = document.createElement('div'); //create freeze header container
- g.fbDiv = document.createElement('div'); //create freeze body container
- }
- g.vDiv = document.createElement('div'); //create grip
- g.rDiv = document.createElement('div'); //create horizontal resizer
- g.cDrag = document.createElement('div'); //create column drag
- g.block = document.createElement('div'); //creat blocker
- g.nDiv = document.createElement('div'); //create column show/hide popup
- g.nBtn = document.createElement('div'); //create column show/hide button
- g.iDiv = document.createElement('div'); //create editable layer
- g.tDiv = document.createElement('div'); //create toolbar
- g.sDiv = document.createElement('div');
-
- if (p.usepager) g.pDiv = document.createElement('div'); //create pager container
- g.hTable = document.createElement('table');
- //set gDiv
- g.gDiv.className = 'flexigrid';
- if (!isNaN(p.width)) g.gDiv.style.width = p.width + 'px';
- //add conditional classes
- if ($.browser.msie)
- $(g.gDiv).addClass('ie');
-
- if (p.novstripe)
- $(g.gDiv).addClass('novstripe');
- // added by ls at 2009-7-6 15:25
- if (!isNaN(p.restHeight)) {
- var bch = document.documentElement.clientHeight;
- bch -= p.restHeight;
- if (p.usepager)
- bch -= 30;
- if (p.resizable)
- bch -= 5;
- if (p.title)
- bch -= 30;
- p.height = bch - 20;
- }
-
- // end
- $(t).before(g.gDiv);
- $(g.gDiv)
- .append(t)
- ;
- //set toolbar
- if (p.buttons)
- {
- g.tDiv.className = 'tDiv';
- var tDiv2 = document.createElement('div');
- tDiv2.className = 'tDiv2';
-
- for (i=0;i<p.buttons.length;i++)
- {
- var btn = p.buttons[i];
- if (!btn.separator)
- {
- var btnDiv = document.createElement('div');
- btnDiv.className = 'fbutton';
- btnDiv.innerHTML = "<div><span>"+btn.name+"</span></div>";
- if (btn.bclass)
- $('span',btnDiv)
- .addClass(btn.bclass)
- .css({paddingLeft:20})
- ;
- btnDiv.onpress = btn.onpress;
- btnDiv.name = btn.name;
- if (btn.onpress)
- {
- $(btnDiv).click
- (
- function ()
- {
- this.onpress(this.name,g.gDiv);
- }
- );
- }
- $(tDiv2).append(btnDiv);
- if ($.browser.msie&&$.browser.version<7.0)
- {
- $(btnDiv).hover(function(){$(this).addClass('fbOver');},function(){$(this).removeClass('fbOver');});
- }
-
- } else {
- $(tDiv2).append("<div class='btnseparator'></div>");
- }
- }
- $(g.tDiv).append(tDiv2);
- $(g.tDiv).append("<div style='clear:both'></div>");
- $(g.gDiv).prepend(g.tDiv);
- }
-
- //set hDiv
- g.hDiv.className = 'hDiv';
- $(t).before(g.hDiv);
- //set hTable
-
- g.hTable.cellPadding = 0;
- g.hTable.cellSpacing = 0;
- $(g.hDiv).append('<div class="hDivBox"></div>');
- $('div',g.hDiv).append(g.hTable);
- var thead = $("thead:first",t).get(0);
- if (thead) $(g.hTable).append(thead);
- thead = null;
-
- if (!p.colmodel) var ci = 0;
- //setup thead
- $('thead tr:first th',g.hDiv).each(function (){
- var thdiv = document.createElement('div');
-
- if ($(this).attr('abbr')) {
- $(this).click( function(e){
- if (!$(this).hasClass('thOver')) return false;
- var obj = (e.target || e.srcElement);
- if (obj.href || obj.type) return true;
- g.changeSort(this);
- });
-
- if ($(this).attr('abbr')==p.sortname){
- this.className = 'sorted';
- thdiv.className = 's'+p.sortorder;
- }
- }
- if (this.style.display) $(this).hide();
-
- if (!p.colmodel){
- $(this).attr('axis','col' + ci++);
- }
-
-
- $(thdiv).css({textAlign:this.align, width: this.width + 'px'});
- thdiv.innerHTML = this.innerHTML;
-
- $(this).empty().append(thdiv).removeAttr('width')
- .mousedown(function (e)
- {
- //by ls
- if ($(this).attr("movable")) g.dragStart('colMove',e,this);
- })
- .hover(
- function(){
-
- if (!g.colresize&&!$(this).hasClass('thMove')&&!g.colCopy && $(this).attr("movable") != undefined) {
- $(this).addClass('thOver');
- }
-
- if ($(this).attr('abbr')!=p.sortname&&!g.colCopy&&!g.colresize&&$(this).attr('abbr')) $('div',this).addClass('s'+p.sortorder);
- else if ($(this).attr('abbr')==p.sortname&&!g.colCopy&&!g.colresize&&$(this).attr('abbr'))
- {
- var no = '';
- if (p.sortorder=='asc') no = 'desc';
- else no = 'asc';
- $('div',this).removeClass('s'+p.sortorder).addClass('s'+no);
- }
-
- if (g.colCopy)
- {
- var n = $('th',g.hDiv).index(this);
-
- if (n==g.dcoln) return false;
-
-
-
- if (n<g.dcoln) $(this).append(g.cdropleft);
- else $(this).append(g.cdropright);
-
- g.dcolt = n;
-
- } else if (!g.colresize) {
-
- var nv = $('th:visible',g.hDiv).index(this);
- var onl = parseInt($('div:eq('+nv+')',g.cDrag).css('left'));
- var nw = parseInt($(g.nBtn).width()) + parseInt($(g.nBtn).css('borderLeftWidth'));
- nl = onl - (isNaN(nw) ? 0 : nw) + Math.floor(p.cgwidth/2);
-
- $(g.nDiv).hide();$(g.nBtn).hide();
- if (p.showToggleBtn && this.getAttribute("togglable") != "false") $(g.nBtn).css({'left':nl,top:g.hDiv.offsetTop}).show();
-
- var ndw = parseInt($(g.nDiv).width());
-
- $(g.nDiv).css({top:g.bDiv.offsetTop});
-
- if ((nl+ndw)>$(g.gDiv).width()) {
- $(g.nDiv).css('left',onl-ndw+1);
- } else {
- $(g.nDiv).css('left',nl);
- }
-
- if ($(this).hasClass('sorted'))
- $(g.nBtn).addClass('srtd');
- else
- $(g.nBtn).removeClass('srtd');
-
- }
-
- },
- function(){
- $(this).removeClass('thOver');
- if ($(this).attr('abbr')!=p.sortname) $('div',this).removeClass('s'+p.sortorder);
- else if ($(this).attr('abbr')==p.sortname)
- {
- var no = '';
- if (p.sortorder=='asc') no = 'desc';
- else no = 'asc';
-
- $('div',this).addClass('s'+p.sortorder).removeClass('s'+no);
- }
- if (g.colCopy)
- {
- $(g.cdropleft).remove();
- $(g.cdropright).remove();
- g.dcolt = null;
- }
- })
- ; //wrap content
- }
- );
-
- //set bDiv
- g.bDiv.className = 'bDiv';
- $(t).before(g.bDiv);
- //替换下面注释
- if ($.browser.msie){
- if(p.height=='auto'){
- $(g.bDiv).css({ height:'auto'}).scroll(function(e) {
- g.scroll()
- }).append(t);
- }else{
- if(p.height<0){
-
- }else{
- g.bDiv.style.height = p.height+"px";
-
- $(g.bDiv).scroll(function(e) {
- g.scroll()
- }).append(t);
- }
- }
- }else{
- $(g.bDiv).css({ height: (p.height=='auto') ? 'auto' : p.height+"px"}).scroll(
- function (e) {
- g.scroll()
- }) .append(t);
- }
-
- if (p.height == 'auto')
- {
- $('table',g.bDiv).addClass('autoht');
- g.bDiv.style.overflowY = 'hidden';
- }
-
- // $(g.bDiv).css({ height: (p.height=='auto') ? 'auto' : p.height+"px"}) .scroll(function (e) {g.scroll()}).append(t) ;
- //
- // if (p.height == 'auto')
- // {
- // $('table',g.bDiv).addClass('autoht');
- // g.bDiv.style.overflowY = 'hidden';
- // }
- //add td properties
- g.addCellProp();
-
- //add row properties
- g.addRowProp();
-
-
- //set cDrag
-
- var cdcol = $('thead tr:first th:first',g.hDiv).get(0);
-
- if (cdcol != null)
- {
- g.cDrag.className = 'cDrag';
- g.cdpad = 0;
-
- g.cdpad += (isNaN(parseInt($('div',cdcol).css('borderLeftWidth'))) ? 0 : parseInt($('div',cdcol).css('borderLeftWidth')));
- g.cdpad += (isNaN(parseInt($('div',cdcol).css('borderRightWidth'))) ? 0 : parseInt($('div',cdcol).css('borderRightWidth')));
- g.cdpad += (isNaN(parseInt($('div',cdcol).css('paddingLeft'))) ? 0 : parseInt($('div',cdcol).css('paddingLeft')));
- g.cdpad += (isNaN(parseInt($('div',cdcol).css('paddingRight'))) ? 0 : parseInt($('div',cdcol).css('paddingRight')));
- g.cdpad += (isNaN(parseInt($(cdcol).css('borderLeftWidth'))) ? 0 : parseInt($(cdcol).css('borderLeftWidth')));
- g.cdpad += (isNaN(parseInt($(cdcol).css('borderRightWidth'))) ? 0 : parseInt($(cdcol).css('borderRightWidth')));
- g.cdpad += (isNaN(parseInt($(cdcol).css('paddingLeft'))) ? 0 : parseInt($(cdcol).css('paddingLeft')));
- g.cdpad += (isNaN(parseInt($(cdcol).css('paddingRight'))) ? 0 : parseInt($(cdcol).css('paddingRight')));
- $(g.bDiv).before(g.cDrag);
-
- var cdheight = $(g.bDiv).height();
- var hdheight = $(g.hDiv).height();
-
- $(g.cDrag).css({top: -hdheight + 'px'});
-
- $('thead tr:first th',g.hDiv).each
- (
- function ()
- {
- var cgDiv = document.createElement('div');
- $(g.cDrag).append(cgDiv);
- if (!p.cgwidth) p.cgwidth = $(cgDiv).width();
- $(cgDiv).css({height: cdheight + hdheight})
- .mousedown(function(e){g.dragStart('colresize',e,this);})
- ;
- if ($.browser.msie&&$.browser.version<7.0)
- {
- g.fixHeight($(g.gDiv).height());
- $(cgDiv).hover(
- function ()
- {
- g.fixHeight();
- $(this).addClass('dragging')
- },
- function () { if (!g.colresize) $(this).removeClass('dragging') }
- );
- }
- }
- );
-
- //g.rePosDrag();
-
- }
-
- //add strip
- if (p.striped)
- $('tbody tr:odd',g.bDiv).addClass('erow');
-
-
- if (p.resizable && p.height !='auto')
- {
- g.vDiv.className = 'vGrip';
- $(g.vDiv)
- .mousedown(function (e) { g.dragStart('vresize',e)})
- .html('<span></span>');
- $(g.bDiv).after(g.vDiv);
- }
-
- if (p.resizable && p.width !='auto' && !p.nohresize)
- {
- g.rDiv.className = 'hGrip';
- $(g.rDiv)
- .mousedown(function (e) {g.dragStart('vresize',e,true);})
- .html('<span></span>')
- .css('height',$(g.gDiv).height())
- ;
- if ($.browser.msie&&$.browser.version<7.0)
- {
- $(g.rDiv).hover(function(){$(this).addClass('hgOver');},function(){$(this).removeClass('hgOver');});
- }
- $(g.gDiv).append(g.rDiv);
- }
-
- // add pager
- if (p.usepager)
- {
- g.pDiv.className = 'pDiv';
- g.pDiv.innerHTML = '<div class="pDiv2"></div><div class="pDiv3"></div>';
- $(g.bDiv).after(g.pDiv);
- g.gDiv.appendChild(g.pDiv);
-
-
- // $('.pDiv2', g.pDiv).html(html);
- // var html3 = '<div class="rightGroup"><span class="pPageStat"></span></div>';
- // $('.pDiv3', g.pDiv).html(html3);
-
- if (typeof(p.pages) == 'undefined') p.pages = p.rp == 0 ? 0 : Math.ceil(p.total/p.rp);
- // var html = ' <div class="pGroup"> <div class="pFirst pButton"><span></span></div><div class="pPrev pButton"><span></span></div> </div> <div class="btnseparator"></div> <div class="pGroup"><span class="pcontrol">页码 <input type="text" size="1" value="' + p.page + '" /> 共 <span>' + p.pages + ' 页 </span></span></div> <div class="btnseparator"></div> <div class="pGroup"> <div class="pNext pButton"><span></span></div><div class="pLast pButton"><span></span></div> </div> <div class="btnseparator"></div> <div class="pGroup"> <div class="pReload pButton"><span></span></div> </div> <div class="btnseparator"></div> <div class="pGroup"><span class="pPageStat"></span></div>';
- // $('div',g.pDiv).html(html);
-
- var html = ' <div class="pGroup"> <div class="pFirst pButton"><span></span></div><div class="pPrev pButton"><span></span></div> </div> <div class="btnseparator"></div> <div class="pGroup"><span class="pcontrol">页码 <input type="text" size="1" value="' + p.page + '" /> 共 <span>' + p.pages + ' 页 </span></span></div> <div class="btnseparator"></div> <div class="pGroup"> <div class="pNext pButton"><span></span></div><div class="pLast pButton"><span></span></div> </div> <div class="btnseparator"></div> <div class="pGroup"> <div class="pReload pButton"><span></span></div> </div> <div class="btnseparator"></div> ';
- $('.pDiv2', g.pDiv).html(html);
- var html3 = '<div class="rightGroup"><span class="pPageStat"></span></div>';
- $('.pDiv3', g.pDiv).html(html3);
-
- $('.pReload',g.pDiv).click(function(){g.populate()});
- $('.pFirst',g.pDiv).click(function(){g.changePage('first')});
- $('.pPrev',g.pDiv).click(function(){g.changePage('prev')});
- $('.pNext',g.pDiv).click(function(){g.changePage('next')});
- $('.pLast',g.pDiv).click(function(){g.changePage('last')});
- $('.pcontrol input',g.pDiv).keydown(function(e){if(e.keyCode==13) g.changePage('input')});
- if ($.browser.msie&&$.browser.version<7) $('.pButton',g.pDiv).hover(function(){$(this).addClass('pBtnOver');},function(){$(this).removeClass('pBtnOver');});
- g.buildpager();
-
- if (p.useRp)
- {
- var opt = "";
- for (var nx=0;nx<p.rpOptions.length;nx++)
- {
- if (p.rp == p.rpOptions[nx]) sel = 'selected="selected"'; else sel = '';
- opt += "<option value='" + p.rpOptions[nx] + "' " + sel + " >" + p.rpOptions[nx] + " </option>";
- };
- $('.pDiv2',g.pDiv).prepend("<div class='pGroup'><select name='rp'>"+opt+"</select></div> <div class='btnseparator'></div>");
- $('select',g.pDiv).change(
- function ()
- {
- if (p.onRpChange)
- p.onRpChange(+this.value);
- else
- {
- p.newp = 1;
- p.rp = +this.value;
- g.populate();
- }
- }
- );
- }
-
- //add search button
- if (p.searchitems && p.searchitems.length > 0)
- {
- $('.pDiv2',g.pDiv).prepend("<div class='pGroup'> <div class='pSearch pButton'><span></span></div> </div> <div class='btnseparator'></div>");
- $('.pSearch',g.pDiv).click(function(){
- $(g.sDiv).slideToggle('fast',function(){
- if($(this).is(':hidden')){
- g.bDiv.style.height = p.height + "px";
- }else{
- g.bDiv.style.height = p.height-35 + "px";
- }
- $('.sDiv:visible input:first',g.gDiv).trigger('focus');
- });
- });
- //add search box
- g.sDiv.className = 'sDiv';
-
- sitems = p.searchitems;
-
- var sopt = "";
- for (var s = 0; s < sitems.length; s++)
- {
- if (p.qtype=='' && sitems[s].isdefault==true)
- {
- p.qtype = sitems[s].name;
- sel = 'selected="selected"';
- } else sel = '';
- sopt += "<option value='" + sitems[s].name + "' " + sel + " >" + sitems[s].display + " </option>";
- }
-
- if (p.qtype=='') p.qtype = sitems[0].name;
-
- $(g.sDiv).append("<div class='sDiv2'>过滤条件 <select name='filterField'>"+sopt+"</select> <input type='text' size='30' name='filterValue' class='qsbox' /> <input type='button' value='确定' /> <input type='button' value='重置' /></div>");
- $('input[name=filterField],select[name=filterValue]',g.sDiv).keydown( function(e){
- alert("1");
- if(e.keyCode==13)
- g.doSearch()
- });
- $('input[value=重置]',g.sDiv).click(function(){
- // alert($('input[name=filterValue]',g.sDiv).val());
- $('input[name=filterValue]',g.sDiv).val('');
- p.query = '';
- g.doSearch();
- });
- $('input[value=确定]', g.sDiv).click(function(){g.doSearch()});
- $(g.bDiv).after(g.sDiv);
-
- }
-
- }
- $(g.pDiv,g.sDiv).append("<div style='clear:both'></div>");
-
-
-
- // add title
- if (p.title)
- {
- g.mDiv.className = 'mDiv';
- g.mDiv.innerHTML = '<div class="ftitle">'+p.title+'</div>';
- $(g.gDiv).prepend(g.mDiv);
- if (p.showTableToggleBtn)
- {
- $(g.mDiv).append('<div class="ptogtitle" title="Minimize/Maximize Table"><span></span></div>');
- $('div.ptogtitle',g.mDiv).click
- (
- function ()
- {
- $(g.gDiv).toggleClass('hideBody');
- $(this).toggleClass('vsble');
- }
- );
- }
- //g.rePosDrag();
- }
-
- //setup cdrops
- g.cdropleft = document.createElement('span');
- g.cdropleft.className = 'cdropleft';
- g.cdropright = document.createElement('span');
- g.cdropright.className = 'cdropright';
- //add block
- g.block.className = 'gBlock';
- // var loadingDiv = document.createElement('div');
- // loadingDiv.className = 'l-grid-loading';
- // $(g.block).append(loadingDiv);
- var gh = $(g.bDiv).height();
- var gtop = g.hDiv.offsetTop;
- // $(g.block).css(
- // {
- // background: 'blue',
- // position: 'absolute',
- // zIndex:100
- // });
- //$(g.block).fadeTo(0,p.blockOpacity);
-
- // add column control
- if ($('th',g.hDiv).length)
- {
-
- g.nDiv.className = 'nDiv';
- g.nDiv.innerHTML = "<table cellpadding='0' cellspacing='0'><tbody></tbody></table>";
- $(g.nDiv).css(
- {
- marginBottom: (gh * -1),
- display: 'none',
- top: gtop
- }
- ).noSelect()
- ;
-
- var cn = 0;
-
- $('th div',g.hDiv).each
- (
- function ()
- {
- //by ls
- if ($(this).parent("th").attr("togglable") != "false") {
- var kcol = $("th[axis='col" + cn + "']",g.hDiv)[0];
- var chk = 'checked="checked"';
- if (kcol.style.display=='none') chk = '';
- $('tbody',g.nDiv).append('<tr><td class="ndcol1"><input type="checkbox" '+ chk +' class="togCol" value="'+ cn +'" /></td><td class="ndcol2">'+this.innerHTML+'</td></tr>');
- }
- cn++;
- }
- );
-
-
-
- if ($.browser.msie&&$.browser.version<7.0)
- $('tr',g.nDiv).hover
- (
- function () {$(this).addClass('ndcolover');},
- function () {$(this).removeClass('ndcolover');}
- );
-
- $('td.ndcol2',g.nDiv).click ( function (){
- if ($('input:checked',g.nDiv).length<=p.minColToggle&&$(this).prev().find('input')[0].checked) return false;
- return g.toggleCol($(this).prev().find('input').val());
- }
-
-
- // function ()
- // {
- // if ($('input:checked',g.nDiv).length<=p.minColToggle&&$(this).prev().find('input')[0].checked) return false;
- // // =======add by ls
- // var visible;
- // var cid = $(this).prev().find('input').val();
- // if($("#colHides"+parseInt(cid)).length ==0){
- // visible = false;
- // }else{
- // visible = true;
- // }
- // //alert(visible);
- // // =======add by ls end
- // return g.toggleCol($(this).prev().find('input').val(),visible);//=======add by ls 加了个visible的参数
- // }
- );
-
-
-
- $('input.togCol',g.nDiv).click
- (
- function ()
- {
- if ($('input:checked',g.nDiv).length<p.minColToggle&&this.checked==false) return false;
- $(this).parent().next().trigger('click');
- //return false;
- }
- );
- $(g.gDiv).prepend(g.nDiv);
-
- $(g.nBtn).addClass('nBtn')
- .html('<div></div>')
- .attr('title','隐藏/显示 列')
- .click
- (
- function ()
- {
- $(g.nDiv).toggle(); return true;
- }
- );
-
- if (p.showToggleBtn) $(g.gDiv).prepend(g.nBtn);
-
- }
-
-
-
- // add date edit layer
- $(g.iDiv)
- .addClass('iDiv')
- .css({display:'none'})
- ;
- $(g.bDiv).append(g.iDiv);
-
- // add flexigrid events
- $(g.bDiv)
- .hover(function(){$(g.nDiv).hide();$(g.nBtn).hide();},function(){if (g.multisel) g.multisel = false;})
- ;
- $(g.gDiv)
- .hover(function(){},function(){$(g.nDiv).hide();$(g.nBtn).hide();})
- ;
-
- //add document events
- $(document)
- .mousemove(function(e){g.dragMove(e)})
- .mouseup(function(e){g.dragEnd()})
- .hover(function(){},function (){g.dragEnd()})
- ;
-
- //browser adjustments
- if ($.browser.msie&&$.browser.version<7.0)
- {
- $('.hDiv,.bDiv,.mDiv,.pDiv,.vGrip,.tDiv, .sDiv',g.gDiv)
- .css({width: '100%'});
- $(g.gDiv).addClass('ie6');
- if (p.width!='auto') $(g.gDiv).addClass('ie6fullwidthbug');
- }
-
- g.rePosDrag();
- g.fixHeight();
-
- //make grid functions accessible
- t.p = p;
- t.grid = g;
-
-
- // load data
- if (p.url&&p.autoload&&p.useAjax)
- {
- g.populate();
- }
- return t;
-
- };
-
-
-
-
- //by ls at 2009-7-12 12:00
- $.addPlainFlex = function(t,p)
- {
- if (t.grid) return false; //return if already exist
-
- // apply default properties
- p = $.extend({
- height: 400, //default height
- width: 'auto', //auto width
- striped: true, //apply odd even stripes
- novstripe: false,
- minwidth: 30, //min width of columns
- minheight: 80, //min height of columns
- resizable: false, //resizable table
- url: false, //ajax url
- method: 'POST', // data sending method
- dataType: 'json', // type of data loaded
- errormsg: 'Connection Error',
- usepager: false, //
- nowrap: true, //
- page: 1, //current page
- total: 1, //total rows
- useRp: true, //use the results per page select box
- rp: 15, // results per page
- rpOptions: [10,15,20,25,30,50,100],
- title: false,
- pagestat: '当前显示 {from}—{to}, 总计 {total}',
- procmsg: '处理中, 请稍候 ...',
- query: '',
- qtype: '',
- nomsg: '无记录显示',
- minColToggle: 1, //minimum allowed column to be hidden
- showToggleBtn: true, //show or hide column toggle popup
- hideOnSubmit: true,
- autoload: true,
- blockOpacity: 0.5,
- onToggleCol: false,
- onChangeSort: false,
- onSuccess: false,
- onSubmit: false, // using a custom populate function
- useAjax:false,
- pageName:'page',
- pageSizeName:'pageSize'
- }, p);
-
- var g = {
- buildpager: function(){ //rebuild pager based on new properties
-
- $('.pcontrol input', this.pDiv).val(p.page);
- $('.pcontrol span', this.pDiv).html(p.pages);
-
- var r1 = (p.page-1) * p.rp + 1;
- var r2 = r1 + p.rp - 1;
-
- if (p.total<r2) r2 = p.total;
-
- var stat = p.pagestat;
-
- stat = stat.replace(/{from}/,r1);
- stat = stat.replace(/{to}/,r2);
- stat = stat.replace(/{total}/,p.total);
-
- $('.pPageStat', this.pDiv).html(stat);
- },
- populate: function () { //get latest data
- if (this.loading) return true;
- if (p.onSubmit)
- {
- var gh = p.onSubmit();
- if (!gh) return false;
- }
-
- if (p.page>p.pages) p.page = p.pages;
- if (!p.newp) p.newp = p.page;
-
- //by ls
- if (!p.useAjax) {
- var form = $(t).parents("form:first");
- if (form && p.method.toLowerCase() == 'post') {
- form.append($("<input type='hidden'>").attr({name:"grid",value:$(t).attr("id")}));
- form.append($("<input type='hidden'>").attr({name:p.pageName,value:p.newp}));
- form.append($("<input type='hidden'>").attr({name:p.pageSizeName,value:p.rp}));
-
- // $(':hidden[name=' + p.pageName + ']', form).val(p.newp);
- // $(':hidden[name=' + p.pageSizeName + ']', form).val(p.rp);
-
- if (p.sortname)
- form.append($("<input type='hidden'>").attr({name:"sortname",value:p.sortname}));
- if (p.sortorder)
- form.append($("<input type='hidden'>").attr({name:"sortorder",value:p.sortorder}));
- var gh = true;
- if (form.onsubmit) gh = form.onsubmit();
- if (gh) {
- if (p.url) $(form).attr("action", p.url);
- $(form).submit();
- }
- } else {
- var url = p.url ? p.url : window.location.href;
- var qsPos = url.indexOf("?");
- var qsParser;
- if (qsPos != -1) {
- qsParser = $.querystring(url.substr(qsPos + 1));
- url = url.substr(0, qsPos);
- } else {
- qsParser = $.querystring('');
- }
- qsParser.set('grid', $(t).attr("id")).set(p.pageName, p.newp)
- .set(p.pageSizeName, p.rp);
- if (p.sortname && p.sortname.length > 0)
- qsParser.set('sortname', p.sortname).set('sortorder', p.sortorder);
- if (p.qtype && p.qtype.length > 0 && p.query.length > 0)
- qsParser.set('filterValue', p.query).set('filterField', p.qtype);
- window.location.href = url + "?" + qsParser.toString();
- }
- return true;
- }
- if (!p.url) return false;
-
- this.loading = true;
-
- $('.pPageStat',this.pDiv).html(p.procmsg);
-
- $('.pReload',this.pDiv).addClass('loading');
-
- //block to prevent to operate the grid.
- var hDivOffset = $(g.hDiv).offset();
- $(g.block).css({
- top:hDivOffset.top,
- left:hDivOffset.left,
- height:$(g.hDiv).height() + $(g.bDiv).height(),
- width:$(g.hDiv).width()
- });
- if (p.hideOnSubmit) $("body").append(g.block); //$(t).hide();
-
- if ($.browser.opera) $(t).css('visibility','hidden');
- //--------------
- //var param = {page:p.newp, rp: p.rp, sortname: p.sortname, sortorder: p.sortorder, query: p.query, qtype: p.qtype};
- var param = [
- { name : p.pageName, value : p.newp }
- ,{ name : p.pageSizeName, value : p.rp }
- ,{ name : 'sortname', value : p.sortname}
- ,{ name : 'sortorder', value : p.sortorder }
- ,{ name : 'filterValue', value : p.query}
- ,{ name : 'filterField', value : p.qtype}
- ];
- if (p.params)
- {
- for (var pi = 0; pi < p.params.length; pi++) param[param.length] = p.params[pi];
- }
-
- $.ajax({
- type: p.method,
- url: p.url,
- data: param,
- timeout : 20000,
- cache : false,
- dataType: p.dataType == 'xhtml' ? 'xml' : p.dataType,
- success: function(data){
- g.loading = false;
- g.addData(data);
- if (p.hideOnSubmit) $(g.block).remove();
- },
- error: function(req, status, e) {
- g.loading = false;
- try {
- if (p.onError)
- p.onError(data);
- else
- alert('获取列表数据失败!\n' + req.status + ":" + req.statusText);
- } catch (e) {}
- if (p.hideOnSubmit) $(g.block).remove();
- },
- complete:function() {
- g.loading = false;
- }
- });
- },
- doSearch: function () {
- p.query = $('input[name=filterValue]',g.sDiv).val();
- p.qtype = $('select[name=filterField]',g.sDiv).val();
- p.newp = 1;
- this.populate();
- },
- changePage: function (ctype){ //change page
-
- if (this.loading) return true;
- switch(ctype)
- {
- case 'first': p.newp = 1; break;
- case 'prev': if (p.page>1) p.newp = parseInt(p.page) - 1; break;
- case 'next': if (p.page<p.pages) p.newp = parseInt(p.page) + 1; break;
- case 'last': p.newp = p.pages; break;
- case 'input':
- var nv = parseInt($('.pcontrol input',this.pDiv).val());
- if (isNaN(nv)) nv = 1;
- if (nv<1) nv = 1;
- else if (nv > p.pages) nv = p.pages;
- $('.pcontrol input',this.pDiv).val(nv);
- p.newp =nv;
- break;
- }
- if (typeof(p.newp) != 'number' || p.newp==p.page) return false;
-
- if (p.onChangePage)
- p.onChangePage(p.newp);
- else
- this.populate();
-
- },
- changeSort: function(th) { //change sortorder
-
- if (this.loading) return true;
-
- p.sortname = th.getAttribute('abbr');
- if (p.sortorder=='asc') p.sortorder = 'desc';
- else p.sortorder = 'asc';
-
- //$(th).addClass('sorted').siblings().removeClass('sorted');
- $('.sdesc', this.hDiv).removeClass('sdesc');
- $('.sasc', this.hDiv).removeClass('sasc');
- $(th).addClass('s' + p.sortorder);
-
- if (p.onChangeSort)
- p.onChangeSort(p.sortname,p.sortorder);
- else
- this.populate();
-
- },
- addRow:function(row) {
- var tr = document.createElement('tr');
- var tbody = g.bDiv.getElementsByTagName("TBODY")[0];
- var rowc = $(tbody).children("tr").length + 1;
- if (rowc % 2 && p.striped) tr.className = 'erow';
- if (row.id) tr.id = 'row' + row.id;
- //add cell
- $('thead tr:first th',g.hDiv).each
- (
- function (i)
- {
- var td = document.createElement('td');
- var field = this.getAttribute('field');
- if (this.tdalign) td.align = this.tdalign;
- td.width = this.width;
- td.style.display = this.style.display;
- var fieldData = " ";
- if (! field) {
- field = "cell" + i;
- }
- if (typeof(row[field]) != 'undefined') {
- fieldData = row[field];
- }
-
- if ($.browser.msie) {
- td.innerHTML = fieldData;
- } else {
- var tdDiv = document.createElement("DIV");
- tdDiv.innerHTML = fieldData;
- tdDiv.style.width = this.width + "px";
- if (this.noWrap == false) tdDiv.style.whiteSpace = "normal";
- td.appendChild(tdDiv);
- }
- tr.appendChild(td);
- td = null;
- if (field == p.sortname && p.sortorder) {
- this.className = 's' + p.sortorder;
- } else {
- this.className = "";
- }
- }
- );
-
- tbody.appendChild(tr);
- tr.onclick = function(){
- if (this == g.selectedRow) return;
- if (g.selectedRow && p.striped)
- g.selectedRow.className = (g.selectedRow.rowIndex % 2 == 1) ? "erow" : "";
- this.className = "trSelected";
- g.selectedRow = this;
- };
-
- if (p.dbclickHandler) {
- tr.ondblclick=function() {
- p.dbclickHandler.call(this, tr);
- }
- }
- },
- deleteRow:function(rowIndex) {
- var tbody = g.bDiv.getElementsByTagName("TBODY")[0];
- $(tbody).children("tr:eq(" + rowIndex + ")").remove();
- },
- getRowByKey:function(keys) {
- if (typeof(keys) == "string") {
- keys = [keys];
- }
- var thead = g.hDiv.getElementsByTagName("THEAD")[0];
- var ths = $(thead).children("tr");
- var keyindex = new Array();
- ths.each (function(i) {
- if (i == 0) {
- $(this).children("th").each(function(c) {
- if (this.getAttribute('key') == 'true') {
- keyindex[keyindex.length] = c;
- }
- });
- }
- });
- var result = null;
- if (keyindex.length > 0) {
- var tbody = g.bDiv.getElementsByTagName("TBODY")[0];
- var trs = $(tbody).children("tr");
-
- trs.each (function(i) {
- if (keyindex.length == 0)
- return;
- var succcount = 0;
- $(this).children("td").each (function(d) {
- for (var j = 0; j < keyindex.length; j++) {
- if (keyindex[j] == d && keys[j] == $.trim($(this).text())) {
- succcount++;
- }
- }
- });
- if (succcount == keyindex.length) {
- result = this;
- return;
- }
- });
- }
- return result;
- },
- deleteRowByKey:function(keys) {
- var tr = this.getRowByKey(keys);
- if (tr != null) $(tr).remove();
- },
- getRowDataByKey:function(keys) {
- var tr = this.getRowByKey(keys);
- var rd = {};
- if (tr == null) return rd;
- tr = $(tr);
- var tbody = g.bDiv.getElementsByTagName("TBODY")[0];
- if (tr.length > 0) {
- $('thead:eq(0) tr:first th',g.hDiv).each
- (
- function (i)
- {
- var field = this.getAttribute('field');
- var cell = tr.children("td:eq(" + i + ")");
- if (field != null && field.length > 0) {
- rd[field] = cell.text().replace(/(^[\s\u00a0]+)|([\s\u00a0]+$)/g, '');
- } else {
- rd["cell" + i] = cell.text().replace(/(^[\s\u00a0]+)|([\s\u00a0]+$)/g, '');
- }
- }
- );
- return rd;
- }
- },
- getRowData:function(rowIndex) {
- var tbody = g.bDiv.getElementsByTagName("TBODY")[0];
- var rd = {};
- var tr = $(tbody).children("tr:eq(" + rowIndex + ")");
- if (tr.length > 0) {
- $('thead tr:first th',g.hDiv).each
- (
- function (i)
- {
- var field = this.getAttribute('field');
- var cell = tr.children("td:eq(" + i + ")");
- if (field != null && field.length > 0) {
- rd[field] = cell.text();
- } else {
- rd["cell" + i] = cell.text();
- }
- }
- );
- return rd;
- }
- },
- addData: function (data) { //parse data
- if (p.preProcess)
- data = p.preProcess(data);
-
- if ($.isFunction(p.ajaxDataHandler)) {
- p.ajaxDataHandler.call(g, data, p);
- }
- $('.pReload',this.pDiv).removeClass('loading');
- this.loading = false;
- if (!data)
- {
- $('.pPageStat',this.pDiv).html(p.errormsg);
- return false;
- }
- p.total = data.total;
-
- var tbody = g.bDiv.getElementsByTagName("TBODY")[0];
-
- while(tbody.firstChild)
- tbody.removeChild(tbody.firstChild);
-
- if (p.total==0)
- {
- p.pages = 1;
- p.page = 1;
- this.buildpager();
- $('.pPageStat',this.pDiv).html(p.nomsg);
- return false;
- }
-
- p.pages = Math.ceil(p.total/p.rp);
- p.page = data.page;
-
- this.buildpager();
- //build new body
-
-
- if (p.dataType=='json')
- {
- $.each (data.rows,
- function(i, row)
- {
- var tr = document.createElement('tr');
- if (i % 2 && p.striped) tr.className = 'erow';
- if (row.id) tr.id = 'row' + row.id;
- //add cell
- $('thead tr:first th',g.hDiv).each
- (
- function ()
- {
- var td = document.createElement('td');
- var field = this.getAttribute('field');
- if (this.tdalign) td.align = this.tdalign;
- td.width = this.width;
- td.style.display = this.style.display;
- if (field) {
- var fieldData = typeof(row[field]) != 'undefined' ? row[field] : " ";
- if ($.browser.msie) {
- td.innerHTML = fieldData;
- } else {
- var tdDiv = document.createElement("DIV");
- tdDiv.innerHTML = fieldData;
- tdDiv.style.width = this.width + "px";
- if (this.noWrap == false) tdDiv.style.whiteSpace = "normal";
- td.appendChild(tdDiv);
- }
- }
- tr.appendChild(td);
- td = null;
- if (field == p.sortname && p.sortorder) {
- this.className = 's' + p.sortorder;
- } else {
- this.className = "";
- }
- }
- );
-
- tbody.appendChild(tr);
- tr.onclick = function(){
- if (this == g.selectedRow) return;
- if (g.selectedRow && p.striped)
- g.selectedRow.className = (g.selectedRow.rowIndex % 2 == 1) ? "erow" : "";
- this.className = "trSelected";
- g.selectedRow = this;
- };
-
- if (p.dbclickHandler) {
- tr.ondblclick=function() {
- p.dbclickHandler.call(this, tr);
- }
- }
- }
- );
- }
- tbody = null; data = null; i = null;
-
- if (p.onSuccess) p.onSuccess();
- if (p.hideOnSubmit) $(g.block).remove();//$(t).show();
-
- this.hDiv.scrollLeft = this.bDiv.scrollLeft;
- if ($.browser.opera) $(t).css('visibility','visible');
-
- //fix the ie6 iframe horizontal scrollbars bug
- if ($.browser.msie && $.browser.version < 7) {
- document.body.style.width = document.documentElement.clientWidth - 2 + "px";
- }
- },
- addContextMenu : function(text, handler) {
- this.contextMenus[text] = handler;
- }
- };
- var frameDiv = document.createElement("DIV");
- frameDiv.className = "flexigrid plain";
- g.gDiv = frameDiv;
-
- if (p.title) {
- var titleDiv = document.createElement("DIV");
- titleDiv.className = "mDiv";
- //titleDiv.innerHTML= p.title;
- frameDiv.appendChild(titleDiv);
- g.mDiv = titleDiv;
- if (p.contextmenu) {
- var ddBox = document.createElement("A");
- ddBox.className = "ddbox";
- ddBox.href = "javascript:void(0)";
- titleDiv.appendChild(ddBox);
-
- var contextmenudiv = document.createElement("DIV");
- contextmenudiv.className = "contextmenu";
-
- frameDiv.appendChild(contextmenudiv);
- g.contextMenus = {};
-
- $(ddBox).click(function(evt) {
- $(contextmenudiv).empty();
- for(var cmdText in g.contextMenus) {
- var mi = document.createElement("A");
- mi.className = "menuitem";
- mi.innerHTML = cmdText;
- mi.href = "javascript:void(0)";
- $(mi).click(function(){
- g.contextMenus[this.innerHTML].call(g, cmdText);
- });
- contextmenudiv.appendChild(mi);
- }
- $(contextmenudiv).css({
- top:15,
- left:evt.pageX - $(contextmenudiv).width()
- }).show();
-
- $(document).one("mouseup", function() {
- $(contextmenudiv).hide();
- });
- });
- }
- var titleBox = document.createElement("DIV");
- if (p.title.charAt(0) == '#') {
- titleBox.appendChild($(p.title).remove().show().get(0));
- } else {
- titleBox.innerHTML = p.title;
- }
- titleDiv.appendChild(titleBox);
- }
-
- var thead = t.getElementsByTagName("THEAD")[0];
- var tbody = t.getElementsByTagName("TBODY")[0];
-
- var headerDiv = document.createElement("DIV");
- headerDiv.className = "hDiv";
- g.hDiv = headerDiv;
-
- var headerTable = document.createElement("TABLE");
- headerTable.style.tableLayout = "fixed";
- headerTable.cellSpacing = 0;
- headerTable.cellPadding = 0;
-
- var nh = document.createElement("THEAD");
- var nhr = document.createElement("TR");
-
- nh.appendChild(nhr);
-
- var headTHs = thead.getElementsByTagName("TR")[0].cells;
- for (var i = 0; i < headTHs.length; i++) {
- var th = headTHs[i].cloneNode($.browser.msie);
- if (!$.browser.msie) {
- var thDiv = document.createElement("DIV");
- thDiv.innerHTML = headTHs[i].innerHTML;
- thDiv.style.width = headTHs[i].width + "px";
- th.appendChild(thDiv);
- }
- nhr.appendChild(th);
- th.style.textAlign = th.align;
- if (th.getAttribute("abbr")) {
- $(th).click(function(){
- g.changeSort(this);
- });
- if (p.sortname == th.getAttribute("abbr") && p.sortorder) {
- th.className = "s" + p.sortorder;
- }
- }
- }
- g.selectedRow = null;
- var rows = tbody.getElementsByTagName("TR");
- for (var i = 0; i < rows.length; i++) {
- if(p.striped){
- if (i % 2 == 1) rows[i].className = "erow";
- }
- rows[i].onclick = function(){
- if (this == g.selectedRow) return;
- if (g.selectedRow && p.striped)
- g.selectedRow.className = (g.selectedRow.rowIndex % 2 == 1) ? "erow" : "";
- this.className = "trSelected";
- g.selectedRow = this;
- };
- if (p.dbclickHandler) {
- rows[i].ondblclick=function() {
- p.dbclickHandler.call(this, rows[i]);
- }
- }
- if (!$.browser.msie) {
- for (var j = 0; j < rows[i].cells.length; j++) {
- var td = rows[i].cells[j];
- var tdDiv = document.createElement("DIV");
- //tdDiv.innerHTML = td.innerHTML;
- tdDiv.style.width = td.width + "px";
- if (td.noWrap == false) tdDiv.style.whiteSpace = "normal";
- while (td.firstChild)
- tdDiv.appendChild(td.removeChild(td.firstChild));
- td.appendChild(tdDiv);
- }
- }
- }
-
- while(thead.firstChild)
- thead.removeChild(thead.firstChild);
-
- headerTable.appendChild(nh);
- headerDiv.appendChild(headerTable);
-
- frameDiv.appendChild(headerDiv);
-
- var bodyDiv = document.createElement("DIV");
- bodyDiv.className = "bDiv";
-
- g.bDiv = bodyDiv;
-
- $(bodyDiv).scroll(function(){
- headerDiv.scrollLeft = this.scrollLeft;
- });
-
- if (!isNaN(p.restHeight)) {
- var bch = document.documentElement.clientHeight;
- bch -= p.restHeight;
- if (p.usepager)
- bch -= 30;
- if (p.title)
- bch -= 30;
- p.height = bch - 30;
- }
- if (p.height != 'auto') {
- bodyDiv.style.height = p.height + "px";
- } else {
- bodyDiv.style.overflowY = "hidden";
- bodyDiv.style.height = 'auto';
- t.className = "autoht";
- }
-
- var pc = t.parentNode;
- frameDiv.appendChild(bodyDiv);
-
- // add pager
- if (p.usepager){
-
- var pDiv = document.createElement("DIV");
- g.pDiv = pDiv;
- pDiv.className = 'pDiv';
- pDiv.innerHTML = '<div class="pDiv2"></div><div class="pDiv3"></div>';
- frameDiv.appendChild(pDiv);
-
- if (typeof(p.pages) == 'undefined') p.pages = p.rp == 0 ? 0 : Math.ceil(p.total/p.rp);
- var html = ' <div class="pGroup"> <div class="pFirst pButton"><span></span></div><div class="pPrev pButton"><span></span></div> </div> <div class="btnseparator"></div> <div class="pGroup"><span class="pcontrol">页码 <input type="text" size="1" value="' + p.page + '" /> 共 <span>' + p.pages + ' 页 </span></span></div> <div class="btnseparator"></div> <div class="pGroup"> <div class="pNext pButton"><span></span></div><div class="pLast pButton"><span></span></div> </div> <div class="btnseparator"></div> <div class="pGroup"> <div class="pReload pButton"><span></span></div> </div> <div class="btnseparator"></div>';
- $('.pDiv2', pDiv).html(html);
- var html3 = '<div class="rightGroup"><span class="pPageStat"></span></div>';
- $('.pDiv3', pDiv).html(html3);
-
- $('.pReload',g.pDiv).click(function(){g.populate()});
- $('.pFirst',g.pDiv).click(function(){g.changePage('first')});
- $('.pPrev',g.pDiv).click(function(){g.changePage('prev')});
- $('.pNext',g.pDiv).click(function(){g.changePage('next')});
- $('.pLast',g.pDiv).click(function(){g.changePage('last')});
- $('.pcontrol input',g.pDiv).keydown(function(e){if(e.keyCode==13) g.changePage('input')});
- if ($.browser.msie&&$.browser.version<7) $('.pButton',g.pDiv).hover(function(){$(this).addClass('pBtnOver');},function(){$(this).removeClass('pBtnOver');});
-
- g.buildpager();
-
- if (p.useRp)
- {
- var opt = "";
- for (var nx=0;nx<p.rpOptions.length;nx++)
- {
- if (p.rp == p.rpOptions[nx]) sel = 'selected="selected"'; else sel = '';
- opt += "<option value='" + p.rpOptions[nx] + "' " + sel + " >" + p.rpOptions[nx] + " </option>";
- };
- $('.pDiv2',g.pDiv).prepend("<div class='pGroup'><select name='rp'>"+opt+"</select></div> <div class='btnseparator'></div>");
- $('select',g.pDiv).change(
- function ()
- {
- if (p.onRpChange)
- p.onRpChange(+this.value);
- else
- {
- p.newp = 1;
- p.rp = +this.value;
- g.populate();
- }
- }
- );
- }
-
- //add search button
- if (p.searchitems && p.searchitems.length > 0)
- {
- g.sDiv = document.createElement("DIV");
- frameDiv.insertBefore(g.sDiv, g.pDiv);
- $('.pDiv2',g.pDiv).prepend("<div class='pGroup'> <div class='pSearch pButton'><span></span></div> </div> <div class='btnseparator'></div>");
- $('.pSearch',g.pDiv).click(function(){$(g.sDiv).slideToggle('fast',function(){$('.sDiv:visible input:first',g.gDiv).trigger('focus');});});
- //add search box
- g.sDiv.className = 'sDiv';
-
- sitems = p.searchitems;
-
- var sopt = "";
- for (var s = 0; s < sitems.length; s++)
- {
- if (p.qtype=='' && sitems[s].isdefault==true)
- {
- p.qtype = sitems[s].name;
- sel = 'selected="selected"';
- } else sel = '';
- sopt += "<option value='" + sitems[s].name + "' " + sel + " >" + sitems[s].display + " </option>";
- }
-
- if (p.qtype=='') p.qtype = sitems[0].name;
-
- $(g.sDiv).append("<div class='sDiv2'>过滤条件 <select name='filterField'>"+sopt+"</select> <input type='text' size='30' name='filterValue' class='qsbox' /> <input type='button' value='确定' /> <input type='button' value='重置' /></div>");
- $('input[name=filterField],select[name=filterValue]',g.sDiv).keydown(function(e){if(e.keyCode==13) g.doSearch()});
- $('input[value=重置]',g.sDiv).click(function(){$('input[name=q]',g.sDiv).val(''); p.query = ''; g.doSearch(); });
- $('input[value=确定]', g.sDiv).click(function(){g.doSearch()});
- $(g.bDiv).after(g.sDiv);
- }
- }
-
- pc.insertBefore(frameDiv, t);
- t.cellPadding = 0;
- t.cellSpacing = 0;
- bodyDiv.appendChild(pc.removeChild(t));
-
- if ($.browser.msie&&$.browser.version<7.0)
- {
- if (g.mDiv)
- g.mDiv.style.width = "100%";
- g.bDiv.style.width = "100%";
- g.hDiv.style.width = "100%";
- if (g.pDiv)
- g.pDiv.style.width = "100%";
- if (g.sDiv)
- g.sDiv.style.width = "100%";
- g.gDiv.className = g.gDiv.className + " ie6";
- if (p.width!='auto') g.gDiv.className = g.gDiv.className + ' ie6fullwidthbug';
- }
- t.style.display = "block";
-
- g.block = document.createElement("DIV");
- g.block.className = "gBlock";
- t.p = p;
- t.grid = g;
- // load data
- if (p.url&&p.autoload&&p.useAjax)
- {
- g.populate();
- }
-
- return g;
- }
-
-
-
-
-
-
-
- var docloaded = false;
- $(document).ready(function () {docloaded = true} );
- $.fn.hcksGrid = function(p) {
- return this.each( function() {
- var t = this;
- if (!docloaded)
- {
- $(this).hide();
- $(document).ready (function(){
- if (p.plain) {
- $.addPlainFlex(t, p);
- } else {
- $.addFlex(t,p);
- }
- });
- } else {
- if (p.plain) {
- $.addPlainFlex(t, p);
- } else {
- $.addFlex(t,p);
- }
- }
- });
- }; //end grid
- $.fn.gridReload = function(p) { // function to reload grid
- return this.each( function() {
- if (this.grid && this.p.url) this.grid.populate();
- });
- }; //end flexReload
- $.fn.gridOptions = function(p) { //function to update general options
- return this.each( function() {
- if (this.grid) $.extend(this.p,p);
- });
- }; //end flexOptions
- $.fn.gridToggleCol = function(cid,visible) { // function to reload grid
- return this.each( function() {
- if (this.grid) this.grid.toggleCol(cid,visible);
- });
- }; //end flexToggleCol
- $.fn.gridAddData = function(data) { // function to add data to grid
- return this.each( function() {
- if (this.grid) this.grid.addData(data);
- });
- };
- $.fn.noSelect = function(p) { //no select plugin by me :-)
- if (p == null)
- prevent = true;
- else
- prevent = p;
- if (prevent) {
-
- return this.each(function ()
- {
- if ($.browser.msie||$.browser.safari) $(this).bind('selectstart',function(){return false;});
- else if ($.browser.mozilla)
- {
- $(this).css('MozUserSelect','none');
- $('body').trigger('focus');
- }
- else if ($.browser.opera) $(this).bind('mousedown',function(){return false;});
- else $(this).attr('unselectable','on');
- });
-
- } else {
-
- return this.each(function ()
- {
- if ($.browser.msie||$.browser.safari) $(this).unbind('selectstart');
- else if ($.browser.mozilla) $(this).css('MozUserSelect','inherit');
- else if ($.browser.opera) $(this).unbind('mousedown');
- else $(this).removeAttr('unselectable','on');
- });
-
- }
- }; //end noSelect
-
- })(jQuery);
|