1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054 |
- /*
- * Copyright Scand LLC http://www.scbr.com To use this component please contact
- * info@scbr.com to obtain license
- */
- /*
- * _TOPICS_ @0:initialization @1:selection control @2:rows control @3:colums
- * control @4:cells controll @5:data manipulation @6:appearence control
- * @7:overal control @8:tools @9:treegrid @10: event handlers
- */
- var globalActiveDHTMLGridObject;
- String.prototype._dhx_trim = function() {
- return this.replace(/ /g, " ").replace(/(^[ \t]*)|([ \t]*$)/g, "");
- }
- Array.prototype._dhx_find = function(pattern) {
- for (var i = 0; i < this.length; i++) {
- if (pattern == this[i])
- return i;
- }
- return -1;
- }
- Array.prototype._dhx_delAt = function(ind) {
- if (Number(ind) < 0 || this.length == 0)
- return false;
- for (var i = ind; i < this.length; i++) {
- this[i] = this[i + 1];
- }
- this.length--;
- }
- Array.prototype._dhx_insertAt = function(ind, value) {
- this[this.length] = null;
- for (var i = this.length - 1; i >= ind; i--) {
- this[i] = this[i - 1]
- }
- this[ind] = value
- }
- Array.prototype._dhx_removeAt = function(ind) {
- for (var i = ind; i < this.length; i++) {
- this[i] = this[i + 1]
- }
- this.length--;
- }
- /*
- * Array.prototype.moveTo = function(ind,ind2){
- * this._dhx_insertAt(ind,this[ind2]); this._dhx_delAt(ind2*1+1); } -
- */
- Array.prototype._dhx_swapItems = function(ind1, ind2) {
- var tmp = this[ind1];
- this[ind1] = this[ind2]
- this[ind2] = tmp;
- }
- /**
- * @desc: dhtmlxGrid constructor
- * @param: id - (optional) id of div element to base grid on
- * @returns: dhtmlxGrid object
- * @type: public
- */
- function dhtmlXGridObject(id) {
- if (id) {
- if (typeof(id) == 'object') {
- this.entBox = id
- this.entBox.id = "cgrid2_" + (allGetServerTime()).getTime();
- } else
- this.entBox = document.getElementById(id);
- } else {
- this.entBox = document.createElement("DIV");
- this.entBox.id = "cgrid2_" + (allGetServerTime()).getTime();
- }
- this._tttag = this._tttag || "rows";
- this._cttag = this._cttag || "cell";
- this._rttag = this._rttag || "row";
- var self = this;
- this.nm = this.entBox.nm || "grid";
- this.cell = null;
- this.row = null;
- this.editor = null;
- this._f2kE = true;
- this._dclE = true;
- this.combos = new Array(0);
- this.defVal = new Array(0);
- this.rowsAr = new Array(0);// array of rows by idd
- this.rowsCol = new Array(0);// array of rows by index
- this._maskArr = new Array(0);
- this.selectedRows = new Array(0);// selected rows array
- this.rowsBuffer = new Array(new Array(0), new Array(0));// buffer of rows
- // loaded, but not
- // rendered (array
- // of ids, array of
- // cell values
- // arrays)
- this.loadedKidsHash = null;// not null if there is tree cell in grid
- this.UserData = new Array(0)// array of rows (and for grid -
- // "gridglobaluserdata") user data elements
- /* MAIN OBJECTS */
- this.styleSheet = document.styleSheets;
- this.entBox.className = "gridbox";
- this.entBox.style.width = this.entBox.getAttribute("width")
- || (window.getComputedStyle ? window.getComputedStyle(this.entBox,
- null)["width"] : (this.entBox.currentStyle
- ? this.entBox.currentStyle["width"]
- : 0)) || "100%";
- this.entBox.style.height = this.entBox.getAttribute("height")
- || (window.getComputedStyle ? window.getComputedStyle(this.entBox,
- null)["height"] : (this.entBox.currentStyle
- ? this.entBox.currentStyle["height"]
- : 0)) || "100%";
- // cursor and text selection
- this.entBox.style.cursor = 'default';
- this.entBox.onselectstart = function() {
- return false
- };// avoid text select
- this.obj = document.createElement("TABLE");
- this.obj.cellSpacing = 0;
- this.obj.cellPadding = 0;
- this.obj.style.width = "100%";// nb:
- this.obj.style.tableLayout = "fixed";
- this.obj.className = "obj";
- this.hdr = document.createElement("TABLE");
- this.hdr.style.border = "1px solid gray"; // FF 1.0 fix
- this.hdr.cellSpacing = 0;
- this.hdr.cellPadding = 0;
- if (!_isOpera)
- this.hdr.style.tableLayout = "fixed";
- this.hdr.className = "hdr";
- this.hdr.width = "100%";
- this.xHdr = document.createElement("TABLE");
- this.xHdr.cellPadding = 0;
- this.xHdr.cellSpacing = 0;
- var r = this.xHdr.insertRow(0)
- var c = r.insertCell(0);
- r.insertCell(1).innerHTML = " ";
- c.appendChild(this.hdr)
- this.objBuf = document.createElement("DIV");
- this.objBuf.style.borderBottom = "1px solid white"
- this.objBuf.appendChild(this.obj);
- this.entCnt = document.createElement("TABLE");
- this.entCnt.insertRow(0).insertCell(0)
- this.entCnt.insertRow(1).insertCell(0);
- this.entCnt.cellPadding = 0;
- this.entCnt.cellSpacing = 0;
- this.entCnt.width = "100%";
- this.entCnt.height = "100%";
- this.entCnt.style.tableLayout = "fixed";
- this.objBox = document.createElement("DIV");
- this.objBox.style.width = "100%";
- this.objBox.style.height = this.entBox.style.height;
- this.objBox.style.overflow = "auto";
- this.objBox.style.position = "relative";
- this.objBox.appendChild(this.objBuf);
- this.objBox.className = "objbox";
- this.hdrBox = document.createElement("DIV");
- this.hdrBox.style.width = "100%"
- if ((_isOpera) || ((_isMacOS) && (_isFF)))
- this.hdrSizeA = 25;
- else
- this.hdrSizeA = 100;
- this.hdrBox.style.height = this.hdrSizeA + "px";
- if (((_isOpera) || ((_isMacOS) && (_isFF))))
- this.hdrBox.style.overflow = "hidden";
- else if (!_isKHTML)
- this.hdrBox.style.overflowX = "hidden";
- this.hdrBox.style.position = "relative";
- this.hdrBox.appendChild(this.xHdr);
- this.preloadImagesAr = new Array(0)
- this.sortImg = document.createElement("IMG")
- this.hdrBox.insertBefore(this.sortImg, this.xHdr)
- this.entCnt.rows[0].cells[0].vAlign = "top";
- this.entCnt.rows[0].cells[0].appendChild(this.hdrBox);
- this.entCnt.rows[1].cells[0].appendChild(this.objBox);
- this.entBox.appendChild(this.entCnt);
- // add links to current object
- this.entBox.grid = this;
- this.objBox.grid = this;
- this.hdrBox.grid = this;
- this.obj.grid = this;
- this.hdr.grid = this;
- /* PROPERTIES */
- this.cellWidthPX = new Array(0);// current width in pixels
- this.cellWidthPC = new Array(0);// width in % if cellWidthType set in pc
- this.cellWidthType = this.entBox.cellwidthtype || "px";// px or %
- this.delim = this.entBox.delimiter || ",";
- this.hdrLabels = (this.entBox.hdrlabels || "").split(",");
- this.columnIds = (this.entBox.columnids || "").split(",");
- this.columnColor = (this.entBox.columncolor || "").split(",");
- this.cellType = (this.entBox.cellstype || "").split(",");
- this.cellAlign = (this.entBox.cellsalign || "").split(",");
- this.initCellWidth = (this.entBox.cellswidth || "").split(",");
- this.fldSort = (this.entBox.fieldstosort || "").split(",")
- this.imgURL = this.entBox.imagesurl || "gridCfx/";
- this.isActive = false;// fl to indicate if grid is in work now
- this.isEditable = true;
- this.raNoState = this.entBox.ranostate || "N";
- this.chNoState = this.entBox.chnostate || "N";
- this.selBasedOn = (this.entBox.selbasedon || "cell").toLowerCase()
- this.selMultiRows = this.entBox.selmultirows || false;
- this.multiLine = this.entBox.multiline || false;
- this.noHeader = this.entBox.noheader || false;
- this.dynScroll = this.entBox.dynscroll || false;// add/remove rows from dom
- this.dynScrollPageSize = 0;// will be autodetected
- this.dynScrollPos = 0;// position of dynamic scroll
- this.xmlFileUrl = this.entBox.xmlfileurl || "";
- this.recordsNoMore = this.entBox.infinitloading || true;;// if true, then
- // it will not
- // attempt to
- // fill the
- // buffer from
- // server
- this.useImagesInHeader = false;// use images in header or not
- // this.dynScrollBuffer = 100;//number of rows in buffer
- this.rowsBufferOutSize = 0;// number of rows rendered at a moment
- /* EVENTS */
- if (this.entBox.oncheckbox)
- this.onCheckbox = eval(this.entBox.oncheckbox);// rId,state,cInd
- this.onEditCell = this.entBox.oneditcell || function() {
- return true;
- };// fl,rid,cInd
- this.onRowSelect = this.entBox.onrowselect || function() {
- return true;
- };// rId,false
- this.onEnter = this.entBox.onenter || function() {
- return true;
- };// rId,cin
- if (window.addEventListener)
- window.addEventListener("unload", function() {
- try {
- self.destructor();
- } catch (e) {
- }
- }, false);
- if (window.attachEvent)
- window.attachEvent("onunload", function() {
- try {
- self.destructor();
- } catch (e) {
- }
- });
- /* XML LOADER(S) */
- /**
- * @desc: loads xml content from specified url
- * @type: public
- * @topic: 0,5
- */
- this.loadXML = function(url) {
- if (url.indexOf("?") != -1)
- var s = "&";
- else
- var s = "?";
- if (this.onXLS)
- this.onXLS(this);
- this.xmlLoader.loadXML(url + "" + s + "rowsLoaded=" + this.getRowsNum()
- + "&lastid=" + this.getRowId(this.getRowsNum() - 1) + "&sn="
- + Date.parse(allGetServerTime()));
- }
- /**
- * @desc: loads xml content from specified string
- * @type: public
- * @topic: 0,5
- * @edition: Professional
- */
- this.loadXMLString = function(str) {
- if (this.onXLS)
- this.onXLS(this);
- this.xmlLoader.loadXMLString(str);
- }
- /**
- * @desc: puts xml to parser
- * @type: private
- * @topic: 0,5
- */
- this.doLoadDetails = function(obj) {
- var root = self.xmlLoader.getXMLTopNode(self._tttag)
- if (root.tagName != "DIV")
- if (!self.xmlLoader.xmlDoc.nodeName) {
- self.parseXML(self.xmlLoader.xmlDoc.responseXML)
- } else {
- self.parseXML(self.xmlLoader.xmlDoc)
- }
- }
- this.xmlLoader = new dtmlXMLLoaderObject(this.doLoadDetails, window);
- this.dragger = new dhtmlDragAndDropObject();
- /* METHODS. SERVICE */
- /**
- * @desc: on scroll grid inside actions
- * @type: private
- * @topic: 7
- */
- this._doOnScroll = function(e, mode) {
- if (this._onSCRL)
- this._onSCRL(this.objBox.scrollLeft, this.objBox.scrollTop);
- this.doOnScroll(e, mode);
- }
- this.doOnScroll = function(e, mode) {
- this.hdrBox.scrollLeft = this.objBox.scrollLeft;
- this.setSortImgPos(null, true);
- if (mode)
- return;
- if (this.objBox.scrollTop + this.hdrSizeA + this.objBox.offsetHeight > this.objBox.scrollHeight) {
- if (this._xml_ready && this.addRowsFromBuffer())
- this.objBox.scrollTop = this.objBox.scrollHeight
- - (this.hdrSizeA + 1 + this.objBox.offsetHeight)
- }
- }
- /**
- * @desc: attach this grid to some object in DOM
- * @param: obj - object to attach to
- * @type: public
- * @topic: 0,7
- */
- this.attachToObject = function(obj) {
- obj.appendChild(this.entBox)
- }
- /**
- * @desc: initialize grid
- * @param: fl - if to parse on page xml dataisland
- * @type: public
- * @topic: 0,7
- */
- this.init = function(fl) {
- // debugger;
- this.editStop()
- /* TEMPORARY STATES */
- this.lastClicked = null;// row clicked without shift key. used in
- // multiselect only
- this.resized = null;// hdr cell that is resized now
- this.fldSorted = null;// hdr cell last sorted
- this.gridWidth = 0;
- this.gridHeight = 0;
- // empty grid if it already was initialized
- this.cellWidthPX = new Array(0);
- this.cellWidthPC = new Array(0);
- if (this.hdr.rows.length > 0) {
- this.clearAll();
- this.hdr.rows[0].removeNode(true);// this.hdr.firstChild.removeChild(this.hdr.rows[0])
- }
- if (this.cellType._dhx_find("tree") != -1) {// create hashtable for
- // treegrid
- this.loadedKidsHash = new Hashtable();
- this.loadedKidsHash.put("hashOfParents", new Hashtable())
- }
- var hdrRow = this.hdr.insertRow(0);
- for (var i = 0; i < this.hdrLabels.length; i++) {
- hdrRow.insertCell(i);
- this.setHeaderCol(i, this.hdrLabels[i])
- /*
- * if(!this.useImagesInHeader) hdrRow.insertCell(i).innerHTML =
- * this.hdrLabels[i]; else{//if images in header header
- * hdrRow.insertCell(i).innerHTML = "<img
- * src='"+this.imgURL+""+this.hdrLabels[i]+"'>";
- * this.preloadImagesAr[this.preloadImagesAr.length] =
- * this.imgURL+""+this.hdrLabels[i].replace(/(\.[a-z]+)/,".desc$1")
- * this.preloadImagesAr[this.preloadImagesAr.length] =
- * this.imgURL+""+this.hdrLabels[i].replace(/(\.[a-z]+)/,".asc$1") }
- */
- hdrRow.cells[i]._cellIndex = i;
- }
- this.setColumnIds()
- if (this.multiLine == -1)
- this.multiLine = true;
- //
- // this.combos = new Array(this.hdrLabels.length);
- // set sort image to initial state
- this.sortImg.style.position = "absolute";
- this.sortImg.style.display = "none";
- this.sortImg.src = this.imgURL + "sort_desc.gif";
- this.sortImg.defLeft = 0;
- // create and kill a row to set initial size
- // this.addRow("deletethisrtowafterresize",new Array("",""))
- this.entCnt.rows[0].style.display = ''// display header
- if (this.noHeader == -1) {
- this.noHeader = true
- this.entCnt.rows[0].style.display = 'none';
- } else {
- this.noHeader = false
- }
- // ========================
- this.attachHeader();
- this.attachHeader(0, 0, "_aFoot");
- // =========================
- if (this._ivizcol)
- for (var i = 0; i < this._ivizcol.length; i++)
- this.setColumnHidden(i, this._ivizcol[i]);
- this.setSizes();
- // this.deleteRow("deletethisrtowafterresize")
- // parse inline xml
- if (fl)
- this.parseXML()
- this.obj.scrollTop = 0
- if (this.dragAndDropOff)
- this.dragger.addDragLanding(this.entBox, this);
- };
- /**
- * @desc: sets sizes of grid elements
- * @type: private
- * @topic: 0,7
- */
- this.setSizes = function(fl) {
- if (fl && this.gridWidth == this.entBox.offsetWidth
- && this.gridHeight == this.entBox.offsetHeight) {
- return false
- } else if (fl) {
- this.gridWidth = this.entBox.offsetWidth
- this.gridHeight = this.entBox.offsetHeight
- }
- if ((!this.hdrBox.offsetHeight) && (this.hdrBox.offsetHeight > 0))
- this.entCnt.rows[0].cells[0].height = this.hdrBox.offsetHeight
- + "px";
- var gridWidth = parseInt(this.entBox.offsetWidth);
- var gridHeight = parseInt(this.entBox.offsetHeight);
- if (this.objBox.scrollHeight > this.objBox.offsetHeight)
- gridWidth -= (this._scrFix || (_isFF ? 19 : 16));
- var len = this.hdr.rows[0].cells.length
- for (var i = 0; i < this.hdr.rows[0].cells.length; i++) {
- if (this.cellWidthType == 'px' && this.cellWidthPX.length < len) {
- this.cellWidthPX[i] = this.initCellWidth[i];
- } else if (this.cellWidthType == '%'
- && this.cellWidthPC.length < len) {
- this.cellWidthPC[i] = this.initCellWidth[i];
- }
- if (this.cellWidthPC.length != 0) {
- this.cellWidthPX[i] = parseInt(gridWidth * this.cellWidthPC[i]
- / 100)
- - (_isFF ? 2 : 0);
- }
- }
- this.chngCellWidth(this.rowsCol._dhx_find(this.obj.rows[0]))
- var summ = 0;
- for (var i = 0; i < this.cellWidthPX.length; i++)
- summ += parseInt(this.cellWidthPX[i])
- this.objBuf.style.width = summ + "px";
- this.objBuf.childNodes[0].style.width = summ + "px";
- if (_isOpera)
- this.hdr.style.width = summ + this.cellWidthPX.length * 2 + "px";
- // set auto page size of dyn scroll
- this.doOnScroll(0, 1);
- // set header part of container visible height to header's height
- // this.entCnt.rows[0].cells[0].style.height = this.hdr.offsetHeight;
- this.hdr.style.border = "0px solid gray"; // FF 1.0 fix
- if ((_isMacOS) && (_isFF))
- var zheight = 20;
- else
- var zheight = this.hdr.offsetHeight;
- if (this._ahgr)
- if (this.objBox.scrollHeight) {
- if (_isIE)
- var z2 = this.objBox.scrollHeight;
- else
- var z2 = this.objBox.childNodes[0].scrollHeight;
- if (this._ahgrM)
- z2 = (z2 > this._ahgrM ? this._ahgrM : z2) * 1;
- gridHeight = z2
- + zheight
- + ((this.objBox.offsetWidth < this.objBox.scrollWidth)
- ? (_isFF ? 20 : 18)
- : 1);
- this.entBox.style.height = gridHeight + "px";
- }
- if (!this.noHeader)
- this.entCnt.rows[1].cells[0].childNodes[0].style.top = (zheight
- - this.hdrBox.offsetHeight + 1)
- + "px";
- // nb 072006:
- this.entCnt.rows[1].cells[0].childNodes[0].style.height = (((gridHeight
- - zheight - 1) < 0 && _isIE) ? 20 : (gridHeight - zheight - 1))
- + "px";
- };
- /**
- * @desc: changes cell width
- * @param: [ind] - index of row in grid
- * @type: private
- * @topic: 4,7
- */
- this.chngCellWidth = function(ind) {
- if (!ind)
- var ind = 0;
- for (var i = 0; i < this.cellWidthPX.length; i++) {
- this.hdr.rows[0].cells[i].style.width = this.cellWidthPX[i] + "px";
- if (this.rowsCol[ind])
- this.rowsCol[ind].cells[i].style.width = this.cellWidthPX[i]
- + "px";
- }
- }
- /**
- * @desc: set default delimiter
- * @param: delim - delimiter as string
- * @before_init: 1
- * @type: public
- * @topic: 0
- */
- this.setDelimiter = function(delim) {
- this.delim = delim;
- }
- /**
- * @desc: set width of columns in percents
- * @type: public
- * @before_init: 1
- * @param: wp - width in percents
- * @topic: 0,7
- */
- this.setInitWidthsP = function(wp) {
- this.cellWidthType = "%";
- this.initCellWidth = wp.split(this.delim.replace(/px/gi, ""));
- var el = window;
- var self = this;
- if (el.addEventListener) {
- if ((_isFF) && (_FFrv < 1.8))
- el.addEventListener("resize", function() {
- if (!self.entBox)
- return;
- var z = self.entBox.style.width;
- self.entBox.style.width = "1px";
- window.setTimeout(function() {
- self.entBox.style.width = z;
- self.setSizes();
- }, 10);
- }, false);
- else
- el.addEventListener("resize", function() {
- if (self.setSizes)
- self.setSizes();
- }, false);
- } else if (el.attachEvent)
- el.attachEvent("onresize", function() {
- if (self._resize_timer)
- window.clearTimeout(self._resize_timer);
- if (self.setSizes)
- self._resize_timer = window.setTimeout(function() {
- self.setSizes();
- }, 500);
- });
- }
- /**
- * @desc: set width of columns in pixels
- * @type: public
- * @before_init: 1
- * @param: wp - width in pixels
- * @topic: 0,7
- */
- this.setInitWidths = function(wp) {
- this.cellWidthType = "px";
- this.initCellWidth = wp.split(this.delim);
- if (_isFF) {
- for (var i = 0; i < this.initCellWidth.length; i++)
- this.initCellWidth[i] = parseInt(this.initCellWidth[i]) - 2;
- }
- }
- /**
- * @desc: set multiline rows support to enabled or disabled state
- * @type: public
- * @before_init: 1
- * @param: state - true or false
- * @topic: 0,7
- */
- this.enableMultiline = function(state) {
- this.multiLine = convertStringToBoolean(state);
- }
- /**
- * @desc: set multiselect mode to enabled or disabled state
- * @type: public
- * @param: state - true or false
- * @topic: 0,7
- */
- this.enableMultiselect = function(state) {
- this.selMultiRows = state;
- }
- /**
- * @desc: set path to grid internal images (sort direction, any images used
- * in editors, checkbox, radiobutton)
- * @type: public
- * @param: path - path to images folder with closing "/"
- * @topic: 0,7
- */
- this.setImagePath = function(path) {
- this.imgURL = path;
- }
- /**
- * @desc: part of column resize routine
- * @type: private
- * @param: ev - event
- * @topic: 3
- */
- this.changeCursorState = function(ev) {
- var el = ev.target || ev.srcElement;
- if ((el.tagName == "TD") && (this._drsclmn)
- && (!this._drsclmn[el._cellIndex]))
- return;
- if ((el.offsetWidth - (ev.offsetX || (parseInt(this.getPosition(el,
- this.hdrBox)) - ev.layerX)
- * -1)) < 10) {
- el.style.cursor = "E-resize";
- } else
- el.style.cursor = "default";
- }
- /**
- * @desc: part of column resize routine
- * @type: private
- * @param: ev - event
- * @topic: 3
- */
- this.startColResize = function(ev) {
- this.resized = null;
- var el = ev.target || ev.srcElement;
- var x = ev.layerX || ev.x;
- var tabW = this.hdr.offsetWidth;
- var startW = parseInt(el.offsetWidth)
- if (el.tagName == "TD" && el.style.cursor != "default") {
- if ((this._drsclmn) && (!this._drsclmn[el._cellIndex]))
- return;
- this.entBox.onmousemove = function(e) {
- this.grid.doColResize(e || window.event, el, startW, x, tabW)
- }
- document.body.onmouseup = new Function("",
- "document.getElementById('" + this.entBox.id
- + "').grid.stopColResize()");
- }
- }
- /**
- * @desc: part of column resize routine
- * @type: private
- * @param: ev - event
- * @topic: 3
- */
- this.stopColResize = function() {
- this.entBox.onmousemove = "";// removeEventListener("mousemove")//
- document.body.onmouseup = "";
- this.setSizes();
- this.doOnScroll(0, 1)
- if (this.onRSE)
- this.onRSE(this);
- }
- /**
- * @desc: part of column resize routine
- * @param: el - element (column resizing)
- * @param: startW - started width
- * @param: x - x coordinate to resize from
- * @param: tabW - started width of header table
- * @type: private
- * @topic: 3
- */
- this.doColResize = function(ev, el, startW, x, tabW) {
- el.style.cursor = "E-resize";
- this.resized = el;
- var fcolW = startW + ((ev.layerX || ev.x) - x);
- var wtabW = tabW + ((ev.layerX || ev.x) - x)
- if ((this.onRSI) && (!this.onRSI(el._cellIndex, fcolW, this)))
- return;
- var gridWidth = parseInt(this.entBox.offsetWidth);
- if (this.objBox.scrollHeight > this.objBox.offsetHeight)
- gridWidth -= (this._scrFix || (_isFF ? 19 : 16));
- if (fcolW > 10) {
- el.style.width = fcolW + "px";
- if (this.rowsCol.length > 0)
- // for (var i=0; i<this.obj.rows.length; i++)
- // this.obj.rows[i].cells[el._cellIndex].style.width =
- // fcolW+"px";
- this.rowsCol[this.rowsCol._dhx_find(this.obj.rows[0])].cells[el._cellIndex].style.width = fcolW
- + "px";
- if (this.cellWidthType == 'px') {
- this.cellWidthPX[el._cellIndex] = fcolW;
- } else {
- var pcWidth = Math.round(fcolW / gridWidth * 100)
- this.cellWidthPC[el._cellIndex] = pcWidth;
- }
- this.doOnScroll(0, 1)
- }
- /*
- * for(var i=0;i<this.cellWidthPX.length;i++) summ +=
- * parseInt(this.cellWidthPX[i]) this.objBuf.style.width = summ + "px";
- */
- this.objBuf.childNodes[0].style.width = "";
- }
- /**
- * @desc: sets position and visibility of sort image
- * @param: [state] - true/false - show/hide image
- * @param: [ind] - index of field
- * @param: [direction] - ASC/DESC - type of image
- * @type: public
- * @edition: Professional
- * @topic: 7
- */
- this.setSortImgState = function(state, ind, direction) {
- if (!convertStringToBoolean(state)) {
- this.sortImg.style.display = "none";
- return;
- }
- if (direction == "ASC")
- this.sortImg.src = this.imgURL + "sort_asc.gif";
- else
- this.sortImg.src = this.imgURL + "sort_desc.gif";
- this.sortImg.style.display = "";
- this.fldSorted = this.hdr.rows[0].cells[ind];
- this.setSortImgPos(ind);
- }
- /**
- * @desc: sets position and visibility of sort image
- * @param: [ind] - index of field
- * @type: private
- * @topic: 7
- */
- this.setSortImgPos = function(ind, mode) {
- if (!ind)
- var el = this.fldSorted;
- else
- var el = this.hdr.rows[0].cells[ind];
- if (el != null) {
- var pos = this.getPosition(el, this.hdrBox)
- var wdth = el.offsetWidth;
- this.sortImg.style.left = Number(pos[0] + wdth - 13) + "px";// Number(pos[0]+5)+"px";
- this.sortImg.defLeft = parseInt(this.sortImg.style.left)
- this.sortImg.style.top = Number(pos[1] + 5) + "px";
- if ((!this.useImagesInHeader) && (!mode))
- this.sortImg.style.display = "inline";
- this.sortImg.style.left = this.sortImg.defLeft + "px";// -parseInt(this.hdrBox.scrollLeft)
- }
- }
- /**
- * @desc: manage activity of the grid.
- * @param: fl - true to activate,false to deactivate
- * @type: private
- * @topic: 1,7
- */
- this.setActive = function(fl) {
- if (arguments.length == 0)
- var fl = true;
- if (fl == true) {
- // document.body.onkeydown = new
- // Function("","document.getElementById('"+this.entBox.id+"').grid.doKey()")//
- globalActiveDHTMLGridObject = this;
- this.isActive = true;
- } else {
- this.isActive = false;
- }
- };
- /**
- * @desc: called on click occured
- * @type: private
- */
- this._doClick = function(ev) {
- var selMethod = 0;
- var el = this.getFirstParentOfType(_isIE ? ev.srcElement : ev.target,
- "TD");
- var fl = true;
- if (this.selMultiRows != false) {
- if (ev.shiftKey && this.row != null) {
- selMethod = 1;
- }
- if (ev.ctrlKey) {
- selMethod = 2;
- }
- }
- this.doClick(el, fl, selMethod)
- };
- this._doContClick = function(ev) {
- var el = this.getFirstParentOfType(_isIE ? ev.srcElement : ev.target,
- "TD");
- if ((!el) || (el.parentNode.idd === undefined))
- return true;
- if ((ev.button == 2) && (this._ctmndx)) {
- if ((this._onBCM)
- && (!this._onBCM(el.parentNode.idd, el._cellIndex, this)))
- return true;
- el.contextMenuId = el.parentNode.idd + "_" + el._cellIndex;
- el.contextMenu = this._ctmndx;
- el.a = this._ctmndx._contextStart;
- if (_isIE)
- ev.srcElement.oncontextmenu = function() {
- event.cancelBubble = true;
- return false;
- };
- el.a(el, ev);
- el.a = null;
- }
- return true;
- }
- /**
- * @desc: occures on cell click (supports treegrid)
- * @param: [el] - cell to click on
- * @param: [fl] - true if to call onRowSelect function
- * @param: [selMethod] - 0 - simple click, 1 - shift, 2 - ctrl
- * @type: private
- * @topic: 1,2,4,9
- */
- this.doClick = function(el, fl, selMethod) {
- this.setActive(true);
- if (!selMethod)
- selMethod = 0;
- if (this.cell != null)
- this.cell.className = this.cell.className.replace(/cellselected/g,
- "");
- if (el.tagName == "TD"
- && this.rowsCol._dhx_find(this.rowsAr[el.parentNode.idd]) != -1) {
- if (selMethod == 0) {
- this.clearSelection();
- } else if (selMethod == 1) {
- var elRowIndex = this.rowsCol._dhx_find(el.parentNode)
- var lcRowIndex = this.rowsCol._dhx_find(this.lastClicked)
- if (elRowIndex > lcRowIndex) {
- var strt = lcRowIndex;
- var end = elRowIndex;
- } else {
- var strt = elRowIndex;
- var end = lcRowIndex;
- }
- this.clearSelection();
- for (var i = 0; i < this.rowsCol.length; i++) {
- if (i >= strt && i <= end) {
- this.rowsCol[i].className += " rowselected";
- this.selectedRows[this.selectedRows.length] = this.rowsCol[i]
- }/*
- * else{ this.rowsCol[i].className = ""; }
- */
- }
- } else if (selMethod == 2) {
- if (el.parentNode.className.indexOf("rowselected") != -1) {
- el.parentNode.className = el.parentNode.className.replace(
- "rowselected", "");
- this.selectedRows._dhx_removeAt(this.selectedRows
- ._dhx_find(el.parentNode))
- var skipRowSelection = true;
- }
- }
- this.editStop()
- this.cell = el;
- if (this.row != el.parentNode) {// if new row selected
- this.row = el.parentNode;
- if (fl) {
- var rid = this.row.idd
- var func = this.onRowSelect
- setTimeout(function() {
- func(rid, false);
- }, 100)
- }
- }
- if (!skipRowSelection) {
- this.row.className += " rowselected"
- if (this.selectedRows._dhx_find(this.row) == -1)
- this.selectedRows[this.selectedRows.length] = this.row;
- }
- if (this.selBasedOn == "cell") {
- if (this.cell.parentNode.className.indexOf("rowselected") != -1)
- this.cell.className = this.cell.className.replace(
- /cellselected/g, "")
- + " cellselected";
- }
- if (selMethod != 1)
- this.lastClicked = el.parentNode;
- }
- this.isActive = true;
- this.moveToVisible(this.cell)
- }
- /**
- * @desc: set selection to specified row-cell
- * @param: r - row object or row index
- * @param: cInd - cell index
- * @param: [fl] - true if to call onRowSelect function
- * @param: preserve - preserve previously selected rows true/false (false by
- * default)
- * @param: edit - switch selected cell to edit mode
- * @type: public
- * @topic: 1,4
- */
- this.selectCell = function(r, cInd, fl, preserve, edit) {
- if (!fl)
- fl = false;
- if (typeof(r) != "object")
- r = this.rowsCol[r]
- var c = r.childNodes[cInd];
- if (preserve)
- this.doClick(c, fl, 3)
- else
- this.doClick(c, fl)
- if (edit)
- this.editCell();
- }
- /**
- * @desc: moves specified cell to visible area (scrolls)
- * @param: cell_obj - object of the cell to work with
- * @type: private
- * @topic: 2,4,7
- */
- this.moveToVisible = function(cell_obj) {
- try {
- var distance = cell_obj.offsetLeft + cell_obj.offsetWidth + 20;
- if (distance > (this.objBox.offsetWidth + this.objBox.scrollLeft)) {
- var scrollLeft = distance - this.objBox.offsetWidth;
- } else if (cell_obj.offsetLeft < this.objBox.scrollLeft) {
- var scrollLeft = cell_obj.offsetLeft - 5
- }
- if (scrollLeft)
- this.objBox.scrollLeft = scrollLeft;
- var distance = cell_obj.offsetTop + cell_obj.offsetHeight + 20;
- if (distance > (this.objBox.offsetHeight + this.objBox.scrollTop)) {
- var scrollTop = distance - this.objBox.offsetHeight;
- } else if (cell_obj.offsetTop < this.objBox.scrollTop) {
- var scrollTop = cell_obj.offsetTop - 5
- }
- if (scrollTop)
- this.objBox.scrollTop = scrollTop;
- } catch (er) {
- }
- }
- /**
- * @desc: creates Editor object and switch cell to edit mode if allowed
- * @type: public
- * @topic: 4
- */
- this.editCell = function() {
- this.editStop();
- if ((this.isEditable != true) || (!this.cell))
- return false;
- var c = this.cell;
- // #locked_row:11052006{
- if (c.parentNode._locked)
- return false;
- // #}
- c.className += " editable";
- eval("this.editor = new eXcell_" + this.cellType[this.cell._cellIndex]
- + "(c)");
- // initialize editor
- if (this.editor != null) {
- if (typeof(this.onEditCell) == "string") {
- if (eval(this.onEditCell + "(0,'" + this.row.idd + "',"
- + this.cell._cellIndex + ");") != false) {
- this.editor.edit()
- this._Opera_stop = (new Date).valueOf();
- eval(this.onEditCell + "(1,'" + this.row.idd + "',"
- + this.cell._cellIndex + ");")
- } else {// preserve editing
- this.editor = null;
- }
- } else {
- if (this.onEditCell(0, this.row.idd, this.cell._cellIndex) != false) {
- this._Opera_stop = (new Date).valueOf();
- this.editor.edit()
- this.onEditCell(1, this.row.idd, this.cell._cellIndex)
- } else {// preserve editing
- this.editor = null;
- }
- }
- }
- }
- /**
- * @desc: gets value from editor(if presents) to cell and closes editor
- * @type: public
- * @topic: 4
- */
- this.editStop = function() {
- if (_isOpera)
- if (this._Opera_stop) {
- if ((this._Opera_stop * 1 + 50) > (new Date).valueOf())
- return;
- this._Opera_stop = null;
- }
- if (this.editor && this.editor != null) {
- this.cell.className = this.cell.className.replace("editable", "");
- this.cell.wasChanged = this.editor.detach();
- this.editor = null;
- if (typeof(this.onEditCell) == "string")
- eval(this.onEditCell + "(2,'" + this.row.idd + "',"
- + this.cell._cellIndex + ");")
- else
- this.onEditCell(2, this.row.idd, this.cell._cellIndex);
- }
- }
- /**
- * @desc: manages keybord activity in grid
- * @type: private
- * @topic: 7
- */
- this.doKey = function(ev) {
- // alert("946 " + ev.keyCode + ev.ctrlKey)
- if (!ev)
- return true;
- if ((ev.target || ev.srcElement).value !== window.undefined) {
- var zx = (ev.target || ev.srcElement);
- if ((!zx.parentNode)
- || (zx.parentNode.className.indexOf("editable") == -1))
- return true;
- }
- if ((globalActiveDHTMLGridObject)
- && (this != globalActiveDHTMLGridObject))
- return globalActiveDHTMLGridObject.doKey(ev);
- if (this.isActive == false) {
- // document.body.onkeydown = "";
- return true;
- }
- if (this._htkebl)
- return true;
- try {
- var type = this.cellType[this.cell._cellIndex]
- // ENTER
- if (ev.keyCode == 13 && (ev.ctrlKey || ev.shiftKey)) {
- var rowInd = this.rowsCol._dhx_find(this.row)
- if (window.event.ctrlKey && rowInd != this.rowsCol.length - 1) {
- if (this.row.rowIndex == this.obj.rows.length - 1
- && this.dynScroll && this.dynScroll != 'false')
- this.doDynScroll("dn")
- this.selectCell(this.rowsCol[rowInd + 1],
- this.cell._cellIndex, true);
- } else if (ev.shiftKey && rowInd != 0) {
- if (this.row.rowIndex == 0 && this.dynScroll
- && this.dynScroll != 'false')
- this.doDynScroll("up")
- this.selectCell(this.rowsCol[rowInd - 1],
- this.cell._cellIndex, true);
- }
- _isIE ? ev.returnValue = false : ev.preventDefault();
- }
- if (ev.keyCode == 13 && !ev.ctrlKey && !ev.shiftKey) {
- this.editStop();
- if (typeof(this.onEnter) == "string")
- eval("window." + this.onEnter + "('" + this.row.idd + "',"
- + this.cell._cellIndex + ")")
- else
- this.onEnter(this.row.idd, this.cell._cellIndex);
- _isIE ? ev.returnValue = false : ev.preventDefault();
- }
- // TAB
- if (ev.keyCode == 9 && !ev.shiftKey) {
- this.editStop();
- var aind = this.cell._cellIndex + 1;
- var arow = this.row;
- if (aind == this.row.childNodes.length) {
- aind = 0;
- arow = this.rowsCol[this.rowsCol._dhx_find(this.row) + 1];
- if (!arow) {
- aind = this.row.childNodes.length - 1;
- return true;
- }
- }
- this.selectCell(arow || this.row, aind,
- ((arow) && (this.row != arow)));
- this.editCell()
- _isIE ? ev.returnValue = false : ev.preventDefault();
- } else if (ev.keyCode == 9 && ev.shiftKey) {
- this.editStop();
- var aind = this.cell._cellIndex - 1;
- var arow = this.row;
- if (aind < 0) {
- aind = this.row.childNodes.length - 1;
- arow = this.rowsCol[this.rowsCol._dhx_find(this.row) - 1];
- if (!arow) {
- aind = 0;
- return true;
- }
- }
- this.selectCell(arow || this.row, aind,
- ((arow) && (this.row != arow)));
- this.editCell()
- _isIE ? ev.returnValue = false : ev.preventDefault();
- }
- // UP & DOWN
- if (ev.keyCode == 40 || ev.keyCode == 38) {// && ev.ctrlKey
- if (this.editor && this.editor.combo) {
- if (ev.keyCode == 40)
- this.editor.shiftNext();
- if (ev.keyCode == 38)
- this.editor.shiftPrev();
- return false;
- } else {
- var rowInd = this.row.rowIndex;// rowsCol._dhx_find(this.row)
- if (ev.keyCode == 38 && rowInd != 0) {
- if (this.row.rowIndex == 0 && this.dynScroll
- && this.dynScroll != 'false')
- this.doDynScroll("up")
- this.selectCell(this.obj.rows[rowInd - 1],
- this.cell._cellIndex, true);
- } else if (ev.keyCode == 40
- && rowInd != this.rowsCol.length - 1) {
- if (this.row.rowIndex == this.obj.rows.length - 1
- && this.dynScroll && this.dynScroll != 'false')
- this.doDynScroll("dn")
- this.selectCell(this.obj.rows[rowInd + 1],
- this.cell._cellIndex, true);
- }
- }
- _isIE ? ev.returnValue = false : ev.preventDefault();
- }
- // F2
- if ((ev.keyCode == 113) && (this._f2kE)) {
- this.editCell();
- return false;
- }
- // SPACE
- if (ev.keyCode == 32) {// && (type=='ch'|| type.indexOf('ra')==0)){
- var c = this.cell
- eval("var ed = new eXcell_" + this.cellType[c._cellIndex]
- + "(c)");
- // this.cell.children(0).click()
- if (ed.changeState() != false)
- _isIE ? ev.returnValue = false : ev.preventDefault();
- }
- // Esc
- if (ev.keyCode == 27 && this.oe != false) {
- this.editStop();
- _isIE ? ev.returnValue = false : ev.preventDefault();
- }
- // PAGEUP / PAGEDOWN
- if (ev.keyCode == 33 || ev.keyCode == 34) {
- if (ev.keyCode == 33)
- this.doDynScroll("up")
- else
- this.doDynScroll("dn")
- _isIE ? ev.returnValue = false : ev.preventDefault();
- }
- // RIGHT LEFT
- if (!this.editor) {
- if (ev.keyCode == 37 && this.cellType._dhx_find("tree") != -1) {
- this.collapseKids(this.row)
- _isIE ? ev.returnValue = false : ev.preventDefault();
- }
- if (ev.keyCode == 39 && this.cellType._dhx_find("tree") != -1) {
- this.expandKids(this.row)
- _isIE ? ev.returnValue = false : ev.preventDefault();
- }
- }
- if (ev.keyCode == 67 && ev.ctrlKey) {
- // alert("Should copy data ....................")
- this.setCSVDelimiter("\t");
- this.copyBlockToClipboard();
- // ======================================================
- // if (!this.callEvent("onKeyPress", [ev.keyCode, ev.ctrlKey,
- // ev.shiftKey]))
- // return false;
- // ===========================================================
- }
- return true;
- } catch (er) {
- return true;
- }
- }
- /**
- * @desc: selects row (?)for comtatibility with previous version
- * @param: cell - cell object(or cell's child)
- * @invoke: click on cell(or cell content)
- * @type: private
- * @topic: 1,2
- */
- this.getRow = function(cell) {
- if (!cell)
- cell = window.event.srcElement;
- if (cell.tagName != 'TD')
- cell = cell.parentElement;
- r = cell.parentElement;
- if (this.cellType[cell._cellIndex] == 'lk')
- eval(this.onLink + "('" + this.getRowId(r.rowIndex) + "',"
- + cell._cellIndex + ")");
- this.selectCell(r, cell._cellIndex, true)
- }
- /**
- * @desc: selects row (and first cell of it)
- * @param: r - row index or row object
- * @param: fl - if true, then call function on select
- * @param: preserve - preserve previously selected rows true/false (false by
- * default)
- * @type: public
- * @topic: 1,2
- */
- this.selectRow = function(r, fl, preserve) {
- if (typeof(r) != 'object')
- r = this.rowsCol[r]
- this.selectCell(r, 0, fl, preserve)
- };
- /**
- * @desc: sorts specified column
- * @param: col - column index
- * @param: type - str.int.date
- * @param: order - asc.desc
- * @type: public
- * @topic: 2,3,5,9
- */
- this.sortRows = function(col, type, order) {
- // if tree cell exists
- if (this.cellType._dhx_find("tree") != -1) {
- return this.sortTreeRows(col, type, order)
- }
- var self = this;
- if (type == 'cus') {
- this.rowsCol.sort(function(a, b) {
- var cA = a.childNodes[col]
- var cB = b.childNodes[col]
- var type = a.grid.cellType[col];
- eval("var edA = new eXcell_" + type + "(cA)")
- eval("var edB = new eXcell_" + type + "(cB)")
- return self._customSorts[col](edA.getValue(), edB
- .getValue(), order);
- });
- } else if (type == 'str') {
- this.rowsCol.sort(function(a, b) {
- var cA = a.childNodes[col]
- var cB = b.childNodes[col]
- var type = a.grid.cellType[col];
- eval("var edA = new eXcell_" + type + "(cA)")
- eval("var edB = new eXcell_" + type + "(cB)")
- if (order == "asc")
- return edA.getValue() > edB.getValue() ? 1 : -1
- else
- return edA.getValue() < edB.getValue() ? 1 : -1
- });
- } else if (type == 'int') {
- this.rowsCol.sort(function(a, b) {
- var cA = a.childNodes[col]
- var cB = b.childNodes[col]
- var type = a.grid.cellType[col];
- eval("var edA = new eXcell_" + type + "(cA)")
- eval("var edB = new eXcell_" + type + "(cB)")
- var aVal = parseFloat(edA.getValue())
- || -99999999999999
- var bVal = parseFloat(edB.getValue())
- || -99999999999999
- if (order == "asc")
- return aVal - bVal
- else
- return bVal - aVal
- });
- } else if (type == 'date') {
- this.rowsCol.sort(function(a, b) {
- var cA = a.childNodes[col]
- var cB = b.childNodes[col]
- var type = a.grid.cellType[col];
- eval("var edA = new eXcell_" + type + "(cA)")
- eval("var edB = new eXcell_" + type + "(cB)")
- // -----------------------------------------------------need
- // to doing something........--------------------------
- var aVal = Date.parse(new Date(edA.getValue())
- || new Date("01/01/1900"))
- var bVal = Date.parse(new Date(edB.getValue())
- || new Date("01/01/1900"))
- if (order == "asc")
- return aVal - bVal
- else
- return bVal - aVal
- });
- }
- if (this.dynScroll && this.dynScroll != 'false') {
- alert("not implemented yet")
- } else {
- var tb = this.obj.firstChild;
- for (var i = 0; i < this.rowsCol.length; i++) {
- tb.insertBefore(this.rowsCol[i], tb.childNodes[i])
- // tb.moveRow(this.rowsCol[i].rowIndex,i)
- }
- }
- this.setSizes()
- if (this.onGridReconstructed)
- this.onGridReconstructed();
- }
- /**
- * @desc: enables the possibility to load content from server when already
- * loaded content was rendered. Using this you decrease the grid
- * loading time for extremely big amounts of data.
- * @type: public
- * @topic: 0,7
- */
- this.setXMLAutoLoading = function(filePath, bufferSize) {
- this.recordsNoMore = false;
- this.xmlFileUrl = filePath;
- this.rowsBufferOutSize = bufferSize || 40;
- }
- /**
- * @desc: enables buffering in content rendering. Using this you decrease
- * the grid loading time.
- * @type: public
- * @topic: 0,7
- */
- this.enableBuffering = function(bufferSize) {
- this.rowsBufferOutSize = bufferSize || 40;
- }
- /**
- * @desc: create rows from another part of buffer
- * @type: private
- * @topic: 0,2,7
- */
- this.addRowsFromBuffer = function() {
- if (this.rowsBuffer[0].length == 0) {
- if (!this.recordsNoMore) {
- if ((this.xmlFileUrl != "") && (!this._startXMLLoading)) {
- this._startXMLLoading = true;
- this.loadXML(this.xmlFileUrl)
- }
- } else
- return false;
- }
- var cnt = Math.min(this.rowsBufferOutSize, this.rowsBuffer[0].length)
- var tree = this.cellType._dhx_find("tree");
- // this.rowsBuffer.length
- for (var i = 0; i < cnt; i++) {
- var rowNode = this.rowsBuffer[1][0]
- var rId = rowNode.getAttribute("id")
- var pId = 0;
- var cellsCol = rowNode.childNodes;
- var strAr = new Array(0);
- var jj = 0;
- for (var j = 0; j < cellsCol.length; j++) {
- if (cellsCol[j].tagName == 'cell') {
- if (jj != tree)
- strAr[strAr.length] = cellsCol[j].firstChild
- ? cellsCol[j].firstChild.data
- : "";
- else
- strAr[strAr.length] = rowNode.parentNode
- .getAttribute("id")
- || 0
- + "^"
- + (cellsCol[j].firstChild
- ? cellsCol[j].firstChild.data
- : "")
- + "^"
- + (rowNode.getAttribute("xmlkids") ? "1" : "0")
- + "^"
- + (cellsCol[j].getAttribute("image") || "leaf.gif");
- jj++;
- }
- }
- var r = this._addRow(rId, strAr)
- // select row
- if (rowNode.getAttribute("selected") == true) {
- this.setSelectedRow(rId, false, false, rowNode
- .getAttribute("call") == true)
- }
- // expand
- if (rowNode.getAttribute("expand") == "1") {
- r.expand = "";
- }
- this.rowsBuffer[0]._dhx_removeAt(0);
- this.rowsBuffer[1]._dhx_removeAt(0);
- }
- return true;
- }
- /**
- * @desc: allow multiselection
- * @param: fl - false/true
- * @type: public
- * @before_init: 1
- * @topic: 0,2,7
- */
- this.setMultiselect = function(fl) {
- this.selMultiRows = fl;
- }
- /**
- * @desc: deletes row
- * @param: row_id - id of row to delete
- * @type: public
- * @topic: 2,9
- */
- this.deleteRow = function(row_id, node) {
- this.editStop();
- if (typeof(this.onBeforeRowDeleted) == "function"
- && this.onBeforeRowDeleted(row_id) == false)
- return false;
- if (!node)
- node = this.getRowById(row_id)
- if (node != null) {
- if (this.cellType._dhx_find("tree") != -1)
- this._removeTrGrRow(node);
- node.parentNode.removeChild(node);// nb:node.removeNode(true);
- var ind = this.rowsCol._dhx_find(node);
- this.rowsCol._dhx_removeAt(ind)
- node = null;
- }
- this.rowsAr[row_id] = null;
- if (this.onGridReconstructed)
- this.onGridReconstructed();
- this.setSizes();
- }
- /**
- * @desc: called when row was double clicked
- * @type: private
- * @topic: 1,2
- */
- this.wasDblClicked = function(ev) {
- var el = this.getFirstParentOfType(_isIE ? ev.srcElement : ev.target,
- "TR");
- if (el) {
- var rowId = el.idd;
- if (typeof(this.onRowDblClicked) == "function") {
- return this.onRowDblClicked(rowId)
- } else {
- return true;
- }
- }
- }
- /**
- * @desc: deletes selected row(s)
- * @type: public
- * @topic: 2
- */
- this.deleteSelectedItem = function() {
- var num = this.selectedRows.length// this.obj.rows.length
- if (num == 0)
- return;
- var tmpAr = this.selectedRows;
- this.selectedRows = new Array(0)
- for (var i = num - 1; i >= 0; i--) {
- var node = tmpAr[i]
- if (!this.deleteRow(node.idd, node)) {
- this.selectedRows[this.selectedRows.length] = node;
- } else {
- if (node == this.row) {
- var ind = i;
- }
- }
- /*
- * this.rowsAr[node.idd] = null; var posInCol =
- * this.rowsCol._dhx_find(node)
- * this.rowsCol[posInCol].parentNode.removeChild(this.rowsCol[posInCol]);//nb:this.rowsCol[posInCol].removeNode(true);
- * this.rowsCol._dhx_removeAt(posInCol)
- */
- }
- if (ind) {
- try {
- if (ind + 1 > this.rowsCol.length)// this.obj.rows.length)
- ind--;
- this.selectCell(ind, 0, true)
- } catch (er) {
- this.row = null
- this.cell = null
- }
- }
- }
- /**
- * @desc: gets selected row id
- * @returns: id of selected row (list of ids with default delimiter) or null
- * if non row selected
- * @type: public
- * @topic: 1,2,9
- */
- this.getSelectedId = function() {
- var selAr = new Array(0);
- for (var i = 0; i < this.selectedRows.length; i++) {
- selAr[selAr.length] = this.selectedRows[i].idd
- }
- // ..
- if (selAr.length == 0)
- return null;
- else
- return selAr.join(this.delim);
- }
- /**
- * @desc: gets index of selected cell
- * @returns: index of selected cell or -1 if there is no selected sell
- * @type: public
- * @topic: 1,4
- */
- this.getSelectedCellIndex = function() {
- if (this.cell != null)
- return this.cell._cellIndex;
- else
- return -1;
- }
- /**
- * @desc: gets width of specified column in pixels
- * @param: ind - column index
- * @returns: column width in pixels
- * @type: public
- * @topic: 3,7
- */
- this.getColWidth = function(ind) {
- return parseInt(this.cellWidthPX[ind]) + ((_isFF) ? 2 : 0);
- }
- /**
- * @desc: sets width of specified column in pixels (soen't works with
- * procent based grid)
- * @param: ind - column index
- * @param: value - new width value
- * @type: public
- * @topic: 3,7
- */
- this.setColWidth = function(ind, value) {
- this.cellWidthPX[ind] = parseInt(value);
- this.setSizes();
- }
- /**
- * @desc: gets row object by id
- * @param: id - row id
- * @returns: row object or null if there is no row with specified id
- * @type: private
- * @topic: 2,7,9
- */
- this.getRowById = function(id) {
- var row = this.rowsAr[id]
- if (row)
- return row;
- else
- return null;
- }
- /**
- * @desc: gets row index by id (grid only)
- * @param: row_id - row id
- * @returns: row index or -1 if there is no row with specified id
- * @type: public
- * @topic: 2
- */
- this.getRowIndex = function(row_id) {
- var ind = this.rowsCol._dhx_find(this.getRowById(row_id));
- if (ind != -1)
- return ind;
- else {
- ind = this.rowsBuffer[0]._dhx_find(row_id)
- if (ind != -1)
- return ind + this.rowsCol.length;
- return -1;
- }
- }
- /**
- * @desc: gets row id by index
- * @param: ind - row index
- * @returns: row id or null if there is no row with specified index
- * @type: public
- * @topic: 2
- */
- this.getRowId = function(ind) {
- try {
- return this.rowsCol[parseInt(ind)].idd;
- } catch (er) {
- return this.rowsBuffer[0][ind - this.rowsCol.length - 1]
- // return null;
- }
- }
- /**
- * @desc: sets new id for row by its index
- * @param: ind - row index
- * @param: row_id - new row id
- * @type: public
- * @topic: 2
- */
- this.setRowId = function(ind, row_id) {
- var r = this.rowsCol[ind]
- this.changeRowId(r.idd, row_id)
- }
- /**
- * @desc: changes id of the row to the new one
- * @param: oldRowId - row id to change
- * @param: newRowId - row id to set
- * @type:public
- * @topic: 2
- */
- this.changeRowId = function(oldRowId, newRowId) {
- var row = this.rowsAr[oldRowId]
- row.idd = newRowId;
- if (this.UserData[oldRowId]) {
- this.UserData[newRowId] = this.UserData[oldRowId]
- this.UserData[oldRowId] = null;
- }
- if (this.loadedKidsHash) {
- if (this.loadedKidsHash.get(oldRowId) != null) {
- this.loadedKidsHash.put(newRowId, this.loadedKidsHash
- .get(oldRowId));
- this.loadedKidsHash.remove(oldRowId);
- }
- var parentsHash = this.loadedKidsHash.get("hashOfParents")
- if (parentsHash != null) {
- if (parentsHash.get(oldRowId) != null) {
- parentsHash.put(newRowId, row);
- parentsHash.remove(oldRowId);
- this.loadedKidsHash.put("hashOfParents", parentsHash)
- }
- }
- }
- this.rowsAr[oldRowId] = null;
- this.rowsAr[newRowId] = row;
- }
- /**
- * @desc: sets ids to every column. Can be used then to retreive the index
- * of the desired colum
- * @param: [ids] - "," delimitered list of ids, or empty if to use values
- * set earlier
- * @type: public
- * @topic: 3
- */
- this.setColumnIds = function(ids) {
- if (ids)
- this.columnIds = ids.split(",")
- if (this.hdr.rows[0].cells.length >= this.columnIds.length) {
- for (var i = 0; i < this.columnIds.length; i++) {
- this.hdr.rows[0].cells[i].column_id = this.columnIds[i];
- }
- }
- }
- /**
- * @desc: gets column index by column id
- * @param: id - column id
- * @returns: index of the column
- * @type: public
- * @topic: 3
- */
- this.getColIndexById = function(id) {
- for (var i = 0; i < this.hdr.rows[0].cells.length; i++) {
- if (this.hdr.rows[0].cells[i].column_id == id)
- return i;
- }
- }
- /**
- * @desc: gets column id of column specified by index
- * @param: cin - column index
- * @returns: column id
- * @type: public
- * @topic: 3
- */
- this.getColumnId = function(cin) {
- return this.hdr.rows[0].cells[cin].column_id
- }
- /**
- * @desc: gets label of column specified by index
- * @param: cin - column index
- * @returns: column label
- * @type: public
- * @topic: 3
- */
- this.getHeaderCol = function(cin) {
- return this.hdr.rows[0].cells[Number(cin)].innerHTML;
- }
- /**
- * @desc: sets row text BOLD
- * @param: row_id - row id
- * @type: public
- * @topic: 2,6
- */
- this.setRowTextBold = function(row_id) {
- this.getRowById(row_id).style.fontWeight = "bold";
- }
- /**
- * @desc: sets style to row
- * @param: row_id - row id
- * @param: styleString - style string in common format (exmpl:
- * "color:red;border:1px solid gray;")
- * @type: public
- * @topic: 2,6
- */
- this.setRowTextStyle = function(row_id, styleString) {
- var r = this.getRowById(row_id)
- for (var i = 0; i < r.childNodes.length; i++) {
- var pfix = "";
- if ((this._hrrar) && (this._hrrar[i]))
- pfix = "display:none;";
- if (_isIE)
- r.childNodes[i].style.cssText = pfix + "width:"
- + r.childNodes[i].style.width + ";" + styleString;
- else
- r.childNodes[i].style.cssText = pfix + "width:"
- + r.childNodes[i].style.width + ";" + styleString;
- }
- }
- /**
- * @desc: sets style to cell
- * @param: row_id - row id
- * @param: ind - cell index
- * @param: styleString - style string in common format (exmpl:
- * "color:red;border:1px solid gray;")
- * @type: public
- * @topic: 2,6
- */
- this.setCellTextStyle = function(row_id, ind, styleString) {
- var r = this.getRowById(row_id)
- if (!r)
- return;
- if (ind < r.childNodes.length) {
- var pfix = "";
- if ((this._hrrar) && (this._hrrar[i]))
- pfix = "display:none;";
- if (_isIE)
- r.childNodes[ind].style.cssText = pfix + "width:"
- + r.childNodes[ind].style.width + ";" + styleString;
- else
- r.childNodes[ind].style.cssText = pfix + "width:"
- + r.childNodes[ind].style.width + ";" + styleString;
- }
- }
- /**
- * @desc: sets row text NORMAL
- * @param: row_id - row id
- * @type: public
- * @topic: 2,6
- */
- this.setRowTextNormal = function(row_id) {
- this.getRowById(row_id).style.fontWeight = "normal";
- }
- /**
- * @desc: determines if row with specified id exists
- * @param: row_id - row id
- * @returns: true if exists, false otherwise
- * @type: public
- * @topic: 2,7
- */
- this.isItemExists = function(row_id) {
- if (this.getRowById(row_id) != null)
- return true
- else
- return false
- }
- /**
- * @desc: gets a list of all row ids in grid
- * @param: separator - delimiter to use in list
- * @returns: list of all row ids in grid
- * @type: public
- * @topic: 2,7
- */
- this.getAllItemIds = function(separator) {
- var ar = new Array(0)
- for (i = 0; i < this.rowsCol.length; i++) {
- ar[ar.length] = this.rowsCol[i].idd
- }
- for (i = 0; i < this.rowsBuffer[0].length; i++) {
- ar[ar.length] = this.rowsBuffer[0][i]
- }
- return ar.join(separator || ",")
- }
- /**
- * @desc: gets number of rows in grid
- * @returns: number of rows in grid
- * @type: public
- * @topic: 2,7
- */
- this.getRowsNum = function() {
- return this.rowsCol.length + this.rowsBuffer[0].length;
- }
- /**
- * @desc: gets number of columns in grid
- * @returns: number of columns in grid
- * @type: public
- * @topic: 3,7
- */
- this.getColumnCount = function() {
- return this.hdr.rows[0].cells.length;
- }
- this.moveRowUp = function(row_id) {
- var r = this.getRowById(row_id)
- var rInd = this.rowsCol._dhx_find(r)
- if (this.isTreeGrid()) {
- if (this.rowsCol[rInd].parent_id != this.rowsCol[rInd - 1].parent_id)
- return;
- this.collapseKids(r);
- }
- this.rowsCol._dhx_swapItems(rInd, rInd - 1)
- if (r.previousSibling) {
- this.obj.firstChild.insertBefore(r, r.previousSibling)
- this.setSizes();
- }
- }
- /**
- * @desc: moves row one position down if possible
- * @param: row_id - row id
- * @type: public
- * @topic: 2
- */
- this.moveRowDown = function(row_id) {
- var r = this.getRowById(row_id)
- var rInd = this.rowsCol._dhx_find(r)
- if (this.isTreeGrid())
- if (this.rowsCol[rInd].parent_id != this.rowsCol[rInd + 1].parent_id)
- return;
- if (r.nextSibling) {
- if (r.nextSibling.nextSibling)
- this.obj.firstChild.insertBefore(r, r.nextSibling.nextSibling)
- else
- this.obj.firstChild.appendChild(r)
- this.setSizes();
- }
- }
- /**
- * @desc: gets dhtmlXGridCellObject object (if no arguments then gets
- * dhtmlXGridCellObject object of currently selected cell)
- * @param: row_id - row id
- * @param: col - column index
- * @returns: dhtmlXGridCellObject object (see its methods below)
- * @type: public
- * @topic: 4
- */
- this.cells = function(row_id, col) {
- if (arguments.length == 0) {
- var c = this.cell;
- return eval("new eXcell_" + this.cellType[this.cell._cellIndex]
- + "(c)");
- } else {
- var c = this.getRowById(row_id);
- if (!c)
- return null;
- return eval("new eXcell_" + this.cellType[col]
- + "(c.childNodes[col])");
- }
- }
- /**
- * @desc: gets dhtmlXGridCellObject object
- * @param: row_index - row index
- * @param: col - column index
- * @returns: dhtmlXGridCellObject object (see its methods below)
- * @type: public
- * @topic: 4
- */
- this.cells2 = function(row_index, col) {
- var c = this.rowsCol[parseInt(row_index)].cells[parseInt(col)];
- return eval("new eXcell_" + this.cellType[c._cellIndex] + "(c)");
- }
- this.cells3 = function(row, col) {
- var c = row.childNodes[col];
- return eval("new eXcell_" + this.cellType[c._cellIndex] + "(c)");
- }
- /**
- * @desc: gets Combo object of specified column
- * @type: public
- * @topic: 3,4
- * @param: col_ind - index of the column to get combo object for
- */
- this.getCombo = function(col_ind) {
- if (this.cellType[col_ind].indexOf('co') == 0) {
- if (!this.combos[col_ind]) {
- this.combos[col_ind] = new dhtmlXGridComboObject();
- }
- return this.combos[col_ind];
- } else {
- return null;
- }
- }
- /**
- * @desc: sets user Data
- * @param: row_id - row id. if empty then user data is for grid (not row)
- * @param: name - name of user data
- * @param: value - value of user data
- * @type: public
- * @topic: 2,5
- */
- this.setUserData = function(row_id, name, value) {
- try {
- if (row_id == "")
- row_id = "gridglobaluserdata";
- if (!this.UserData[row_id])
- this.UserData[row_id] = new Hashtable()
- this.UserData[row_id].put(name, value)
- } catch (er) {
- alert("UserData Error:" + er.description)
- }
- }
- /**
- * @desc: gets user Data
- * @param: row_id - row id. if empty then user data is for grid (not row)
- * @param: name - name of user data
- * @returns: value of user data
- * @type: public
- * @topic: 2,5
- */
- this.getUserData = function(row_id, name) {
- if (row_id == "")
- row_id = "gridglobaluserdata";
- var z = this.UserData[row_id];
- return (z ? z.get(name) : "");
- }
- /**
- * @desc: manage editibility of the grid
- * @param: [fl] - set not editable if FALSE, set editable otherwise
- * @type: public
- * @topic: 7
- */
- this.setEditable = function(fl) {
- if (fl != 'true' && fl != 1 && fl != true)
- ifl = true;
- else
- ifl = false;
- for (var j = 0; j < this.cellType.length; j++) {
- if (this.cellType[j].indexOf('ra') == 0 || this.cellType[j] == 'ch') {
- for (var i = 0; i < this.rowsCol.length; i++) {
- var z = this.rowsCol[i].cells[j];
- if ((z.childNodes.length > 0)
- && (z.firstChild.nodeType == 1)) {
- this.rowsCol[i].cells[j].firstChild.disabled = ifl;
- }
- }
- }
- }
- this.isEditable = !ifl;
- }
- /**
- * @desc: selects row
- * @param: row_id - row id
- * @param: multiFL - VOID. select multiple rows
- * @param: show - VOID. scroll row to view
- * @param: call - true to call function on select
- * @type: public
- * @topic: 1,2
- */
- this.setSelectedRow = function(row_id, multiFL, show, call) {
- if (!call)
- call = false;
- this.selectCell(this.getRowById(row_id), 0, call, multiFL);// selectRow(this.getRowById(row_id),false)
- if (arguments.length > 2 && show == true) {
- this.moveToVisible(this.getRowById(row_id).cells[0])
- }
- }
- /**
- * @desc: removes selection from the grid
- * @type: public
- * @topic: 1,9
- */
- this.clearSelection = function() {
- this.editStop()
- for (var i = 0; i < this.selectedRows.length; i++) {
- this.selectedRows[i].className = this.selectedRows[i].className
- .replace(/rowselected/g, "");
- }
- // ..
- this.selectedRows = new Array(0)
- this.row = null;
- if (this.cell != null) {
- this.cell.className = this.cell.className.replace(/cellselected/g,
- "");
- this.cell = null;
- }
- }
- /**
- * @desc: copies row content to another existing row
- * @param: from_row_id - id of the row to copy content from
- * @param: to_row_id - id of the row to copy content to
- * @type: public
- * @topic: 2,5
- */
- this.copyRowContent = function(from_row_id, to_row_id) {
- var frRow = this.getRowById(from_row_id)
- if (!this.isTreeGrid)
- for (i = 0; i < frRow.cells.length; i++) {
- this.cells(to_row_id, i).setValue(this.cells(from_row_id, i)
- .getValue())
- }
- else
- this._copyTreeGridRowContent(frRow, from_row_id, to_row_id);
- // for Mozilla (to avaoid visual glitches)
- if (!isIE())
- this.getRowById(from_row_id).cells[0].height = frRow.cells[0].offsetHeight
- }
- /**
- * @desc: sets new column header label
- * @param: col - header column index
- * @param: label - new label for the cpecified header's column
- * @type: public
- * @topic: 3,6
- */
- this.setHeaderCol = function(col, label) {
- if (!this.useImagesInHeader)
- this.hdr.rows[0].cells[col].innerHTML = label;
- else {// if images in header header
- this.hdr.rows[0].cells[col].style.textAlign = "left";
- this.hdr.rows[0].cells[col].innerHTML = "<img src='" + this.imgURL
- + "" + label + "' onerror='this.src = \"" + this.imgURL
- + "imageloaderror.gif\"'>";
- // preload sorting headers (asc/desc)
- var a = new Image();
- a.src = this.imgURL + "" + label.replace(/(\.[a-z]+)/, ".desc$1");
- this.preloadImagesAr[this.preloadImagesAr.length] = a;
- var b = new Image();
- b.src = this.imgURL + "" + label.replace(/(\.[a-z]+)/, ".asc$1");
- this.preloadImagesAr[this.preloadImagesAr.length] = b;
- }
- // this.hdr.rows[0].cells[Number(col)].innerHTML = label;
- }
- /**
- * @desc: deletes all rows in grid
- * @type: public
- * @topic: 5,7,9
- */
- this.clearAll = function() {
- this.editStop();
- // debugger;
- var len = this.rowsCol.length;
- for (var i = len - 1; i >= 0; i--) {
- this.obj.firstChild.removeChild(this.rowsCol[i])// nb:this.rowsCol[i].removeNode(true);
- this.rowsCol._dhx_removeAt(i);
- }
- // treegrid
- if (this.loadedKidsHash != null) {
- this.loadedKidsHash.clear();
- this.loadedKidsHash.put("hashOfParents", new Hashtable());
- }
- // for some case
- len = this.obj.rows.length
- for (var i = len - 1; i >= 0; i--) {
- this.obj.firstChild.removeChild(this.obj.rows[i])// nb:this.obj.rows[i].removeNode(true);
- }
- // ..
- this.row = null;
- this.cell = null;
- this.rowsAr = new Array(0)
- this.rowsCol = new Array(0)
- this.rowsAr = new Array(0);// array of rows by idd
- this.rowsBuffer = new Array(new Array(0), new Array(0));// buffer of
- // rows loaded,
- // but not
- // rendered
- // (array of
- // ids, array of
- // cell values
- // arrays)
- this.UserData = new Array(0)
- this.setSizes();
- // this.obj.scrollTop = 0;
- }
- this._sortField = function(ev) {
- var el = this.getFirstParentOfType(ev.target || ev.srcElement, "TD");
- this.sortField(el._cellIndex)
- }
- /**
- * @desc: sorts grid by specified field
- * @invoke: header click
- * @param: [ind] - index of the field
- * @param: [repeatFl] - if to repeat last sorting
- * @type: private
- * @topic: 3
- */
- this.sortField = function(ind, repeatFl) {
- if ((this.onCLMS) && (!this.onCLMS(ind, this)))
- return;
- if (this.getRowsNum() == 0)
- return false;
- var el = this.hdr.rows[0].cells[ind];
- if (!el)
- return; // somehow
- if (el.tagName == "TD" && (this.fldSort.length - 1) >= el._cellIndex
- && this.fldSort[el._cellIndex] != 'na') {// this.entBox.fieldstosort!=""
- // &&
- if ((((this.sortImg.src.indexOf("_desc.gif") == -1) && (!repeatFl)) || ((this.sortImg.style.filter != "") && (repeatFl)))
- && (this.fldSorted == el)) {// desc
- var sortType = "desc";
- this.sortImg.src = this.imgURL + "sort_desc.gif";
- } else {// asc
- var sortType = "asc";
- this.sortImg.src = this.imgURL + "sort_asc.gif";
- }
- // for header images
- if (this.useImagesInHeader) {
- if (this.fldSorted != null) {
- this.fldSorted.firstChild.src = this.fldSorted.firstChild.src
- .replace(/\.[ascde]+\./, ".");
- }
- el.firstChild.src = el.firstChild.src.replace(/(\.[a-z]+)/, "."
- + sortType + "$1")
- }
- // .
- this.sortRows(el._cellIndex, this.fldSort[el._cellIndex], sortType)
- this.fldSorted = el;
- this.setSortImgPos();
- }
- }
- /**
- * @desc: set custom sorting (custom sort has three params -
- * valueA,valueB,order; where order can be asc or des)
- * @param: func - column index
- * @param: col - str.int.date
- * @type: public
- * @edition: Professional
- * @topic: 3
- */
- this.setCustomSorting = function(func, col) {
- if (!this._customSorts)
- this._customSorts = new Array();
- this._customSorts[col] = func;
- this.fldSort[col] = "cus";
- }
- /**
- * @desc: specify if values passed to Header are images names
- * @param: fl - true to treat column header values as image names
- * @type: public
- * @before_init: 1
- * @topic: 0,3
- */
- this.enableHeaderImages = function(fl) {
- this.useImagesInHeader = fl;
- }
- /**
- * @desc: set header label and default params for new headers
- * @param: hdrStr - header string with delimiters
- * @type: public
- * @before_init: 1
- * @topic: 0,3
- */
- this.setHeader = function(hdrStr) {
- var arLab = hdrStr.split(this.delim);
- var arWdth = new Array(0);
- var arTyp = new Array(0);
- var arAlg = new Array(0);
- var arVAlg = new Array(0);
- var arSrt = new Array(0);
- for (var i = 0; i < arLab.length; i++) {
- arWdth[arWdth.length] = Math.round(100 / arLab.length);
- arTyp[arTyp.length] = "ed";
- arAlg[arAlg.length] = "left";
- arVAlg[arVAlg.length] = "top";
- arSrt[arSrt.length] = "na";
- }
- this.hdrLabels = arLab;
- this.cellWidth = arWdth;
- this.cellType = arTyp;
- this.cellAlign = arAlg;
- this.cellVAlign = arVAlg;
- this.fldSort = arSrt;
- }
- /**
- * @desc: set column types
- * @param: typeStr - type codes list with default delimiter
- * @before_init: 2
- * @type: public
- * @topic: 0,3,4
- */
- this.setColTypes = function(typeStr) {
- this.cellType = typeStr.split(this.delim)
- this._strangeParams = new Array();
- for (var i = 0; i < this.cellType.length; i++)
- if ((this.cellType[i].indexOf("[") != -1)) {
- var z = this.cellType[i].split(/[\[\]]+/g);
- this.cellType[i] = z[0];
- this.defVal[i] = z[1];
- if (z[1].indexOf("=") == 0) {
- this.cellType[i] = "math";
- this._strangeParams[i] = z[0];
- }
- }
- }
- /**
- * @desc: set column sort types (avaialble: str, int, date, na)
- * @param: sortStr - sort codes list with default delimiter
- * @before_init: 1
- * @type: public
- * @topic: 0,3,4
- */
- this.setColSorting = function(sortStr) {
- this.fldSort = sortStr.split(this.delim)
- for (var i = 0; i < this.fldSort.length; i++)
- if (((this.fldSort[i]).length > 4)
- && (typeof(window[this.fldSort[i]]) == "function")) {
- if (!this._customSorts)
- this._customSorts = new Array();
- this._customSorts[i] = window[this.fldSort[i]];
- this.fldSort[i] = "cus";
- }
- }
- /**
- * @desc: set align of columns
- * @param: alStr - align string with delimiters
- * @before_init: 1
- * @type: public
- * @topic: 0,3
- */
- this.setColAlign = function(alStr) {
- this.cellAlign = alStr.split(this.delim)
- }
- /**
- * @desc: set vertical align of columns
- * @param: alStr - align string with delimiters
- * @before_init: 1
- * @type: public
- * @topic: 0,3
- */
- this.setColVAlign = function(alStr) {
- this.cellVAlign = alStr.split(this.delim)
- }
- /**
- * @desc: sets grid to multiline row support (call before init)
- * @param: fl - true to set multiline support
- * @type: deprecated
- * @before_init: 1
- * @topic: 0,2
- */
- this.setMultiLine = function(fl) {
- if (fl == true)
- this.multiLine = -1;
- }
- /**
- * @desc: use to create grid with no header
- * @param: fl - true to use no header in the grid
- * @type: public
- * @before_init: 1
- * @topic: 0,7
- */
- this.setNoHeader = function(fl) {
- if (fl == true)
- this.noHeader = -1;
- }
- /**
- * @desc: scrolls row to the visible area
- * @param: rowID - row id
- * @type: public
- * @topic: 2,7
- */
- this.showRow = function(rowID) {
- this.moveToVisible(this.getRowById(rowID).cells[0])
- }
- /**
- * @desc: modify default style of grid and its elements. Call before or
- * after Init
- * @param: ss_header - style def. expression for header
- * @param: ss_grid - style def. expression for grid cells
- * @param: ss_selCell - style def. expression for selected cell
- * @param: ss_selRow - style def. expression for selected Row
- * @type: public
- * @before_init: 2
- * @topic: 0,6
- */
- this.setStyle = function(ss_header, ss_grid, ss_selCell, ss_selRow) {
- this.ssModifier = new Array(4)
- this.ssModifier[0] = ss_header;
- this.ssModifier[1] = ss_grid;
- this.ssModifier[2] = ss_selCell;
- this.ssModifier[3] = ss_selRow;
- this.styleSheet[0].addRule("#" + this.entBox.id + " table.hdr td",
- this.ssHeader + "" + this.ssModifier[0]);
- this.styleSheet[0].addRule("#" + this.entBox.id + " table.obj td",
- this.ssGridCell + "" + this.ssModifier[1]);
- this.styleSheet[0].addRule("#" + this.entBox.id
- + " table.obj tr.rowselected td.cellselected",
- this.ssSelectedCell + "" + this.ssModifier[2]);
- this.styleSheet[0].addRule("#" + this.entBox.id
- + " table.obj td.cellselected", this.ssSelectedCell
- + "" + this.ssModifier[2])
- this.styleSheet[0].addRule("#" + this.entBox.id
- + " table.obj tr.rowselected td", this.ssSelectedRow
- + "" + this.ssModifier[3]);
- }
- /**
- * @desc: colorize columns.
- * @param: clr - colors list
- * @type: public
- * @before_init: 1
- * @topic: 3,6
- */
- this.setColumnColor = function(clr) {
- this.columnColor = clr.split(this.delim)
- }
- /**
- * @desc: set even/odd css styles
- * @param: cssE - name of css class for even rows
- * @param: cssU - name of css class for odd rows
- * @type: public
- * @edition: Professional
- * @before_init: 1
- * @topic: 3,6
- */
- this.enableAlterCss = function(cssE, cssU) {
- if (cssE || cssU)
- this.setOnGridReconstructedHandler(function() {
- this._fixAlterCss();
- });
- this._cssEven = cssE;
- this._cssUnEven = cssU;
- }
- /**
- * @desc: recolor grid from defined point
- * @type: private
- * @before_init: 1
- * @topic: 3,6
- */
- this._fixAlterCss = function(ind) {
- ind = ind || 0;
- var j = ind;
- for (var i = ind; i < this.rowsCol.length; i++)
- if (this.rowsCol[i].style.display != "none") {
- if (this.rowsCol[i].className.indexOf("rowselected") != -1) {
- if (j % 2 == 1)
- this.rowsCol[i].className = this._cssUnEven
- + " rowselected";
- else
- this.rowsCol[i].className = this._cssEven
- + " rowselected";
- } else {
- if (j % 2 == 1)
- this.rowsCol[i].className = this._cssUnEven;
- else
- this.rowsCol[i].className = this._cssEven;
- }
- j++;
- }
- }
- /**
- * @desc: dynamicaly scrolls grid content.
- * @param: fl - if no fl initializes dynamic scroll, if up scroll page up,
- * if dn scrolls page down
- * @type: public
- * @topic: 0,6,7,9
- */
- this.doDynScroll = function(fl) {
- if (!this.dynScroll || this.dynScroll == 'false')
- return false;
- this.objBox.style.overflowY = "hidden";
- this.setDynScrollPageSize();
- var tmpAr = new Array(0)
- if (fl && fl == 'up') {
- this.dynScrollPos = Math.max(this.dynScrollPos
- - this.dynScrollPageSize, 0);
- } else if (fl
- && fl == 'dn'
- && this.dynScrollPos + this.dynScrollPageSize < this.rowsCol.length) {
- if (this.dynScrollPos + this.dynScrollPageSize
- + this.rowsBufferOutSize > this.rowsCol.length) {
- this.addRowsFromBuffer()
- }
- this.dynScrollPos += this.dynScrollPageSize
- }
- var start = Math.max(this.dynScrollPos - this.dynScrollPageSize, 0);
- for (var i = start; i < this.rowsCol.length; i++) {
- if (i >= this.dynScrollPos
- && i < this.dynScrollPos + this.dynScrollPageSize) {
- tmpAr[tmpAr.length] = this.rowsCol[i];
- }
- this.rowsCol[i].removeNode(true);
- }
- for (var i = 0; i < tmpAr.length; i++) {
- this.obj.childNodes[0].appendChild(tmpAr[i]);
- if (this.obj.offsetHeight > this.objBox.offsetHeight)
- this.dynScrollPos -= (this.dynScrollPageSize - i)
- }
- this.setSizes()
- }
- /**
- * @desc: counts the number of rows to fit the grid for dyn scroll
- * @type: private
- * @topic: 0
- */
- this.setDynScrollPageSize = function() {
- if (this.dynScroll && this.dynScroll != 'false') {
- var rowsH = 0;
- try {
- var rowH = this.obj.rows[0].scrollHeight;
- } catch (er) {
- var rowH = 20
- }
- for (var i = 0; i < 1000; i++) {
- rowsH = i * rowH;
- if (this.objBox.offsetHeight < rowsH)
- break
- }
- this.dynScrollPageSize = i + 2;// parseInt(i/3.5);
- this.rowsBufferOutSize = this.dynScrollPageSize * 4
- }
- }
- /*
- * @BLOCKSTART: SERIALIZATION
- */
- this._sUDa = false;
- this._sAll = false;
- /**
- * @desc: configure XML serialization
- * @type: public
- * @edition: Professional
- * @param: userData - enable/disable user data serialization
- * @param: fullXML - enable/disable full XML serialization (selection state)
- * @param: config - serialize grid configuration
- * @topic: 0,5,7
- */
- this.setSerializationLevel = function(userData, fullXML, config) {
- this._sUDa = userData;
- this._sAll = fullXML;
- this._sConfig = config;
- }
- /**
- * @desc: configure which column must be serialized
- * @type: public
- * @edition: Professional
- * @param: list - list of true/false values separated by comma, if list
- * empty then all fields will be serialized
- * @topic: 0,5,7
- */
- this.setSerializableColumns = function(list) {
- if (!list) {
- this._srClmn = null;
- return;
- }
- this._srClmn = (list || "").split(",");
- for (var i = 0; i < this._srClmn.length; i++)
- this._srClmn[i] = convertStringToBoolean(this._srClmn[i]);
- }
- this._serialise = function(rCol, inner, closed) {
- this.editStop()
- var out = "";
- // rows collection
- var i = 0;
- var j = 0;
- for (i; i < rCol.length; i++) {
- var r = rCol[i];
- var selStr = "";
- // serialize selection
- if (this._sAll && this.selectedRows._dhx_find(r) != -1)
- selStr = " selected='1'";
- out += "<row id='" + r.idd + "'" + selStr + " "
- + ((r.expand == "") ? "open='1'" : "") + ">";
- // userdata
- if (this._sUDa && this.UserData[r.idd]) {
- keysAr = this.UserData[r.idd].getKeys()
- for (var ii = 0; ii < keysAr.length; ii++) {
- out += "<userdata name='" + keysAr[ii] + "'>"
- + this.UserData[r.idd].get(keysAr[ii])
- + "</userdata>";
- }
- }
- // cells
- for (var jj = 0; jj < r.childNodes.length; jj++) {
- if ((!this._srClmn) || (this._srClmn[jj])) {
- var zx = this.cells(r.idd, jj)[this._agetm]();
- if (this._sAll)
- out += "<cell"
- + (r.childNodes[jj]._aimage ? (" image='"
- + r.childNodes[jj]._aimage + "'") : "")
- + ">" + ((zx === null) ? "" : zx) + "</cell>";
- else
- out += "<cell>" + ((zx === null) ? "" : zx) + "</cell>";
- }
- }
- if (this.loadedKidsHash) {
- var z = this.loadedKidsHash.get(r.idd);
- if (z) {
- temp = this._serialise(z, 1, closed || r.expand !== "");
- out += temp[0];
- if ((!closed) && (r.expand === ""))
- if (!inner)
- i += temp[1];
- else
- j += temp[1];
- }
- }
- out += "</row>";
- }
- return [out, j + i];
- }
- this._serialiseConfig = function() {
- var out = "<head>";
- for (var i = 0; i < this.hdr.rows[0].cells.length; i++) {
- out += "<colum width='" + this.cellWidthPX[i] + "' align='"
- + this.cellAlign[i] + "' type='" + this.cellType[i]
- + "' sort='" + this.fldSort[i] + "' color='"
- + this.columnColor[i] + "'>";
- out += this.hdr.rows[0].cells[i].innerHTML;
- var z = this.getCombo(i);
- if (z)
- for (var j = 0; j < z.keys.length; j++)
- out += "<option value='" + z.keys[j] + "'>" + z.values[j]
- + "<option>";
- out += "</column>"
- }
- return out += "</head>";
- }
- /**
- * @desc: return actual xml of grid
- * @type: public
- * @edition: Professional
- * @topic: 5,7
- */
- this.serialize = function() {
- var out = '<?xml version="1.0"?><rows>';
- if (this._mathSerialization)
- this._agetm = "getMathValue";
- else
- this._agetm = "getValue";
- if (this._sUDa && this.UserData["gridglobaluserdata"]) {
- var keysAr = this.UserData["gridglobaluserdata"].getKeys()
- for (var i = 0; i < keysAr.length; i++) {
- out += "<userdata name='" + keysAr[i] + "'>"
- + this.UserData["gridglobaluserdata"].get(keysAr[i])
- + "</userdata>";
- }
- }
- if (this._sConfig)
- out += this._serialiseConfig();
- out += this._serialise(this.rowsCol)[0];
- // rows buffer
- var xmlSerializer;
- if (!isIE()) {
- xmlSerializer = new XMLSerializer();
- }
- for (var i = 0; i < this.rowsBuffer[1].length; i++) {
- if (!xmlSerializer)// ie
- out += this.rowsBuffer[1][i].xml;
- else {// mozilla
- out += xmlSerializer.serializeToString(this.rowsBuffer[1][i]);
- }
- }
- out += '</rows>';
- return out;
- }
- /*
- * ================================================================================
- * @BLOCKEND
- */
- this.dhx_attachEvent = function(original, catcher) {
- // alert("2379 original = " + original)
- if ((!this[original]) || (!this[original].dhx_addEvent)) {
- var z = new this.dhx_eventCatcher();
- z.dhx_addEvent(this[original]);
- this[original] = z;
- }
- this[original].dhx_addEvent(catcher);
- }
- this.dhx_eventCatcher = function() {
- var dhx_catch = new Array();
- var z = function() {
- if (dhx_catch)
- var res = true;
- for (var i = 0; i < dhx_catch.length; i++)
- if (!dhx_catch[i].apply(this, arguments))
- res = false;
- return res;
- }
- z.dhx_addEvent = function(ev) {
- if (typeof(ev) != "function")
- ev = eval(ev);
- if (ev)
- dhx_catch[dhx_catch.length] = ev;
- }
- return z;
- }
- /* SET EVENT HANDLERS */
- /**
- * @desc: set function called when row selected
- * @param: func - event handling function (or its name)
- * @type: public
- * @topic: 10
- * @event: onRowSelect
- * @eventdesc: Event raised immideatly after row was clicked.
- * @eventparam: ID of clicked row
- */
- this.setOnRowSelectHandler = function(func) {
- this.dhx_attachEvent("onRowSelect", func);
- }
- /**
- * @desc: set function called when row added/deleted or grid reordered
- * @param: func - event handling function (or its name)
- * @type: public
- * @topic: 10
- * @event: OnGridReconstructed
- * @eventdesc: Event raised immideatly after row was clicked.
- * @eventparam: grid object
- */
- this.setOnGridReconstructedHandler = function(func) {
- this.dhx_attachEvent("onGridReconstructed", func);
- }
- /**
- * @desc: set function called on grid scrolling
- * @param: func - event handling function (or its name)
- * @type: public
- * @topic: 10
- * @event: onScroll
- * @eventdesc: Event raised immideatly after scrolling occured
- * @eventparam: scroll left
- * @eventparam: scroll top
- */
- this.setOnScrollHandler = function(func) {
- this.dhx_attachEvent("_onSCRL", func);
- }
- /**
- * @desc: set function called when cell editted
- * @param: func - event handling function (or its name)
- * @type: public
- * @topic: 10
- * @event: onEditCell
- * @eventdesc: Event raises 1-3 times depending on cell editibality.
- * @eventparam: stage of editting (0-before start[can be canceled if returns
- * false],1-editor opened,2-editor closed)
- * @eventparam: ID or row
- * @eventparam: index of cell
- */
- this.setOnEditCellHandler = function(func) {
- this.dhx_attachEvent("onEditCell", func);
- }
- /**
- * @desc: set function called when checkbox or radiobutton was clicked
- * @param: func - event handling function (or its name)
- * @type: public
- * @topic: 10
- * @event: onCheck
- * @eventdesc: Event raises after state was changed.
- * @eventparam: ID or row
- * @eventparam: index of cell
- * @eventparam: state of checkbox/radiobutton
- */
- this.setOnCheckHandler = function(func) {
- this.dhx_attachEvent("onCheckbox", func);
- }
- /**
- * @desc: set function called when user press Enter
- * @param: func - event handling function (or its name)
- * @type: public
- * @topic: 10
- * @event: onEnterPressed
- * @eventdesc: Event raised immideatly after Enter pressed.
- * @eventparam: ID or row
- * @eventparam: index of cell
- */
- this.setOnEnterPressedHandler = function(func) {
- this.dhx_attachEvent("onEnter", func);
- }
- /**
- * @desc: set function called before row removed from grid
- * @param: func - event handling function (or its name)
- * @type: public
- * @topic: 10
- * @event: onBeforeRowDeleted
- * @eventdesc: Event raised right before row deleted (if returns false,
- * deletion canceled)
- * @eventparam: ID or row
- */
- this.setOnBeforeRowDeletedHandler = function(func) {
- this.dhx_attachEvent("onBeforeRowDeleted", func);
- }
- /**
- * @desc: set function called after row added to grid
- * @param: func - event handling function (or its name)
- * @type: public
- * @topic: 10
- * @event: onRowAdded
- * @eventdesc: Event raised right after row was added to grid
- * @eventparam: ID or row
- */
- this.setOnRowAddedHandler = function(func) {
- this.dhx_attachEvent("onRowAdded", func);
- }
- /**
- * @desc: set function called when row was dbl clicked
- * @param: func - event handling function (or its name)
- * @type: public
- * @topic: 10
- * @edition: Professional
- * @event: onRowDblClicked
- * @eventdesc: Event raised right after row was double clicked, before cell
- * editor opened by dbl click. If retuns false, event canceled;
- * @eventparam: ID or row
- */
- this.setOnRowDblClickedHandler = function(func) {
- this.dhx_attachEvent("onRowDblClicked", func);
- }
- /* TOOLS METHODS */
- /**
- * @desc: creates XML object from what was returned from specified URL (if
- * possible)
- * @returns: MS XML object
- * @param: url - url of the xml formated page
- * @type: private
- * @topic: 8
- */
- /*
- * this.loadXML = function(url){ if(/\?/g.test(url)) var s = "&"; else var s =
- * "?"; var xmlDoc = new ActiveXObject("microsoft.XMLDOM"); xmlDoc.async =
- * false;
- * xmlDoc.load(url+""+s+"rowsLoaded="+this.getRowsNum()+"&"+Date.parse(new
- * Date())) return xmlDoc; }
- */
- /**
- * @desc: returns absolute left and top position of specified element
- * @returns: array of two values: absolute Left and absolute Top positions
- * @param: oNode - element to get position of
- * @type: private
- * @topic: 8
- */
- this.getPosition = function(oNode, pNode) {
- if (!pNode)
- var pNode = document.body
- var oCurrentNode = oNode;
- var iLeft = 0;
- var iTop = 0;
- while ((oCurrentNode) && (oCurrentNode != pNode)) {// .tagName!="BODY"){
- iLeft += oCurrentNode.offsetLeft;
- iTop += oCurrentNode.offsetTop;
- oCurrentNode = oCurrentNode.offsetParent;// isIE()?:oCurrentNode.parentNode;
- }
- if (((_isKHTML) || (_isOpera)) && (pNode == document.body)) {
- iLeft += document.body.offsetLeft;
- iTop += document.body.offsetTop;
- }
- return new Array(iLeft, iTop);
- }
- /**
- * @desc: gets nearest parent of specified type
- * @param: obj - input object
- * @param: tag - string. tag to find as parent
- * @returns: object. nearest paraent object (including spec. obj) of
- * specified type.
- * @type: private
- * @topic: 8
- */
- this.getFirstParentOfType = function(obj, tag) {
- while (obj.tagName != tag && obj.tagName != "BODY") {
- obj = obj.parentNode;
- }
- return obj;
- }
- /* METHODS deprecated */
- /**
- * @desc: deprecated. sets number of columns
- * @param: cnt - number of columns
- * @type: void
- * @topic: 3,7
- */
- this.setColumnCount = function(cnt) {
- alert('setColumnCount method deprecated')
- }
- /**
- * @desc: deprecated. repaint of the grid
- * @topic: 7
- * @type: void
- */
- this.showContent = function() {
- alert('showContent method deprecated')
- }
- /* INTERNAL EVENT HANDLERS */
- this.objBox.onscroll = new Function("", "this.grid._doOnScroll()")
- if (!_isOpera) {
- this.hdr.onmousemove = new Function("e",
- "this.grid.changeCursorState(e||window.event)");
- this.hdr.onmousedown = new Function("e",
- "this.grid.startColResize(e||window.event)");
- }
- this.obj.onmousemove = new Function(
- "e",
- "var c = this.grid.getFirstParentOfType(e?e.target:event.srcElement,'TD'); if((this.grid.editor)&&(this.grid.editor.cell==c)) return true; var r = c.parentNode; if ((this.grid._enbTts)&&(!this.grid._enbTts[c._cellIndex])) { (e?e.target:event.srcElement).title=''; return true; } var ced = this.grid.cells(r.idd,c._cellIndex); if (!ced) return true; if (!ced) return true;(e?e.target:event.srcElement).title = ced.getTitle?ced.getTitle():ced.getValue(); return true;");
- this.obj.onclick = new Function(
- "e",
- "this.grid._doClick(e||window.event); if (this.grid._sclE) this.grid.editCell(e||window.event) ");
- this.entBox.onmousedown = new Function("e",
- "return this.grid._doContClick(e||window.event);");
- this.obj.ondblclick = new Function(
- "e",
- "if(!this.grid.wasDblClicked(e||window.event)){return false}; if (this.grid._dclE) this.grid.editCell(e||window.event)");
- this.hdr.onclick = new Function("e",
- "if(this.grid.resized==null)this.grid._sortField(e||window.event);");
- // VOID this.grid.ondblclick = this.onDoubleClick;
- document.onkeydown = new Function(
- "e",
- "if (globalActiveDHTMLGridObject) return globalActiveDHTMLGridObject.doKey(e||window.event); return true;");
- // nb:document.body.attachEvent("onclick",new
- // Function("","if(this.document.getElementById('"+this.entBox.id+"').grid.isActive==-1)this.document.getElementById('"+this.entBox.id+"').grid.setActive(false)"))
- // activity management
- this.entBox.onbeforeactivate = new Function("", "this.grid.setActive()");
- this.entBox.onbeforedeactivate = new Function("", "this.grid.isActive=-1");
- // postprocessing events (method can be redeclared to react on some events
- // during processing)
- this.doOnRowAdded = function(row) {
- };
- // ========add by sunzhigang 2007 11 22==============================
- this._eSplit = function(str) {
- if (![].push)
- return str.split(this.delim);
- var a = "r" + (allGetServerTime()).valueOf();
- var z = this.delim.replace(/([ \|\+\*\^])/g, "\\$1")
- return (str || "").replace(RegExp(z, "g"), a).replace(
- RegExp("\\\\" + a, "g"), this.delim).split(a)
- };
- // =======================================
- }
- dhtmlXGridObject.prototype.isTreeGrid = function() {
- return (this.cellType._dhx_find("tree") != -1);
- }
- /**
- * @desc: adds row to the specified position
- * @param: new_id - id for new row
- * @param: text - Array of values or String(with delimiter as in delimiter
- * parameter)
- * @param: [ind] - index of row (0 by default)
- * @returns: new row dom object
- * @type: public
- * @topic: 2
- */
- dhtmlXGridObject.prototype.addRow = function(new_id, text, ind) {
- var r = this._addRow(new_id, text, ind);
- if (typeof(this.onRowAdded) == 'function') {
- this.onRowAdded(new_id);
- }
- this.setSizes();
- return r;
- }
- /**
- * @desc: adds row to the specified position
- * @param: new_id - id for new row
- * @param: text - Array of values or String(with delimiter as in delimiter
- * parameter)
- * @param: [ind] - index of row (0 by default)
- * @returns: new row dom object
- * @type: private
- * @topic: 2
- */
- dhtmlXGridObject.prototype._addRow = function(new_id, text, ind) {
- if (ind < 0)
- ind = this.obj.rows.length;
- this.math_off = true;
- this.math_req = false;
- if ((arguments.length < 3) || (ind === window.undefined))
- ind = this.rowsCol.length// getRowsNum();
- else {
- if (ind > this.rowsCol.length)
- ind = this.rowsCol.length;
- }
- if (typeof(text) != 'object')
- text = text.split(this.delim)
- if ((!this.dynScroll || this.dynScroll == 'false' || ind < this.obj.rows.length)
- && ((ind) || (ind == 0))) {
- if (_isKHTML)
- if (ind == this.obj.rows.length) {
- var r = document.createElement("TR");
- this.obj.appendChild(r);
- } else {
- var r = document.createElement("TR");
- this.obj.rows[ind].parentNode.insertBefore(r,
- this.obj.rows[ind]);
- }
- else if (ind == this.obj.rows.length)
- var r = this.obj.insertRow(ind);
- else
- var r = this.obj.insertRow(ind);
- }
- if (this.multiLine != true)
- this.obj.className += " row20px";
- r.idd = new_id;
- r.grid = this;
- for (var i = 0; i < this.hdr.rows[0].cells.length; i++) {
- var c = r.insertCell(i)
- // #cell_id:11052006{
- if (this._enbCid)
- c.id = "c_" + r.idd + "_" + i;
- // #}
- c._cellIndex = i;
- if (this.dragAndDropOff)
- this.dragger.addDraggableItem(c, this);
- c.align = this.cellAlign[i];
- c.style.verticalAlign = this.cellVAlign[i];
- // add color to column
- c.bgColor = this.columnColor[i] || ""
- this.editStop();
- if ((i < text.length) || (this.defVal[i])) {
- var val = text[i]
- if ((this.defVal[i]) && ((val == "") || (val === window.undefined)))
- val = this.defVal[i];
- eval("this.editor = new eXcell_" + this.cellType[i] + "(c)");
- this.editor.setValue(val)
- this.editor = this.editor.destructor();
- } else {
- var val = " ";
- c.innerHTML = val;
- c._clearCell = true;
- }
- }
- if (this._hrrar) {
- var zl = this.hdr.rows[0].cells.length;
- for (var i = 0; i < zl; i++)
- if (this._hrrar[i])
- r.childNodes[i].style.display = "none";
- }
- this.rowsAr[new_id] = r;
- this.rowsCol._dhx_insertAt(ind, r);
- if (this._cssEven) {
- if (ind % 2 == 1)
- r.className += " " + this._cssUnEven;
- else
- r.className += " " + this._cssEven;
- if (ind != (this.rowsCol.length - 1))
- this._fixAlterCss(ind + 1);
- }
- /*
- * else{ r.removeNode(true) }
- */
- // this.chngCellWidth(ind)
- this.doOnRowAdded(r);
- this.math_off = false;
- if ((this.math_req) && (!this._parsing_)) {
- for (var i = 0; i < this.hdr.rows[0].cells.length; i++)
- this._checkSCL(r.childNodes[i]);
- }
- return r;
- }
- /**
- * @desc: hide/show row (warning! - this command doesn't affect row indexes,
- * only visual appearance)
- * @param: ind - column index
- * @param: state - true/false - hide/show column
- * @type: public
- * @edition: Professional
- */
- dhtmlXGridObject.prototype.setRowHidden = function(id, state) {
- var f = convertStringToBoolean(state);
- var ind = this.getRowIndex(id);
- if (id < 0)
- return;
- var row = this.rowsCol[ind];
- if (row.expand === "")
- this.collapseKids(row);
- if ((state) && (row.style.display != "none")) {
- row.style.display = "none";
- var z = this.selectedRows._dhx_find(row);
- if (z != -1) {
- row.className = row.className.replace("rowselected", "");
- for (var i = 0; i < row.childNodes.length; i++)
- row.childNodes[i].className = row.childNodes[i].className
- .replace(/cellselected/g, "");
- this.selectedRows._dhx_removeAt(z);
- }
- if (this.onGridReconstructed)
- this.onGridReconstructed();
- }
- if ((!state) && (row.style.display == "none")) {
- row.style.display = "";
- if (this.onGridReconstructed)
- this.onGridReconstructed();
- }
- }
- /**
- * @desc: hide/show column
- * @param: ind - column index
- * @param: state - true/false - hide/show column
- * @type: public
- * @edition: Professional
- */
- dhtmlXGridObject.prototype.setColumnHidden = function(ind, state) {
- // ===========2007/11/26=============
- var anchors = document.getElementsByTagName("td");// ��ӵ�
- if ((this.fldSorted) && (this.fldSorted.cellIndex == ind) && (state))
- this.sortImg.style.display = "none";
- var f = convertStringToBoolean(state);
- if (f) {
- if (!this._hrrar)
- this._hrrar = new Array();
- else if (this._hrrar[ind])
- return;
- this._hrrar[ind] = "display:none;";
- this._hideShowColumn(ind, "none");
- // ================2007/11/26=====add by xiaoxiao while hide the
- // filtrate-div ..........
- for (var i = 0; i < anchors.length; i++) {// ��ӵ�
- anchor = anchors[i];
- if (anchor.getAttribute("_cellIndexS") == ind) {
- anchor.style.display = "none";
- anchor.childNodes[0].style.display = "none";
- // alert(anchor.childNodes[0]);
- return;
- }
- }
- } else {
- if ((!this._hrrar) || (!this._hrrar[ind]))
- return;
- this._hrrar[ind] = "";
- this._hideShowColumn(ind, "");
- // =============2007/11/26=======add by xiaoxiao while show the
- // filtrate-div ..........
- for (var i = 0; i < anchors.length; i++) {// ��ӵ�
- anchor = anchors[i];
- if (anchor.getAttribute("_cellIndexS") == ind) {
- anchor.style.display = "";
- anchor.childNodes[0].style.display = "";
- return;
- }
- }
- }
- if ((this.fldSorted) && (this.fldSorted.cellIndex == ind) && (!state))
- this.sortImg.style.display = "inline";
- }
- /**
- * @desc: get show/hidden status of column
- * @param: ind - column index
- * @type: public
- * @returns: if column hidden then true else false
- * @edition: Professional
- */
- dhtmlXGridObject.prototype.isColumnHidden = function(ind) {
- if ((this._hrrar) && (this._hrrar[ind]))
- return true;
- return false;
- }
- /**
- * @desc: set list of visible columns
- * @param: list - list of true/false separated by comma
- * @type: public
- * @edition: Professional
- * @topic:0
- */
- dhtmlXGridObject.prototype.setColHidden = function(list) {
- this._ivizcol = list.split(",");
- }
- /**
- * @desc: hide column
- * @param: ind - column index
- * @param: state - hide/show
- * @type: private
- * @edition: Professional
- */
- dhtmlXGridObject.prototype._hideShowColumn = function(ind, state) {
- if (state == "none") {
- this.hdr.rows[0].cells[ind]._oldWidth = this.hdr.rows[0].cells[ind].style.width;
- this.hdr.rows[0].cells[ind]._oldWidthP = this.cellWidthPC[ind];
- if (this.obj.rows.length)
- this.obj.rows[0].cells[ind].style.width = "0px";
- this.hdr.rows[0].cells[ind].style.width = "0px";
- if (this.cellWidthPX[ind])
- this.cellWidthPX[ind] = 0;
- if (this.cellWidthPC[ind])
- this.cellWidthPC[ind] = 0;
- } else {
- if (this.hdr.rows[0].cells[ind]._oldWidth) {
- var zrow = this.hdr.rows[0].cells[ind];
- if (this.obj.rows.length)
- this.obj.rows[0].cells[ind].style.width = this.hdr.rows[0].cells[ind]._oldWidth;
- zrow.style.width = zrow._oldWidth;
- if (zrow._oldWidthP)
- this.cellWidthPC[ind] = zrow._oldWidthP;
- if (zrow._oldWidth)
- this.cellWidthPX[ind] = parseInt(zrow._oldWidth);
- }
- }
- this.setSizes();
- for (var i = 0; i < this.rowsCol.length; i++)
- this.rowsCol[i].childNodes[ind].style.display = state;
- this.hdr.rows[0].childNodes[ind].style.display = state;
- this.setSizes();
- }
- /**
- * @desc: enable/disable hovering row under mouse
- * @param: mode - true/false
- * @param: cssClass - css class for hovered row
- * @type: public
- * @edition: Professional
- */
- dhtmlXGridObject.prototype.enableRowsHover = function(mode, cssClass) {
- this._hvrCss = cssClass;
- if (convertStringToBoolean(mode)) {
- if (!this._elmnh) {
- this.obj._honmousemove = this.obj.onmousemove;
- this.obj.onmousemove = this._setRowHover;
- if (_isIE)
- this.obj.onmouseleave = this._unsetRowHover;
- else
- this.obj.onmouseout = this._unsetRowHover;
- this._elmnh = true;
- }
- } else {
- if (this._elmnh) {
- this.obj.onmousemove = this.obj._honmousemove;
- if (_isIE)
- this.obj.onmouseleave = null;
- else
- this.obj.onmouseout = null;
- this._elmnh = false;
- }
- }
- };
- /**
- * @desc: enable/disable events which fire excell editing, mutual exclusive with
- * enableLightMouseNavigation
- * @param: click - true/false - enable/disable editing by single click
- * @param: dblclick - true/false - enable/disable editing by double click
- * @param: f2Key - enable/disable editing by pressing F2 key
- * @type: public
- * @edition: Professional
- */
- dhtmlXGridObject.prototype.enableEditEvents = function(click, dblclick, f2Key) {
- this._sclE = convertStringToBoolean(click);
- this._dclE = convertStringToBoolean(dblclick);
- this._f2kE = convertStringToBoolean(f2Key);
- }
- /**
- * @desc: enable/disable light mouse navigation mode (row selection with mouse
- * over, editing with single click), mutual exclusive with
- * enableEditEvents
- * @param: mode - true/false
- * @type: public
- * @edition: Professional
- */
- dhtmlXGridObject.prototype.enableLightMouseNavigation = function(mode) {
- if (convertStringToBoolean(mode)) {
- if (!this._elmn) {
- this.entBox._onclick = this.entBox.onclick;
- this.entBox.onclick = function() {
- return true;
- };
- this.obj.onclick = function(e) {
- this.grid.editStop();
- var c = this.grid.getFirstParentOfType(e
- ? e.target
- : event.srcElement, 'TD');
- this.grid.doClick(c);
- this.ondblclick(e);
- }
- this.obj._onmousemove = this.obj.onmousemove;
- this.obj.onmousemove = this._autoMoveSelect;
- this._elmn = true;
- }
- } else {
- if (this._elmn) {
- this.entBox.onclick = this.entBox._onclick;
- this.obj.onclick = function() {
- return true
- };
- this.obj.onmousemove = this.obj._onmousemove;
- this._elmn = false;
- }
- }
- }
- dhtmlXGridObject.prototype._unsetRowHover = function(e, c) {
- if (c)
- that = this;
- else
- that = this.grid;
- if ((that._lahRw) && (that._lahRw != c)) {
- for (var i = 0; i < that._lahRw.childNodes.length; i++)
- that._lahRw.childNodes[i].className = that._lahRw.childNodes[i].className
- .replace(that._hvrCss, "");
- that._lahRw = null;
- }
- }
- dhtmlXGridObject.prototype._setRowHover = function(e) {
- var c = this.grid.getFirstParentOfType(e ? e.target : event.srcElement,
- 'TD');
- if (c) {
- this.grid._unsetRowHover(0, c);
- c = c.parentNode;
- for (var i = 0; i < c.childNodes.length; i++)
- c.childNodes[i].className += " " + this.grid._hvrCss;
- this.grid._lahRw = c;
- }
- this._honmousemove(e);
- }
- dhtmlXGridObject.prototype._autoMoveSelect = function(e) {
- // this - grid.obj
- if (!this.grid.editor) {
- var c = this.grid.getFirstParentOfType(e ? e.target : event.srcElement,
- 'TD');
- this.grid.doClick(c, true, 0);
- }
- this._onmousemove(e);
- }
- /**
- * @desc: enable/disable light mouse navigation mode
- * @param: mode - true/false
- * @param: count - count of nodes parsed by one step (the 10 by default)
- * @param: time - time between parsing counts in milli seconds (the 250 by
- * default)
- * @type: public
- * @edition: Professional
- */
- dhtmlXGridObject.prototype.enableDistributedParsing = function(mode, count,
- time) {
- count = count || 10;
- time = time || 250;
- if (convertStringToBoolean(mode)) {
- this._ads_count = count;
- this._ads_time = time;
- } else
- this._ads_count = 0;
- }
- function _contextCall(obj, name, rowsCol, startIndex, tree, pId, i, n) {
- window.setTimeout(function() {
- obj[name](rowsCol, startIndex, tree, pId, i);
- }, n);
- return this;
- }
- /**
- * @desc: destructor, cleans used memory
- * @type: public
- * @topic: 0
- */
- dhtmlXGridObject.prototype.destructor = function() {
- var a;
- this.xmlLoader = this.xmlLoader.destructor();
- for (var i = 0; i < this.rowsCol.length; i++)
- this.rowsCol[i].grid = null;
- for (var i = 0; i < this.rowsAr.length; i++)
- if (this.rowsAr[i])
- this.rowsAr[i].grid = null;
- this.rowsCol = new Array();
- this.rowsAr = new Array();
- this.entBox.innerHTML = "";
- this.entBox.onclick = function() {
- };
- this.entBox.onmousedown = function() {
- };
- this.entBox.onbeforeactivate = function() {
- };
- this.entBox.onbeforedeactivate = function() {
- };
- this.entBox.onbeforedeactivate = function() {
- };
- for (a in this)
- this[a] = null;
- if (this == globalActiveDHTMLGridObject)
- globalActiveDHTMLGridObject = null;
- return null;
- }
- /**
- * @desc: set function called after xml loading/parsing ended
- * @param: func - event handling function
- * @type: public
- * @edition: Professional
- * @topic: 0
- * @event: onXMLLoadingEnd
- * @eventdesc: event fired simultaneously with ending XML parsing, new items
- * already available in tree
- * @eventparam: grid object
- * @eventparam: count of nodes added
- */
- dhtmlXGridObject.prototype.setOnLoadingEnd = function(func) {
- this.dhx_attachEvent("onXLE", func);
- };
- /**
- * @desc: set function called before xml loading started
- * @param: func - event handling function
- * @type: public
- * @edition: Professional
- * @topic: 0
- * @event: onXMLLoadingStart
- * @eventdesc: event fired before request for new XML sent to server
- * @eventparam: grid object
- */
- dhtmlXGridObject.prototype.setOnLoadingStart = function(func) {
- this.dhx_attachEvent("onXLS", func);
- };
- /**
- * @desc: set function called after resizing finished
- * @param: func - event handling function
- * @type: public
- * @edition: Professional
- * @topic: 0
- * @event: OnResizeEnd
- * @eventdesc: event fired after resizing of column finished
- * @eventparam: grid object
- */
- dhtmlXGridObject.prototype.setOnResizeEnd = function(func) {
- this.dhx_attachEvent("onRSE", func);
- };
- /**
- * @desc: set function called on each resizing itteration
- * @param: func - event handling function
- * @type: public
- * @edition: Professional
- * @topic: 0
- * @event: OnResize
- * @eventdesc: event fired on each resize itteration
- * @eventparam: cell index
- * @eventparam: cell width
- * @eventparam: grid object
- * @eventreturns: if event returns false - the resizig denied
- */
- dhtmlXGridObject.prototype.setOnResize = function(func) {
- this.dhx_attachEvent("onRSI", func);
- };
- /**
- * @desc: set function called before sorting of data started, didn't occur while
- * calling grid.sortRows
- * @param: func - event handling function
- * @type: public
- * @edition: Professional
- * @topic: 10
- * @event: onBeforeSorting
- * @eventdesc: event called before sorting of data started
- * @eventparam: index of sorted column
- * @eventparam: grid object
- * @eventreturns: if event returns false - the sorting denied
- */
- dhtmlXGridObject.prototype.setOnColumnSort = function(func) {
- this.dhx_attachEvent("onCLMS", func);
- };
- // ====================================================================
- dhtmlXGridObject.prototype.setOnKeyPressed = function(func) {
- this.dhx_attachEvent("onKeyPress", func);
- };
- /**
- * @desc: get sorting state of grid
- * @type: public
- * @edition: Professional
- * @returns: array, first element is index of sortef column, second - direction
- * of sorting.
- * @topic: 0
- */
- dhtmlXGridObject.prototype.getSortingState = function() {
- var z = new Array();
- if (this.fldSorted) {
- z[0] = this.fldSorted._cellIndex;
- z[1] = (this.sortImg.src.indexOf("sort_desc.gif") != -1)
- ? "DES"
- : "ASC";
- }
- return z;
- };
- /**
- * @desc: enable autoheight of grid
- * @param: mode - true/false
- * @param: maxHeight - maximum height before scrolling appears (infinite by
- * default)
- * @type: public
- * @edition: Professional
- * @topic: 0
- */
- dhtmlXGridObject.prototype.enableAutoHeigth = function(mode, maxHeight) {
- this._ahgr = convertStringToBoolean(mode);
- this._ahgrM = maxHeight || null;
- };
- /**
- * @desc: enable/disable hot keys in grid
- * @param: mode - true/false
- * @type: public
- * @edition: Professional
- * @topic: 0
- */
- dhtmlXGridObject.prototype.enableKeyboardSupport = function(mode) {
- this._htkebl = !convertStringToBoolean(mode);
- };
- /**
- * @desc: enable/disable context menu
- * @param: menu object, if null - context menu will be disabled
- * @type: public
- * @edition: Professional
- * @topic: 0
- */
- dhtmlXGridObject.prototype.enableContextMenu = function(menu) {
- this._ctmndx = menu;
- };
- /**
- * @desc: set event handler, which will be called immideatly before showing
- * context menu
- * @param: func - user defined function
- * @type: public
- * @event: OnBeforeContextMenu
- * @eventdesc: Event raised immideatly before showing context menu
- * @eventparam: ID of clicked row
- * @eventparam: index of cell column
- * @eventparam: grid object
- * @eventreturns: if event returns false, then context menu is not shown
- * @edition: Professional
- * @topic: 0,10
- */
- dhtmlXGridObject.prototype.setOnBeforeContextMenu = function(func) {
- this.dhx_attachEvent("onBCM", func);
- };
- /**
- * @desc: set width of browser scrollbars, will be used for correct autoWidth
- * calculations (by default grid will use 16 for IE and 19 for FF)
- * @param: width - scrollbar width
- * @type: public
- * @edition: Professional
- * @topic: 0
- */
- dhtmlXGridObject.prototype.setScrollbarWidthCorrection = function(width) {
- this._scrFix = parseInt(width);
- };
- /**
- * @desc: enable/disable tooltips for specified colums
- * @param: list - list of true/false values, tooltips enabled for all columns by
- * default
- * @type: public
- * @edition: Professional
- * @topic: 0
- */
- dhtmlXGridObject.prototype.enableTooltips = function(list) {
- this._enbTts = list.split(",");
- for (var i = 0; i < this._enbTts.length; i++)
- this._enbTts[i] = convertStringToBoolean(this._enbTts[i]);
- };
- /**
- * @desc: enable/disable resizing for specified colums
- * @param: list - list of true/false values, resizing enabled for all columns by
- * default
- * @type: public
- * @edition: Professional
- * @topic: 0
- */
- dhtmlXGridObject.prototype.enableResizing = function(list) {
- this._drsclmn = list.split(",");
- for (var i = 0; i < this._drsclmn.length; i++)
- this._drsclmn[i] = convertStringToBoolean(this._drsclmn[i]);
- };
- // #cell_id:11052006{
- /**
- * @desc: enable/disable unique id for cells (�_RowId_colIndex)
- * @param: mode - true/false - enable/disable
- * @type: public
- * @edition: Professional
- * @topic: 0
- */
- dhtmlXGridObject.prototype.enableCellIds = function(mode) {
- this._enbCid = convertStringToBoolean(mode);
- };
- // #}
- // #locked_row:11052006{
- /**
- * @desc: lock/unlock row for editing
- * @param: rowId - id of row
- * @param: mode - true/false - lock/unlock
- * @type: public
- * @edition: Professional
- * @topic: 0
- */
- dhtmlXGridObject.prototype.lockRow = function(rowId, mode) {
- var z = this.getRowById(rowId);
- if (z) {
- z._locked = convertStringToBoolean(mode);
- if ((this.cell) && (this.cell.parentNode.idd == rowId))
- this.editStop();
- }
- };
- // #}
- dhtmlXGridObject.prototype._getRowArray = function(row) {
- var text = new Array();
- for (var ii = 0; ii < row.childNodes.length; ii++)
- text[ii] = this.cells3(row, ii).getValue();
- return text;
- }
- // #cell_mask:12052006{
- /**
- * @desc: set mask for formatting date
- * @param: mask - date mask, d,m,y will mean day,month,year; for example d/m/y -
- * 22/05/1985
- * @type: public
- * @edition: Professional
- * @topic: 0
- */
- dhtmlXGridObject.prototype.setDateFormat = function(mask) {
- this._dtmask = mask;
- }
- /**
- * @desc: set mask for formatting numeric data
- * @param: mask - numeric mask; for example 0,000.00 - 1,234.56
- * @param: cInd - column index
- * @type: public
- * @edition: Professional
- * @topic: 0
- */
- dhtmlXGridObject.prototype.setNumberFormat = function(mask, cInd, p_sep, d_sep) {
- var nmask = mask.replace(/[^0\,\.]*/g, "");
- var pfix = nmask.indexOf(".");
- if (pfix > -1)
- pfix = nmask.length - pfix - 1;
- var dfix = nmask.indexOf(",");
- if (dfix > -1)
- dfix = nmask.length - pfix - 2 - dfix;
- p_sep = p_sep || ".";
- d_sep = d_sep || ",";
- var pref = mask.split(nmask)[0];
- var postf = mask.split(nmask)[1];
- this._maskArr[cInd] = [pfix, dfix, pref, postf, p_sep, d_sep];
- }
- dhtmlXGridObject.prototype._aplNFb = function(data, ind) {
- var a = this._maskArr[ind];
- if (!a)
- return data;
- var ndata = parseFloat(data.toString().replace(/[^0-9]*/g, ""));
- if (data.toString().substr(0, 1) == "-")
- ndata = ndata * -1;
- if (a[0] > 0)
- ndata = ndata / Math.pow(10, a[0]);
- return ndata;
- }
- dhtmlXGridObject.prototype._aplNF = function(data, ind) {
- var a = this._maskArr[ind];
- if (!a)
- return data;
- var c = (parseFloat(data) < 0 ? "-" : "") + a[2];
- data = Math.abs(Math.round(parseFloat(data)
- * Math.pow(10, a[0] > 0 ? a[0] : 0))).toString();
- data = (data.length < a[0] ? Math.pow(10, a[0] + 1 - data.length)
- .toString().substr(1, a[0] + 1)
- + data.toString() : data).split("").reverse();
- data[a[0]] = (data[a[0]] || "0") + a[4];
- if (a[1] > 0)
- for (var j = (a[0] > 0 ? 0 : 1) + a[0] + a[1]; j < data.length; j += a[1])
- data[j] += a[5];
- return c + data.reverse().join("") + a[3];
- }
- // #}
- /**
- * @desc: populate grid with data from xml file (if passed parameter contains
- * '.') or island
- * @param: [xml] - xml island will be found by grid id (id_xml) if no file or
- * island id is specified. This also can be ready-to-use XML object
- * @param: [startIndex] - index of row in grid to start insertion from
- * @type: public
- * @topic: 2,5
- */
- dhtmlXGridObject.prototype.parseXML = function(xml, startIndex) {
- // debugger;
- this._xml_ready = true;
- var pid = null;
- var zpid = null;
- if (!xml)
- try {
- var xmlDoc = eval(this.entBox.id + "_xml").XMLDocument;
- } catch (er) {
- var xmlDoc = this.loadXML(this.xmlFileUrl)
- }
- else {
- if (typeof(xml) == "object") {
- var xmlDoc = xml;
- } else {
- if (xml.indexOf(".") != -1) {
- if (this.xmlFileUrl == "")
- this.xmlFileUrl = xml
- var xmlDoc = this.loadXML(xml)
- return;
- } else
- var xmlDoc = eval(xml).XMLDocument;
- }
- }
- // debugger;
- var rowsCol = this.xmlLoader.doXPath("//rows/row", xmlDoc);
- if (rowsCol.length == 0) {
- this.recordsNoMore = true;
- var pid = 0;
- } else {
- pid = (rowsCol[0].parentNode.getAttribute("parent") || "0");
- zpid = this.getRowById(pid);
- if (zpid)
- zpid._xml_await = false;
- else
- pid = 0;
- startIndex = this.getRowIndex(pid) + 1;
- }
- var ar = new Array();
- var idAr = new Array();
- // global(grid) user data
- var gudCol = this.xmlLoader.doXPath("//rows/userdata", xmlDoc);
- if (gudCol.length > 0) {
- this.UserData["gridglobaluserdata"] = new Hashtable();
- for (var j = 0; j < gudCol.length; j++) {
- this.UserData["gridglobaluserdata"].put(gudCol[j]
- .getAttribute("name"), gudCol[j].firstChild
- ? gudCol[j].firstChild.data
- : "");
- }
- }
- // head
- var hheadCol = this.xmlLoader.doXPath("//rows/head", xmlDoc);
- if (hheadCol.length) {
- var headCol = this.xmlLoader.doXPath("//rows/head/column", hheadCol[0]);
- var asettings = this.xmlLoader.doXPath("//rows/head/settings",
- hheadCol[0]);
- var awidthmet = "setInitWidths";
- if (asettings.length) {
- for (var s = 0; s < asettings.length; s++)
- switch (asettings[0].childNodes[s].tagName) {
- case "colwidth" :
- if (asettings[0].childNodes[s].firstChild
- && asettings[0].childNodes[s].firstChild.data == "%")
- awidthmet = "setInitWidthsP";
- break;
- }
- }
- if (headCol.length > 0) {
- var a_list = "";
- var b_list = "";
- var c_list = "";
- var d_list = "";
- var e_list = "";
- var f_list = "";
- for (var i = 0; i < headCol.length; i++) {
- a_list += headCol[i].getAttribute("width") + ",";
- b_list += headCol[i].getAttribute("type") + ",";
- c_list += headCol[i].getAttribute("align") + ",";
- d_list += headCol[i].getAttribute("sort") + ",";
- e_list += (headCol[i].getAttribute("color") != null
- ? headCol[i].getAttribute("color")
- : "")
- + ",";
- f_list += (headCol[i].firstChild
- ? headCol[i].firstChild.data
- : "")
- + ",";
- }
- this.setHeader(f_list.substr(0, f_list.length - 1));
- this[awidthmet](a_list.substr(0, a_list.length - 1));
- this.setColAlign(c_list.substr(0, c_list.length - 1));
- this.setColTypes(b_list.substr(0, b_list.length - 1));
- this.setColSorting(d_list.substr(0, d_list.length - 1));
- this.setColumnColor(e_list.substr(0, e_list.length - 1));
- for (var i = 0; i < headCol.length; i++) {
- if (this.cellType[i].indexOf('co') == 0) {
- var optCol = this.xmlLoader.doXPath("./option", headCol[i]);
- for (var j = 0; j < optCol.length; j++)
- this.getCombo(i).put(
- optCol[j].getAttribute("value"),
- optCol[j].firstChild
- ? optCol[j].firstChild.data
- : "");
- }
- }
- this.init();
- }
- }
- // rows
- var tree = this.cellType._dhx_find("tree");
- if (tree == -1)
- tree = this.cellType._dhx_find("3d");
- this._innerParse(rowsCol, startIndex, tree, pid);
- if (zpid)
- this.expandKids(zpid);
- if (this.dynScroll && this.dynScroll != 'false') {
- this.doDynScroll()
- }
- if (tree != -1) {
- var oCol = this.xmlLoader.doXPath("//row[@open]", xmlDoc);
- for (var i = 0; i < oCol.length; i++)
- this.openItem(oCol[i].getAttribute("id"));
- }
- this.setSizes();
- if (_isOpera) {
- this.obj.style.border = 1;
- this.obj.style.border = 0;
- }
- this._startXMLLoading = false;
- try {
- } catch (er) {
- dhtmlxError.throwError("ParseXML", "Error parsing XML - "
- + er.description, xml)
- return;
- }
- if (this.onXLE)
- this.onXLE(this, rowsCol.length);
- }
- dhtmlXGridObject.prototype._innerParse = function(rowsCol, startIndex, tree,
- pId, i) {
- i = i || 0;
- var imax = i + this._ads_count;
- var r = null;
- for (var i; i < rowsCol.length; i++) {
- if (this._ads_count && i == imax) {
- new _contextCall(this, "_innerParse", rowsCol, startIndex, tree,
- pId, i, this._ads_time);
- return;
- }
- if ((pId)
- || (i <= this.rowsBufferOutSize || this.rowsBufferOutSize == 0)) {
- var rId = rowsCol[i].getAttribute("id")
- var xstyle = rowsCol[i].getAttribute("style");
- // user data
- var udCol = this.xmlLoader.doXPath("./userdata", rowsCol[i]);
- if (udCol.length > 0) {
- this.UserData[rId] = new Hashtable();
- for (var j = 0; j < udCol.length; j++) {
- this.UserData[rId]
- .put(udCol[j].getAttribute("name"),
- udCol[j].firstChild
- ? udCol[j].firstChild.data
- : "");
- }
- }
- var cellsCol = this.xmlLoader.doXPath("./cell", rowsCol[i]);
- var strAr = new Array(0);
- for (var j = 0; j < cellsCol.length; j++) {
- if (j != tree)
- strAr[strAr.length] = cellsCol[j].firstChild
- ? cellsCol[j].firstChild.data
- : "";
- else
- strAr[strAr.length] = pId
- + "^"
- + (cellsCol[j].firstChild
- ? cellsCol[j].firstChild.data
- : "") + "^"
- + (rowsCol[i].getAttribute("xmlkids") ? "1" : "0")
- + "^"
- + (cellsCol[j].getAttribute("image") || "leaf.gif");
- }
- this._parsing_ = true;
- if (startIndex) {
- r = this._addRow(rId, strAr, startIndex)
- startIndex++;
- } else {
- r = this._addRow(rId, strAr)
- }
- // #td_tr_classes:06062006{
- var css1 = rowsCol[i].getAttribute("class");
- if (css1)
- r.className += " " + css1;
- for (var j = 0; j < cellsCol.length; j++) {
- css1 = cellsCol[j].getAttribute("class");
- if (css1)
- r.childNodes[j].className += " " + css1;
- }
- // #}
- // #locked_row:11052006{
- if (rowsCol[i].getAttribute("locked")) {
- r._locked = true;
- // r.style.color='#696969';
- }
- // #}
- this._parsing_ = false;
- // select row
- if (rowsCol[i].getAttribute("selected") == true) {
- this.setSelectedRow(rId, this.selMultiRows, false, rowsCol[i]
- .getAttribute("call") == true)
- }
- // expand row
- if (rowsCol[i].getAttribute("expand") == "1") {
- r.expand = "";
- }
- } else {
- var len = this.rowsBuffer[0].length
- this.rowsBuffer[1][len] = rowsCol[i]
- this.rowsBuffer[0][len] = rowsCol[i].getAttribute("id")
- // this.rowsBuffer[1][len] = ar[i]
- }
- if (tree != -1) {
- var rowsCol2 = this.xmlLoader.doXPath("./row", rowsCol[i]);
- if (rowsCol2.length != 0)
- startIndex = this._innerParse(rowsCol2, startIndex, tree, rId);
- }
- if (xstyle)
- this.setRowTextStyle(rId, xstyle);
- }
- if ((r) && (this._checkSCL))
- for (var i = 0; i < this.hdr.rows[0].cells.length; i++)
- this._checkSCL(r.childNodes[i]);
- return startIndex;
- }
- // ====add bu sunzhigang from grid 1.4
- // =======================================================
- dhtmlXGridObject.prototype.attachHeader = function(values, style, _type) {
- if (typeof(values) == "string")
- values = this._eSplit(values);
- if (typeof(style) == "string")
- style = style.split(this.delim);
- _type = _type || "_aHead";
- if (this.hdr.rows.length) {
- if (values)
- this._createHRow([values, style], this[(_type == "_aHead")
- ? "hdr"
- : "ftr"]);
- else if (this[_type])
- for (var i = 0; i < this[_type].length; i++)
- this.attachHeader.apply(this, this[_type][i])
- } else {
- if (!this[_type])
- this[_type] = new Array();
- this[_type][this[_type].length] = [values, style, _type]
- }
- };
- dhtmlXGridObject.prototype._createHRow = function(data, parent) {
- if (!parent) {
- this.entBox.style.position = "relative";
- var z = document.createElement("DIV");
- z.className = "c_ftr".substr(2);
- this.entBox.appendChild(z);
- var t = document.createElement("TABLE");
- t.cellPadding = t.cellSpacing = 0;
- if (!_isIE) {
- t.width = "100%";
- t.style.paddingRight = "20px"
- };
- t.style.tableLayout = "fixed";
- z.appendChild(t);
- t.appendChild(document.createElement("TBODY"));
- this.ftr = parent = t;
- var hdrRow = t.insertRow(0);
- var thl = ((this.hdrLabels.length <= 1)
- ? data[0].length
- : this.hdrLabels.length);
- for (var i = 0; i < thl; i++) {
- hdrRow.appendChild(document.createElement("TH"));
- hdrRow.childNodes[i]._cellIndex = i
- };
- if (_isIE)
- hdrRow.style.position = "absolute";
- else
- hdrRow.style.height = 'auto'
- };
- var st1 = data[1];
- var z = document.createElement("TR");
- parent.rows[0].parentNode.appendChild(z);
- for (var i = 0; i < data[0].length; i++) {
- if (data[0][i] == "#cspan") {
- var pz = z.cells[z.cells.length - 1];
- pz.colSpan = (pz.colSpan || 1) + 1;
- continue
- };
- if ((data[0][i] == "#rspan") && (parent.rows.length > 1)) {
- var pind = parent.rows.length - 2;
- var found = false;
- var pz = null;
- while (!found) {
- var pz = parent.rows[pind];
- for (var j = 0; j < pz.cells.length; j++)
- if (pz.cells[j]._cellIndex == i) {
- found = j + 1;
- break
- };
- pind--
- };
- pz = pz.cells[found - 1];
- pz.rowSpan = (pz.rowSpan || 1) + 1;
- continue
- };
- var w = document.createElement("TD");
- w._cellIndex = w._cellIndexS = i;
- if (this.forceDivInHeader)
- w.innerHTML = "<div class='hdrcell'>" + data[0][i] + "</div>";
- else
- w.innerHTML = data[0][i];
- var t;
- if (((t = (data[0][i] || "")).indexOf("#") == 0)
- && (this[t = "_in_header_" + t.substr(1)]))
- this[t]((this.forceDivInHeader ? w.firstChild : w), i);
- if (st1)
- w.style.cssText = st1[i];
- z.appendChild(w)
- };
- var self = parent;
- if (_isKHTML) {
- if (parent._kTimer)
- window.clearTimeout(parent._kTimer);
- parent._kTimer = window.setTimeout(function() {
- parent.rows[1].style.display = 'none';
- window.setTimeout(function() {
- parent.rows[1].style.display = ''
- }, 1)
- }, 500)
- }
- };
- // ============================================
|