00ea5cb8344ab7354acdcae02b2928adfc9037c5.svn-base 113 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054
  1. /*
  2. * Copyright Scand LLC http://www.scbr.com To use this component please contact
  3. * info@scbr.com to obtain license
  4. */
  5. /*
  6. * _TOPICS_ @0:initialization @1:selection control @2:rows control @3:colums
  7. * control @4:cells controll @5:data manipulation @6:appearence control
  8. * @7:overal control @8:tools @9:treegrid @10: event handlers
  9. */
  10. var globalActiveDHTMLGridObject;
  11. String.prototype._dhx_trim = function() {
  12. return this.replace(/ /g, " ").replace(/(^[ \t]*)|([ \t]*$)/g, "");
  13. }
  14. Array.prototype._dhx_find = function(pattern) {
  15. for (var i = 0; i < this.length; i++) {
  16. if (pattern == this[i])
  17. return i;
  18. }
  19. return -1;
  20. }
  21. Array.prototype._dhx_delAt = function(ind) {
  22. if (Number(ind) < 0 || this.length == 0)
  23. return false;
  24. for (var i = ind; i < this.length; i++) {
  25. this[i] = this[i + 1];
  26. }
  27. this.length--;
  28. }
  29. Array.prototype._dhx_insertAt = function(ind, value) {
  30. this[this.length] = null;
  31. for (var i = this.length - 1; i >= ind; i--) {
  32. this[i] = this[i - 1]
  33. }
  34. this[ind] = value
  35. }
  36. Array.prototype._dhx_removeAt = function(ind) {
  37. for (var i = ind; i < this.length; i++) {
  38. this[i] = this[i + 1]
  39. }
  40. this.length--;
  41. }
  42. /*
  43. * Array.prototype.moveTo = function(ind,ind2){
  44. * this._dhx_insertAt(ind,this[ind2]); this._dhx_delAt(ind2*1+1); } -
  45. */
  46. Array.prototype._dhx_swapItems = function(ind1, ind2) {
  47. var tmp = this[ind1];
  48. this[ind1] = this[ind2]
  49. this[ind2] = tmp;
  50. }
  51. /**
  52. * @desc: dhtmlxGrid constructor
  53. * @param: id - (optional) id of div element to base grid on
  54. * @returns: dhtmlxGrid object
  55. * @type: public
  56. */
  57. function dhtmlXGridObject(id) {
  58. if (id) {
  59. if (typeof(id) == 'object') {
  60. this.entBox = id
  61. this.entBox.id = "cgrid2_" + (allGetServerTime()).getTime();
  62. } else
  63. this.entBox = document.getElementById(id);
  64. } else {
  65. this.entBox = document.createElement("DIV");
  66. this.entBox.id = "cgrid2_" + (allGetServerTime()).getTime();
  67. }
  68. this._tttag = this._tttag || "rows";
  69. this._cttag = this._cttag || "cell";
  70. this._rttag = this._rttag || "row";
  71. var self = this;
  72. this.nm = this.entBox.nm || "grid";
  73. this.cell = null;
  74. this.row = null;
  75. this.editor = null;
  76. this._f2kE = true;
  77. this._dclE = true;
  78. this.combos = new Array(0);
  79. this.defVal = new Array(0);
  80. this.rowsAr = new Array(0);// array of rows by idd
  81. this.rowsCol = new Array(0);// array of rows by index
  82. this._maskArr = new Array(0);
  83. this.selectedRows = new Array(0);// selected rows array
  84. this.rowsBuffer = new Array(new Array(0), new Array(0));// buffer of rows
  85. // loaded, but not
  86. // rendered (array
  87. // of ids, array of
  88. // cell values
  89. // arrays)
  90. this.loadedKidsHash = null;// not null if there is tree cell in grid
  91. this.UserData = new Array(0)// array of rows (and for grid -
  92. // "gridglobaluserdata") user data elements
  93. /* MAIN OBJECTS */
  94. this.styleSheet = document.styleSheets;
  95. this.entBox.className = "gridbox";
  96. this.entBox.style.width = this.entBox.getAttribute("width")
  97. || (window.getComputedStyle ? window.getComputedStyle(this.entBox,
  98. null)["width"] : (this.entBox.currentStyle
  99. ? this.entBox.currentStyle["width"]
  100. : 0)) || "100%";
  101. this.entBox.style.height = this.entBox.getAttribute("height")
  102. || (window.getComputedStyle ? window.getComputedStyle(this.entBox,
  103. null)["height"] : (this.entBox.currentStyle
  104. ? this.entBox.currentStyle["height"]
  105. : 0)) || "100%";
  106. // cursor and text selection
  107. this.entBox.style.cursor = 'default';
  108. this.entBox.onselectstart = function() {
  109. return false
  110. };// avoid text select
  111. this.obj = document.createElement("TABLE");
  112. this.obj.cellSpacing = 0;
  113. this.obj.cellPadding = 0;
  114. this.obj.style.width = "100%";// nb:
  115. this.obj.style.tableLayout = "fixed";
  116. this.obj.className = "obj";
  117. this.hdr = document.createElement("TABLE");
  118. this.hdr.style.border = "1px solid gray"; // FF 1.0 fix
  119. this.hdr.cellSpacing = 0;
  120. this.hdr.cellPadding = 0;
  121. if (!_isOpera)
  122. this.hdr.style.tableLayout = "fixed";
  123. this.hdr.className = "hdr";
  124. this.hdr.width = "100%";
  125. this.xHdr = document.createElement("TABLE");
  126. this.xHdr.cellPadding = 0;
  127. this.xHdr.cellSpacing = 0;
  128. var r = this.xHdr.insertRow(0)
  129. var c = r.insertCell(0);
  130. r.insertCell(1).innerHTML = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
  131. c.appendChild(this.hdr)
  132. this.objBuf = document.createElement("DIV");
  133. this.objBuf.style.borderBottom = "1px solid white"
  134. this.objBuf.appendChild(this.obj);
  135. this.entCnt = document.createElement("TABLE");
  136. this.entCnt.insertRow(0).insertCell(0)
  137. this.entCnt.insertRow(1).insertCell(0);
  138. this.entCnt.cellPadding = 0;
  139. this.entCnt.cellSpacing = 0;
  140. this.entCnt.width = "100%";
  141. this.entCnt.height = "100%";
  142. this.entCnt.style.tableLayout = "fixed";
  143. this.objBox = document.createElement("DIV");
  144. this.objBox.style.width = "100%";
  145. this.objBox.style.height = this.entBox.style.height;
  146. this.objBox.style.overflow = "auto";
  147. this.objBox.style.position = "relative";
  148. this.objBox.appendChild(this.objBuf);
  149. this.objBox.className = "objbox";
  150. this.hdrBox = document.createElement("DIV");
  151. this.hdrBox.style.width = "100%"
  152. if ((_isOpera) || ((_isMacOS) && (_isFF)))
  153. this.hdrSizeA = 25;
  154. else
  155. this.hdrSizeA = 100;
  156. this.hdrBox.style.height = this.hdrSizeA + "px";
  157. if (((_isOpera) || ((_isMacOS) && (_isFF))))
  158. this.hdrBox.style.overflow = "hidden";
  159. else if (!_isKHTML)
  160. this.hdrBox.style.overflowX = "hidden";
  161. this.hdrBox.style.position = "relative";
  162. this.hdrBox.appendChild(this.xHdr);
  163. this.preloadImagesAr = new Array(0)
  164. this.sortImg = document.createElement("IMG")
  165. this.hdrBox.insertBefore(this.sortImg, this.xHdr)
  166. this.entCnt.rows[0].cells[0].vAlign = "top";
  167. this.entCnt.rows[0].cells[0].appendChild(this.hdrBox);
  168. this.entCnt.rows[1].cells[0].appendChild(this.objBox);
  169. this.entBox.appendChild(this.entCnt);
  170. // add links to current object
  171. this.entBox.grid = this;
  172. this.objBox.grid = this;
  173. this.hdrBox.grid = this;
  174. this.obj.grid = this;
  175. this.hdr.grid = this;
  176. /* PROPERTIES */
  177. this.cellWidthPX = new Array(0);// current width in pixels
  178. this.cellWidthPC = new Array(0);// width in % if cellWidthType set in pc
  179. this.cellWidthType = this.entBox.cellwidthtype || "px";// px or %
  180. this.delim = this.entBox.delimiter || ",";
  181. this.hdrLabels = (this.entBox.hdrlabels || "").split(",");
  182. this.columnIds = (this.entBox.columnids || "").split(",");
  183. this.columnColor = (this.entBox.columncolor || "").split(",");
  184. this.cellType = (this.entBox.cellstype || "").split(",");
  185. this.cellAlign = (this.entBox.cellsalign || "").split(",");
  186. this.initCellWidth = (this.entBox.cellswidth || "").split(",");
  187. this.fldSort = (this.entBox.fieldstosort || "").split(",")
  188. this.imgURL = this.entBox.imagesurl || "gridCfx/";
  189. this.isActive = false;// fl to indicate if grid is in work now
  190. this.isEditable = true;
  191. this.raNoState = this.entBox.ranostate || "N";
  192. this.chNoState = this.entBox.chnostate || "N";
  193. this.selBasedOn = (this.entBox.selbasedon || "cell").toLowerCase()
  194. this.selMultiRows = this.entBox.selmultirows || false;
  195. this.multiLine = this.entBox.multiline || false;
  196. this.noHeader = this.entBox.noheader || false;
  197. this.dynScroll = this.entBox.dynscroll || false;// add/remove rows from dom
  198. this.dynScrollPageSize = 0;// will be autodetected
  199. this.dynScrollPos = 0;// position of dynamic scroll
  200. this.xmlFileUrl = this.entBox.xmlfileurl || "";
  201. this.recordsNoMore = this.entBox.infinitloading || true;;// if true, then
  202. // it will not
  203. // attempt to
  204. // fill the
  205. // buffer from
  206. // server
  207. this.useImagesInHeader = false;// use images in header or not
  208. // this.dynScrollBuffer = 100;//number of rows in buffer
  209. this.rowsBufferOutSize = 0;// number of rows rendered at a moment
  210. /* EVENTS */
  211. if (this.entBox.oncheckbox)
  212. this.onCheckbox = eval(this.entBox.oncheckbox);// rId,state,cInd
  213. this.onEditCell = this.entBox.oneditcell || function() {
  214. return true;
  215. };// fl,rid,cInd
  216. this.onRowSelect = this.entBox.onrowselect || function() {
  217. return true;
  218. };// rId,false
  219. this.onEnter = this.entBox.onenter || function() {
  220. return true;
  221. };// rId,cin
  222. if (window.addEventListener)
  223. window.addEventListener("unload", function() {
  224. try {
  225. self.destructor();
  226. } catch (e) {
  227. }
  228. }, false);
  229. if (window.attachEvent)
  230. window.attachEvent("onunload", function() {
  231. try {
  232. self.destructor();
  233. } catch (e) {
  234. }
  235. });
  236. /* XML LOADER(S) */
  237. /**
  238. * @desc: loads xml content from specified url
  239. * @type: public
  240. * @topic: 0,5
  241. */
  242. this.loadXML = function(url) {
  243. if (url.indexOf("?") != -1)
  244. var s = "&";
  245. else
  246. var s = "?";
  247. if (this.onXLS)
  248. this.onXLS(this);
  249. this.xmlLoader.loadXML(url + "" + s + "rowsLoaded=" + this.getRowsNum()
  250. + "&lastid=" + this.getRowId(this.getRowsNum() - 1) + "&sn="
  251. + Date.parse(allGetServerTime()));
  252. }
  253. /**
  254. * @desc: loads xml content from specified string
  255. * @type: public
  256. * @topic: 0,5
  257. * @edition: Professional
  258. */
  259. this.loadXMLString = function(str) {
  260. if (this.onXLS)
  261. this.onXLS(this);
  262. this.xmlLoader.loadXMLString(str);
  263. }
  264. /**
  265. * @desc: puts xml to parser
  266. * @type: private
  267. * @topic: 0,5
  268. */
  269. this.doLoadDetails = function(obj) {
  270. var root = self.xmlLoader.getXMLTopNode(self._tttag)
  271. if (root.tagName != "DIV")
  272. if (!self.xmlLoader.xmlDoc.nodeName) {
  273. self.parseXML(self.xmlLoader.xmlDoc.responseXML)
  274. } else {
  275. self.parseXML(self.xmlLoader.xmlDoc)
  276. }
  277. }
  278. this.xmlLoader = new dtmlXMLLoaderObject(this.doLoadDetails, window);
  279. this.dragger = new dhtmlDragAndDropObject();
  280. /* METHODS. SERVICE */
  281. /**
  282. * @desc: on scroll grid inside actions
  283. * @type: private
  284. * @topic: 7
  285. */
  286. this._doOnScroll = function(e, mode) {
  287. if (this._onSCRL)
  288. this._onSCRL(this.objBox.scrollLeft, this.objBox.scrollTop);
  289. this.doOnScroll(e, mode);
  290. }
  291. this.doOnScroll = function(e, mode) {
  292. this.hdrBox.scrollLeft = this.objBox.scrollLeft;
  293. this.setSortImgPos(null, true);
  294. if (mode)
  295. return;
  296. if (this.objBox.scrollTop + this.hdrSizeA + this.objBox.offsetHeight > this.objBox.scrollHeight) {
  297. if (this._xml_ready && this.addRowsFromBuffer())
  298. this.objBox.scrollTop = this.objBox.scrollHeight
  299. - (this.hdrSizeA + 1 + this.objBox.offsetHeight)
  300. }
  301. }
  302. /**
  303. * @desc: attach this grid to some object in DOM
  304. * @param: obj - object to attach to
  305. * @type: public
  306. * @topic: 0,7
  307. */
  308. this.attachToObject = function(obj) {
  309. obj.appendChild(this.entBox)
  310. }
  311. /**
  312. * @desc: initialize grid
  313. * @param: fl - if to parse on page xml dataisland
  314. * @type: public
  315. * @topic: 0,7
  316. */
  317. this.init = function(fl) {
  318. // debugger;
  319. this.editStop()
  320. /* TEMPORARY STATES */
  321. this.lastClicked = null;// row clicked without shift key. used in
  322. // multiselect only
  323. this.resized = null;// hdr cell that is resized now
  324. this.fldSorted = null;// hdr cell last sorted
  325. this.gridWidth = 0;
  326. this.gridHeight = 0;
  327. // empty grid if it already was initialized
  328. this.cellWidthPX = new Array(0);
  329. this.cellWidthPC = new Array(0);
  330. if (this.hdr.rows.length > 0) {
  331. this.clearAll();
  332. this.hdr.rows[0].removeNode(true);// this.hdr.firstChild.removeChild(this.hdr.rows[0])
  333. }
  334. if (this.cellType._dhx_find("tree") != -1) {// create hashtable for
  335. // treegrid
  336. this.loadedKidsHash = new Hashtable();
  337. this.loadedKidsHash.put("hashOfParents", new Hashtable())
  338. }
  339. var hdrRow = this.hdr.insertRow(0);
  340. for (var i = 0; i < this.hdrLabels.length; i++) {
  341. hdrRow.insertCell(i);
  342. this.setHeaderCol(i, this.hdrLabels[i])
  343. /*
  344. * if(!this.useImagesInHeader) hdrRow.insertCell(i).innerHTML =
  345. * this.hdrLabels[i]; else{//if images in header header
  346. * hdrRow.insertCell(i).innerHTML = "<img
  347. * src='"+this.imgURL+""+this.hdrLabels[i]+"'>";
  348. * this.preloadImagesAr[this.preloadImagesAr.length] =
  349. * this.imgURL+""+this.hdrLabels[i].replace(/(\.[a-z]+)/,".desc$1")
  350. * this.preloadImagesAr[this.preloadImagesAr.length] =
  351. * this.imgURL+""+this.hdrLabels[i].replace(/(\.[a-z]+)/,".asc$1") }
  352. */
  353. hdrRow.cells[i]._cellIndex = i;
  354. }
  355. this.setColumnIds()
  356. if (this.multiLine == -1)
  357. this.multiLine = true;
  358. //
  359. // this.combos = new Array(this.hdrLabels.length);
  360. // set sort image to initial state
  361. this.sortImg.style.position = "absolute";
  362. this.sortImg.style.display = "none";
  363. this.sortImg.src = this.imgURL + "sort_desc.gif";
  364. this.sortImg.defLeft = 0;
  365. // create and kill a row to set initial size
  366. // this.addRow("deletethisrtowafterresize",new Array("",""))
  367. this.entCnt.rows[0].style.display = ''// display header
  368. if (this.noHeader == -1) {
  369. this.noHeader = true
  370. this.entCnt.rows[0].style.display = 'none';
  371. } else {
  372. this.noHeader = false
  373. }
  374. // ========================
  375. this.attachHeader();
  376. this.attachHeader(0, 0, "_aFoot");
  377. // =========================
  378. if (this._ivizcol)
  379. for (var i = 0; i < this._ivizcol.length; i++)
  380. this.setColumnHidden(i, this._ivizcol[i]);
  381. this.setSizes();
  382. // this.deleteRow("deletethisrtowafterresize")
  383. // parse inline xml
  384. if (fl)
  385. this.parseXML()
  386. this.obj.scrollTop = 0
  387. if (this.dragAndDropOff)
  388. this.dragger.addDragLanding(this.entBox, this);
  389. };
  390. /**
  391. * @desc: sets sizes of grid elements
  392. * @type: private
  393. * @topic: 0,7
  394. */
  395. this.setSizes = function(fl) {
  396. if (fl && this.gridWidth == this.entBox.offsetWidth
  397. && this.gridHeight == this.entBox.offsetHeight) {
  398. return false
  399. } else if (fl) {
  400. this.gridWidth = this.entBox.offsetWidth
  401. this.gridHeight = this.entBox.offsetHeight
  402. }
  403. if ((!this.hdrBox.offsetHeight) && (this.hdrBox.offsetHeight > 0))
  404. this.entCnt.rows[0].cells[0].height = this.hdrBox.offsetHeight
  405. + "px";
  406. var gridWidth = parseInt(this.entBox.offsetWidth);
  407. var gridHeight = parseInt(this.entBox.offsetHeight);
  408. if (this.objBox.scrollHeight > this.objBox.offsetHeight)
  409. gridWidth -= (this._scrFix || (_isFF ? 19 : 16));
  410. var len = this.hdr.rows[0].cells.length
  411. for (var i = 0; i < this.hdr.rows[0].cells.length; i++) {
  412. if (this.cellWidthType == 'px' && this.cellWidthPX.length < len) {
  413. this.cellWidthPX[i] = this.initCellWidth[i];
  414. } else if (this.cellWidthType == '%'
  415. && this.cellWidthPC.length < len) {
  416. this.cellWidthPC[i] = this.initCellWidth[i];
  417. }
  418. if (this.cellWidthPC.length != 0) {
  419. this.cellWidthPX[i] = parseInt(gridWidth * this.cellWidthPC[i]
  420. / 100)
  421. - (_isFF ? 2 : 0);
  422. }
  423. }
  424. this.chngCellWidth(this.rowsCol._dhx_find(this.obj.rows[0]))
  425. var summ = 0;
  426. for (var i = 0; i < this.cellWidthPX.length; i++)
  427. summ += parseInt(this.cellWidthPX[i])
  428. this.objBuf.style.width = summ + "px";
  429. this.objBuf.childNodes[0].style.width = summ + "px";
  430. if (_isOpera)
  431. this.hdr.style.width = summ + this.cellWidthPX.length * 2 + "px";
  432. // set auto page size of dyn scroll
  433. this.doOnScroll(0, 1);
  434. // set header part of container visible height to header's height
  435. // this.entCnt.rows[0].cells[0].style.height = this.hdr.offsetHeight;
  436. this.hdr.style.border = "0px solid gray"; // FF 1.0 fix
  437. if ((_isMacOS) && (_isFF))
  438. var zheight = 20;
  439. else
  440. var zheight = this.hdr.offsetHeight;
  441. if (this._ahgr)
  442. if (this.objBox.scrollHeight) {
  443. if (_isIE)
  444. var z2 = this.objBox.scrollHeight;
  445. else
  446. var z2 = this.objBox.childNodes[0].scrollHeight;
  447. if (this._ahgrM)
  448. z2 = (z2 > this._ahgrM ? this._ahgrM : z2) * 1;
  449. gridHeight = z2
  450. + zheight
  451. + ((this.objBox.offsetWidth < this.objBox.scrollWidth)
  452. ? (_isFF ? 20 : 18)
  453. : 1);
  454. this.entBox.style.height = gridHeight + "px";
  455. }
  456. if (!this.noHeader)
  457. this.entCnt.rows[1].cells[0].childNodes[0].style.top = (zheight
  458. - this.hdrBox.offsetHeight + 1)
  459. + "px";
  460. // nb 072006:
  461. this.entCnt.rows[1].cells[0].childNodes[0].style.height = (((gridHeight
  462. - zheight - 1) < 0 && _isIE) ? 20 : (gridHeight - zheight - 1))
  463. + "px";
  464. };
  465. /**
  466. * @desc: changes cell width
  467. * @param: [ind] - index of row in grid
  468. * @type: private
  469. * @topic: 4,7
  470. */
  471. this.chngCellWidth = function(ind) {
  472. if (!ind)
  473. var ind = 0;
  474. for (var i = 0; i < this.cellWidthPX.length; i++) {
  475. this.hdr.rows[0].cells[i].style.width = this.cellWidthPX[i] + "px";
  476. if (this.rowsCol[ind])
  477. this.rowsCol[ind].cells[i].style.width = this.cellWidthPX[i]
  478. + "px";
  479. }
  480. }
  481. /**
  482. * @desc: set default delimiter
  483. * @param: delim - delimiter as string
  484. * @before_init: 1
  485. * @type: public
  486. * @topic: 0
  487. */
  488. this.setDelimiter = function(delim) {
  489. this.delim = delim;
  490. }
  491. /**
  492. * @desc: set width of columns in percents
  493. * @type: public
  494. * @before_init: 1
  495. * @param: wp - width in percents
  496. * @topic: 0,7
  497. */
  498. this.setInitWidthsP = function(wp) {
  499. this.cellWidthType = "%";
  500. this.initCellWidth = wp.split(this.delim.replace(/px/gi, ""));
  501. var el = window;
  502. var self = this;
  503. if (el.addEventListener) {
  504. if ((_isFF) && (_FFrv < 1.8))
  505. el.addEventListener("resize", function() {
  506. if (!self.entBox)
  507. return;
  508. var z = self.entBox.style.width;
  509. self.entBox.style.width = "1px";
  510. window.setTimeout(function() {
  511. self.entBox.style.width = z;
  512. self.setSizes();
  513. }, 10);
  514. }, false);
  515. else
  516. el.addEventListener("resize", function() {
  517. if (self.setSizes)
  518. self.setSizes();
  519. }, false);
  520. } else if (el.attachEvent)
  521. el.attachEvent("onresize", function() {
  522. if (self._resize_timer)
  523. window.clearTimeout(self._resize_timer);
  524. if (self.setSizes)
  525. self._resize_timer = window.setTimeout(function() {
  526. self.setSizes();
  527. }, 500);
  528. });
  529. }
  530. /**
  531. * @desc: set width of columns in pixels
  532. * @type: public
  533. * @before_init: 1
  534. * @param: wp - width in pixels
  535. * @topic: 0,7
  536. */
  537. this.setInitWidths = function(wp) {
  538. this.cellWidthType = "px";
  539. this.initCellWidth = wp.split(this.delim);
  540. if (_isFF) {
  541. for (var i = 0; i < this.initCellWidth.length; i++)
  542. this.initCellWidth[i] = parseInt(this.initCellWidth[i]) - 2;
  543. }
  544. }
  545. /**
  546. * @desc: set multiline rows support to enabled or disabled state
  547. * @type: public
  548. * @before_init: 1
  549. * @param: state - true or false
  550. * @topic: 0,7
  551. */
  552. this.enableMultiline = function(state) {
  553. this.multiLine = convertStringToBoolean(state);
  554. }
  555. /**
  556. * @desc: set multiselect mode to enabled or disabled state
  557. * @type: public
  558. * @param: state - true or false
  559. * @topic: 0,7
  560. */
  561. this.enableMultiselect = function(state) {
  562. this.selMultiRows = state;
  563. }
  564. /**
  565. * @desc: set path to grid internal images (sort direction, any images used
  566. * in editors, checkbox, radiobutton)
  567. * @type: public
  568. * @param: path - path to images folder with closing "/"
  569. * @topic: 0,7
  570. */
  571. this.setImagePath = function(path) {
  572. this.imgURL = path;
  573. }
  574. /**
  575. * @desc: part of column resize routine
  576. * @type: private
  577. * @param: ev - event
  578. * @topic: 3
  579. */
  580. this.changeCursorState = function(ev) {
  581. var el = ev.target || ev.srcElement;
  582. if ((el.tagName == "TD") && (this._drsclmn)
  583. && (!this._drsclmn[el._cellIndex]))
  584. return;
  585. if ((el.offsetWidth - (ev.offsetX || (parseInt(this.getPosition(el,
  586. this.hdrBox)) - ev.layerX)
  587. * -1)) < 10) {
  588. el.style.cursor = "E-resize";
  589. } else
  590. el.style.cursor = "default";
  591. }
  592. /**
  593. * @desc: part of column resize routine
  594. * @type: private
  595. * @param: ev - event
  596. * @topic: 3
  597. */
  598. this.startColResize = function(ev) {
  599. this.resized = null;
  600. var el = ev.target || ev.srcElement;
  601. var x = ev.layerX || ev.x;
  602. var tabW = this.hdr.offsetWidth;
  603. var startW = parseInt(el.offsetWidth)
  604. if (el.tagName == "TD" && el.style.cursor != "default") {
  605. if ((this._drsclmn) && (!this._drsclmn[el._cellIndex]))
  606. return;
  607. this.entBox.onmousemove = function(e) {
  608. this.grid.doColResize(e || window.event, el, startW, x, tabW)
  609. }
  610. document.body.onmouseup = new Function("",
  611. "document.getElementById('" + this.entBox.id
  612. + "').grid.stopColResize()");
  613. }
  614. }
  615. /**
  616. * @desc: part of column resize routine
  617. * @type: private
  618. * @param: ev - event
  619. * @topic: 3
  620. */
  621. this.stopColResize = function() {
  622. this.entBox.onmousemove = "";// removeEventListener("mousemove")//
  623. document.body.onmouseup = "";
  624. this.setSizes();
  625. this.doOnScroll(0, 1)
  626. if (this.onRSE)
  627. this.onRSE(this);
  628. }
  629. /**
  630. * @desc: part of column resize routine
  631. * @param: el - element (column resizing)
  632. * @param: startW - started width
  633. * @param: x - x coordinate to resize from
  634. * @param: tabW - started width of header table
  635. * @type: private
  636. * @topic: 3
  637. */
  638. this.doColResize = function(ev, el, startW, x, tabW) {
  639. el.style.cursor = "E-resize";
  640. this.resized = el;
  641. var fcolW = startW + ((ev.layerX || ev.x) - x);
  642. var wtabW = tabW + ((ev.layerX || ev.x) - x)
  643. if ((this.onRSI) && (!this.onRSI(el._cellIndex, fcolW, this)))
  644. return;
  645. var gridWidth = parseInt(this.entBox.offsetWidth);
  646. if (this.objBox.scrollHeight > this.objBox.offsetHeight)
  647. gridWidth -= (this._scrFix || (_isFF ? 19 : 16));
  648. if (fcolW > 10) {
  649. el.style.width = fcolW + "px";
  650. if (this.rowsCol.length > 0)
  651. // for (var i=0; i<this.obj.rows.length; i++)
  652. // this.obj.rows[i].cells[el._cellIndex].style.width =
  653. // fcolW+"px";
  654. this.rowsCol[this.rowsCol._dhx_find(this.obj.rows[0])].cells[el._cellIndex].style.width = fcolW
  655. + "px";
  656. if (this.cellWidthType == 'px') {
  657. this.cellWidthPX[el._cellIndex] = fcolW;
  658. } else {
  659. var pcWidth = Math.round(fcolW / gridWidth * 100)
  660. this.cellWidthPC[el._cellIndex] = pcWidth;
  661. }
  662. this.doOnScroll(0, 1)
  663. }
  664. /*
  665. * for(var i=0;i<this.cellWidthPX.length;i++) summ +=
  666. * parseInt(this.cellWidthPX[i]) this.objBuf.style.width = summ + "px";
  667. */
  668. this.objBuf.childNodes[0].style.width = "";
  669. }
  670. /**
  671. * @desc: sets position and visibility of sort image
  672. * @param: [state] - true/false - show/hide image
  673. * @param: [ind] - index of field
  674. * @param: [direction] - ASC/DESC - type of image
  675. * @type: public
  676. * @edition: Professional
  677. * @topic: 7
  678. */
  679. this.setSortImgState = function(state, ind, direction) {
  680. if (!convertStringToBoolean(state)) {
  681. this.sortImg.style.display = "none";
  682. return;
  683. }
  684. if (direction == "ASC")
  685. this.sortImg.src = this.imgURL + "sort_asc.gif";
  686. else
  687. this.sortImg.src = this.imgURL + "sort_desc.gif";
  688. this.sortImg.style.display = "";
  689. this.fldSorted = this.hdr.rows[0].cells[ind];
  690. this.setSortImgPos(ind);
  691. }
  692. /**
  693. * @desc: sets position and visibility of sort image
  694. * @param: [ind] - index of field
  695. * @type: private
  696. * @topic: 7
  697. */
  698. this.setSortImgPos = function(ind, mode) {
  699. if (!ind)
  700. var el = this.fldSorted;
  701. else
  702. var el = this.hdr.rows[0].cells[ind];
  703. if (el != null) {
  704. var pos = this.getPosition(el, this.hdrBox)
  705. var wdth = el.offsetWidth;
  706. this.sortImg.style.left = Number(pos[0] + wdth - 13) + "px";// Number(pos[0]+5)+"px";
  707. this.sortImg.defLeft = parseInt(this.sortImg.style.left)
  708. this.sortImg.style.top = Number(pos[1] + 5) + "px";
  709. if ((!this.useImagesInHeader) && (!mode))
  710. this.sortImg.style.display = "inline";
  711. this.sortImg.style.left = this.sortImg.defLeft + "px";// -parseInt(this.hdrBox.scrollLeft)
  712. }
  713. }
  714. /**
  715. * @desc: manage activity of the grid.
  716. * @param: fl - true to activate,false to deactivate
  717. * @type: private
  718. * @topic: 1,7
  719. */
  720. this.setActive = function(fl) {
  721. if (arguments.length == 0)
  722. var fl = true;
  723. if (fl == true) {
  724. // document.body.onkeydown = new
  725. // Function("","document.getElementById('"+this.entBox.id+"').grid.doKey()")//
  726. globalActiveDHTMLGridObject = this;
  727. this.isActive = true;
  728. } else {
  729. this.isActive = false;
  730. }
  731. };
  732. /**
  733. * @desc: called on click occured
  734. * @type: private
  735. */
  736. this._doClick = function(ev) {
  737. var selMethod = 0;
  738. var el = this.getFirstParentOfType(_isIE ? ev.srcElement : ev.target,
  739. "TD");
  740. var fl = true;
  741. if (this.selMultiRows != false) {
  742. if (ev.shiftKey && this.row != null) {
  743. selMethod = 1;
  744. }
  745. if (ev.ctrlKey) {
  746. selMethod = 2;
  747. }
  748. }
  749. this.doClick(el, fl, selMethod)
  750. };
  751. this._doContClick = function(ev) {
  752. var el = this.getFirstParentOfType(_isIE ? ev.srcElement : ev.target,
  753. "TD");
  754. if ((!el) || (el.parentNode.idd === undefined))
  755. return true;
  756. if ((ev.button == 2) && (this._ctmndx)) {
  757. if ((this._onBCM)
  758. && (!this._onBCM(el.parentNode.idd, el._cellIndex, this)))
  759. return true;
  760. el.contextMenuId = el.parentNode.idd + "_" + el._cellIndex;
  761. el.contextMenu = this._ctmndx;
  762. el.a = this._ctmndx._contextStart;
  763. if (_isIE)
  764. ev.srcElement.oncontextmenu = function() {
  765. event.cancelBubble = true;
  766. return false;
  767. };
  768. el.a(el, ev);
  769. el.a = null;
  770. }
  771. return true;
  772. }
  773. /**
  774. * @desc: occures on cell click (supports treegrid)
  775. * @param: [el] - cell to click on
  776. * @param: [fl] - true if to call onRowSelect function
  777. * @param: [selMethod] - 0 - simple click, 1 - shift, 2 - ctrl
  778. * @type: private
  779. * @topic: 1,2,4,9
  780. */
  781. this.doClick = function(el, fl, selMethod) {
  782. this.setActive(true);
  783. if (!selMethod)
  784. selMethod = 0;
  785. if (this.cell != null)
  786. this.cell.className = this.cell.className.replace(/cellselected/g,
  787. "");
  788. if (el.tagName == "TD"
  789. && this.rowsCol._dhx_find(this.rowsAr[el.parentNode.idd]) != -1) {
  790. if (selMethod == 0) {
  791. this.clearSelection();
  792. } else if (selMethod == 1) {
  793. var elRowIndex = this.rowsCol._dhx_find(el.parentNode)
  794. var lcRowIndex = this.rowsCol._dhx_find(this.lastClicked)
  795. if (elRowIndex > lcRowIndex) {
  796. var strt = lcRowIndex;
  797. var end = elRowIndex;
  798. } else {
  799. var strt = elRowIndex;
  800. var end = lcRowIndex;
  801. }
  802. this.clearSelection();
  803. for (var i = 0; i < this.rowsCol.length; i++) {
  804. if (i >= strt && i <= end) {
  805. this.rowsCol[i].className += " rowselected";
  806. this.selectedRows[this.selectedRows.length] = this.rowsCol[i]
  807. }/*
  808. * else{ this.rowsCol[i].className = ""; }
  809. */
  810. }
  811. } else if (selMethod == 2) {
  812. if (el.parentNode.className.indexOf("rowselected") != -1) {
  813. el.parentNode.className = el.parentNode.className.replace(
  814. "rowselected", "");
  815. this.selectedRows._dhx_removeAt(this.selectedRows
  816. ._dhx_find(el.parentNode))
  817. var skipRowSelection = true;
  818. }
  819. }
  820. this.editStop()
  821. this.cell = el;
  822. if (this.row != el.parentNode) {// if new row selected
  823. this.row = el.parentNode;
  824. if (fl) {
  825. var rid = this.row.idd
  826. var func = this.onRowSelect
  827. setTimeout(function() {
  828. func(rid, false);
  829. }, 100)
  830. }
  831. }
  832. if (!skipRowSelection) {
  833. this.row.className += " rowselected"
  834. if (this.selectedRows._dhx_find(this.row) == -1)
  835. this.selectedRows[this.selectedRows.length] = this.row;
  836. }
  837. if (this.selBasedOn == "cell") {
  838. if (this.cell.parentNode.className.indexOf("rowselected") != -1)
  839. this.cell.className = this.cell.className.replace(
  840. /cellselected/g, "")
  841. + " cellselected";
  842. }
  843. if (selMethod != 1)
  844. this.lastClicked = el.parentNode;
  845. }
  846. this.isActive = true;
  847. this.moveToVisible(this.cell)
  848. }
  849. /**
  850. * @desc: set selection to specified row-cell
  851. * @param: r - row object or row index
  852. * @param: cInd - cell index
  853. * @param: [fl] - true if to call onRowSelect function
  854. * @param: preserve - preserve previously selected rows true/false (false by
  855. * default)
  856. * @param: edit - switch selected cell to edit mode
  857. * @type: public
  858. * @topic: 1,4
  859. */
  860. this.selectCell = function(r, cInd, fl, preserve, edit) {
  861. if (!fl)
  862. fl = false;
  863. if (typeof(r) != "object")
  864. r = this.rowsCol[r]
  865. var c = r.childNodes[cInd];
  866. if (preserve)
  867. this.doClick(c, fl, 3)
  868. else
  869. this.doClick(c, fl)
  870. if (edit)
  871. this.editCell();
  872. }
  873. /**
  874. * @desc: moves specified cell to visible area (scrolls)
  875. * @param: cell_obj - object of the cell to work with
  876. * @type: private
  877. * @topic: 2,4,7
  878. */
  879. this.moveToVisible = function(cell_obj) {
  880. try {
  881. var distance = cell_obj.offsetLeft + cell_obj.offsetWidth + 20;
  882. if (distance > (this.objBox.offsetWidth + this.objBox.scrollLeft)) {
  883. var scrollLeft = distance - this.objBox.offsetWidth;
  884. } else if (cell_obj.offsetLeft < this.objBox.scrollLeft) {
  885. var scrollLeft = cell_obj.offsetLeft - 5
  886. }
  887. if (scrollLeft)
  888. this.objBox.scrollLeft = scrollLeft;
  889. var distance = cell_obj.offsetTop + cell_obj.offsetHeight + 20;
  890. if (distance > (this.objBox.offsetHeight + this.objBox.scrollTop)) {
  891. var scrollTop = distance - this.objBox.offsetHeight;
  892. } else if (cell_obj.offsetTop < this.objBox.scrollTop) {
  893. var scrollTop = cell_obj.offsetTop - 5
  894. }
  895. if (scrollTop)
  896. this.objBox.scrollTop = scrollTop;
  897. } catch (er) {
  898. }
  899. }
  900. /**
  901. * @desc: creates Editor object and switch cell to edit mode if allowed
  902. * @type: public
  903. * @topic: 4
  904. */
  905. this.editCell = function() {
  906. this.editStop();
  907. if ((this.isEditable != true) || (!this.cell))
  908. return false;
  909. var c = this.cell;
  910. // #locked_row:11052006{
  911. if (c.parentNode._locked)
  912. return false;
  913. // #}
  914. c.className += " editable";
  915. eval("this.editor = new eXcell_" + this.cellType[this.cell._cellIndex]
  916. + "(c)");
  917. // initialize editor
  918. if (this.editor != null) {
  919. if (typeof(this.onEditCell) == "string") {
  920. if (eval(this.onEditCell + "(0,'" + this.row.idd + "',"
  921. + this.cell._cellIndex + ");") != false) {
  922. this.editor.edit()
  923. this._Opera_stop = (new Date).valueOf();
  924. eval(this.onEditCell + "(1,'" + this.row.idd + "',"
  925. + this.cell._cellIndex + ");")
  926. } else {// preserve editing
  927. this.editor = null;
  928. }
  929. } else {
  930. if (this.onEditCell(0, this.row.idd, this.cell._cellIndex) != false) {
  931. this._Opera_stop = (new Date).valueOf();
  932. this.editor.edit()
  933. this.onEditCell(1, this.row.idd, this.cell._cellIndex)
  934. } else {// preserve editing
  935. this.editor = null;
  936. }
  937. }
  938. }
  939. }
  940. /**
  941. * @desc: gets value from editor(if presents) to cell and closes editor
  942. * @type: public
  943. * @topic: 4
  944. */
  945. this.editStop = function() {
  946. if (_isOpera)
  947. if (this._Opera_stop) {
  948. if ((this._Opera_stop * 1 + 50) > (new Date).valueOf())
  949. return;
  950. this._Opera_stop = null;
  951. }
  952. if (this.editor && this.editor != null) {
  953. this.cell.className = this.cell.className.replace("editable", "");
  954. this.cell.wasChanged = this.editor.detach();
  955. this.editor = null;
  956. if (typeof(this.onEditCell) == "string")
  957. eval(this.onEditCell + "(2,'" + this.row.idd + "',"
  958. + this.cell._cellIndex + ");")
  959. else
  960. this.onEditCell(2, this.row.idd, this.cell._cellIndex);
  961. }
  962. }
  963. /**
  964. * @desc: manages keybord activity in grid
  965. * @type: private
  966. * @topic: 7
  967. */
  968. this.doKey = function(ev) {
  969. // alert("946 " + ev.keyCode + ev.ctrlKey)
  970. if (!ev)
  971. return true;
  972. if ((ev.target || ev.srcElement).value !== window.undefined) {
  973. var zx = (ev.target || ev.srcElement);
  974. if ((!zx.parentNode)
  975. || (zx.parentNode.className.indexOf("editable") == -1))
  976. return true;
  977. }
  978. if ((globalActiveDHTMLGridObject)
  979. && (this != globalActiveDHTMLGridObject))
  980. return globalActiveDHTMLGridObject.doKey(ev);
  981. if (this.isActive == false) {
  982. // document.body.onkeydown = "";
  983. return true;
  984. }
  985. if (this._htkebl)
  986. return true;
  987. try {
  988. var type = this.cellType[this.cell._cellIndex]
  989. // ENTER
  990. if (ev.keyCode == 13 && (ev.ctrlKey || ev.shiftKey)) {
  991. var rowInd = this.rowsCol._dhx_find(this.row)
  992. if (window.event.ctrlKey && rowInd != this.rowsCol.length - 1) {
  993. if (this.row.rowIndex == this.obj.rows.length - 1
  994. && this.dynScroll && this.dynScroll != 'false')
  995. this.doDynScroll("dn")
  996. this.selectCell(this.rowsCol[rowInd + 1],
  997. this.cell._cellIndex, true);
  998. } else if (ev.shiftKey && rowInd != 0) {
  999. if (this.row.rowIndex == 0 && this.dynScroll
  1000. && this.dynScroll != 'false')
  1001. this.doDynScroll("up")
  1002. this.selectCell(this.rowsCol[rowInd - 1],
  1003. this.cell._cellIndex, true);
  1004. }
  1005. _isIE ? ev.returnValue = false : ev.preventDefault();
  1006. }
  1007. if (ev.keyCode == 13 && !ev.ctrlKey && !ev.shiftKey) {
  1008. this.editStop();
  1009. if (typeof(this.onEnter) == "string")
  1010. eval("window." + this.onEnter + "('" + this.row.idd + "',"
  1011. + this.cell._cellIndex + ")")
  1012. else
  1013. this.onEnter(this.row.idd, this.cell._cellIndex);
  1014. _isIE ? ev.returnValue = false : ev.preventDefault();
  1015. }
  1016. // TAB
  1017. if (ev.keyCode == 9 && !ev.shiftKey) {
  1018. this.editStop();
  1019. var aind = this.cell._cellIndex + 1;
  1020. var arow = this.row;
  1021. if (aind == this.row.childNodes.length) {
  1022. aind = 0;
  1023. arow = this.rowsCol[this.rowsCol._dhx_find(this.row) + 1];
  1024. if (!arow) {
  1025. aind = this.row.childNodes.length - 1;
  1026. return true;
  1027. }
  1028. }
  1029. this.selectCell(arow || this.row, aind,
  1030. ((arow) && (this.row != arow)));
  1031. this.editCell()
  1032. _isIE ? ev.returnValue = false : ev.preventDefault();
  1033. } else if (ev.keyCode == 9 && ev.shiftKey) {
  1034. this.editStop();
  1035. var aind = this.cell._cellIndex - 1;
  1036. var arow = this.row;
  1037. if (aind < 0) {
  1038. aind = this.row.childNodes.length - 1;
  1039. arow = this.rowsCol[this.rowsCol._dhx_find(this.row) - 1];
  1040. if (!arow) {
  1041. aind = 0;
  1042. return true;
  1043. }
  1044. }
  1045. this.selectCell(arow || this.row, aind,
  1046. ((arow) && (this.row != arow)));
  1047. this.editCell()
  1048. _isIE ? ev.returnValue = false : ev.preventDefault();
  1049. }
  1050. // UP & DOWN
  1051. if (ev.keyCode == 40 || ev.keyCode == 38) {// && ev.ctrlKey
  1052. if (this.editor && this.editor.combo) {
  1053. if (ev.keyCode == 40)
  1054. this.editor.shiftNext();
  1055. if (ev.keyCode == 38)
  1056. this.editor.shiftPrev();
  1057. return false;
  1058. } else {
  1059. var rowInd = this.row.rowIndex;// rowsCol._dhx_find(this.row)
  1060. if (ev.keyCode == 38 && rowInd != 0) {
  1061. if (this.row.rowIndex == 0 && this.dynScroll
  1062. && this.dynScroll != 'false')
  1063. this.doDynScroll("up")
  1064. this.selectCell(this.obj.rows[rowInd - 1],
  1065. this.cell._cellIndex, true);
  1066. } else if (ev.keyCode == 40
  1067. && rowInd != this.rowsCol.length - 1) {
  1068. if (this.row.rowIndex == this.obj.rows.length - 1
  1069. && this.dynScroll && this.dynScroll != 'false')
  1070. this.doDynScroll("dn")
  1071. this.selectCell(this.obj.rows[rowInd + 1],
  1072. this.cell._cellIndex, true);
  1073. }
  1074. }
  1075. _isIE ? ev.returnValue = false : ev.preventDefault();
  1076. }
  1077. // F2
  1078. if ((ev.keyCode == 113) && (this._f2kE)) {
  1079. this.editCell();
  1080. return false;
  1081. }
  1082. // SPACE
  1083. if (ev.keyCode == 32) {// && (type=='ch'|| type.indexOf('ra')==0)){
  1084. var c = this.cell
  1085. eval("var ed = new eXcell_" + this.cellType[c._cellIndex]
  1086. + "(c)");
  1087. // this.cell.children(0).click()
  1088. if (ed.changeState() != false)
  1089. _isIE ? ev.returnValue = false : ev.preventDefault();
  1090. }
  1091. // Esc
  1092. if (ev.keyCode == 27 && this.oe != false) {
  1093. this.editStop();
  1094. _isIE ? ev.returnValue = false : ev.preventDefault();
  1095. }
  1096. // PAGEUP / PAGEDOWN
  1097. if (ev.keyCode == 33 || ev.keyCode == 34) {
  1098. if (ev.keyCode == 33)
  1099. this.doDynScroll("up")
  1100. else
  1101. this.doDynScroll("dn")
  1102. _isIE ? ev.returnValue = false : ev.preventDefault();
  1103. }
  1104. // RIGHT LEFT
  1105. if (!this.editor) {
  1106. if (ev.keyCode == 37 && this.cellType._dhx_find("tree") != -1) {
  1107. this.collapseKids(this.row)
  1108. _isIE ? ev.returnValue = false : ev.preventDefault();
  1109. }
  1110. if (ev.keyCode == 39 && this.cellType._dhx_find("tree") != -1) {
  1111. this.expandKids(this.row)
  1112. _isIE ? ev.returnValue = false : ev.preventDefault();
  1113. }
  1114. }
  1115. if (ev.keyCode == 67 && ev.ctrlKey) {
  1116. // alert("Should copy data ....................")
  1117. this.setCSVDelimiter("\t");
  1118. this.copyBlockToClipboard();
  1119. // ======================================================
  1120. // if (!this.callEvent("onKeyPress", [ev.keyCode, ev.ctrlKey,
  1121. // ev.shiftKey]))
  1122. // return false;
  1123. // ===========================================================
  1124. }
  1125. return true;
  1126. } catch (er) {
  1127. return true;
  1128. }
  1129. }
  1130. /**
  1131. * @desc: selects row (?)for comtatibility with previous version
  1132. * @param: cell - cell object(or cell's child)
  1133. * @invoke: click on cell(or cell content)
  1134. * @type: private
  1135. * @topic: 1,2
  1136. */
  1137. this.getRow = function(cell) {
  1138. if (!cell)
  1139. cell = window.event.srcElement;
  1140. if (cell.tagName != 'TD')
  1141. cell = cell.parentElement;
  1142. r = cell.parentElement;
  1143. if (this.cellType[cell._cellIndex] == 'lk')
  1144. eval(this.onLink + "('" + this.getRowId(r.rowIndex) + "',"
  1145. + cell._cellIndex + ")");
  1146. this.selectCell(r, cell._cellIndex, true)
  1147. }
  1148. /**
  1149. * @desc: selects row (and first cell of it)
  1150. * @param: r - row index or row object
  1151. * @param: fl - if true, then call function on select
  1152. * @param: preserve - preserve previously selected rows true/false (false by
  1153. * default)
  1154. * @type: public
  1155. * @topic: 1,2
  1156. */
  1157. this.selectRow = function(r, fl, preserve) {
  1158. if (typeof(r) != 'object')
  1159. r = this.rowsCol[r]
  1160. this.selectCell(r, 0, fl, preserve)
  1161. };
  1162. /**
  1163. * @desc: sorts specified column
  1164. * @param: col - column index
  1165. * @param: type - str.int.date
  1166. * @param: order - asc.desc
  1167. * @type: public
  1168. * @topic: 2,3,5,9
  1169. */
  1170. this.sortRows = function(col, type, order) {
  1171. // if tree cell exists
  1172. if (this.cellType._dhx_find("tree") != -1) {
  1173. return this.sortTreeRows(col, type, order)
  1174. }
  1175. var self = this;
  1176. if (type == 'cus') {
  1177. this.rowsCol.sort(function(a, b) {
  1178. var cA = a.childNodes[col]
  1179. var cB = b.childNodes[col]
  1180. var type = a.grid.cellType[col];
  1181. eval("var edA = new eXcell_" + type + "(cA)")
  1182. eval("var edB = new eXcell_" + type + "(cB)")
  1183. return self._customSorts[col](edA.getValue(), edB
  1184. .getValue(), order);
  1185. });
  1186. } else if (type == 'str') {
  1187. this.rowsCol.sort(function(a, b) {
  1188. var cA = a.childNodes[col]
  1189. var cB = b.childNodes[col]
  1190. var type = a.grid.cellType[col];
  1191. eval("var edA = new eXcell_" + type + "(cA)")
  1192. eval("var edB = new eXcell_" + type + "(cB)")
  1193. if (order == "asc")
  1194. return edA.getValue() > edB.getValue() ? 1 : -1
  1195. else
  1196. return edA.getValue() < edB.getValue() ? 1 : -1
  1197. });
  1198. } else if (type == 'int') {
  1199. this.rowsCol.sort(function(a, b) {
  1200. var cA = a.childNodes[col]
  1201. var cB = b.childNodes[col]
  1202. var type = a.grid.cellType[col];
  1203. eval("var edA = new eXcell_" + type + "(cA)")
  1204. eval("var edB = new eXcell_" + type + "(cB)")
  1205. var aVal = parseFloat(edA.getValue())
  1206. || -99999999999999
  1207. var bVal = parseFloat(edB.getValue())
  1208. || -99999999999999
  1209. if (order == "asc")
  1210. return aVal - bVal
  1211. else
  1212. return bVal - aVal
  1213. });
  1214. } else if (type == 'date') {
  1215. this.rowsCol.sort(function(a, b) {
  1216. var cA = a.childNodes[col]
  1217. var cB = b.childNodes[col]
  1218. var type = a.grid.cellType[col];
  1219. eval("var edA = new eXcell_" + type + "(cA)")
  1220. eval("var edB = new eXcell_" + type + "(cB)")
  1221. // -----------------------------------------------------need
  1222. // to doing something........--------------------------
  1223. var aVal = Date.parse(new Date(edA.getValue())
  1224. || new Date("01/01/1900"))
  1225. var bVal = Date.parse(new Date(edB.getValue())
  1226. || new Date("01/01/1900"))
  1227. if (order == "asc")
  1228. return aVal - bVal
  1229. else
  1230. return bVal - aVal
  1231. });
  1232. }
  1233. if (this.dynScroll && this.dynScroll != 'false') {
  1234. alert("not implemented yet")
  1235. } else {
  1236. var tb = this.obj.firstChild;
  1237. for (var i = 0; i < this.rowsCol.length; i++) {
  1238. tb.insertBefore(this.rowsCol[i], tb.childNodes[i])
  1239. // tb.moveRow(this.rowsCol[i].rowIndex,i)
  1240. }
  1241. }
  1242. this.setSizes()
  1243. if (this.onGridReconstructed)
  1244. this.onGridReconstructed();
  1245. }
  1246. /**
  1247. * @desc: enables the possibility to load content from server when already
  1248. * loaded content was rendered. Using this you decrease the grid
  1249. * loading time for extremely big amounts of data.
  1250. * @type: public
  1251. * @topic: 0,7
  1252. */
  1253. this.setXMLAutoLoading = function(filePath, bufferSize) {
  1254. this.recordsNoMore = false;
  1255. this.xmlFileUrl = filePath;
  1256. this.rowsBufferOutSize = bufferSize || 40;
  1257. }
  1258. /**
  1259. * @desc: enables buffering in content rendering. Using this you decrease
  1260. * the grid loading time.
  1261. * @type: public
  1262. * @topic: 0,7
  1263. */
  1264. this.enableBuffering = function(bufferSize) {
  1265. this.rowsBufferOutSize = bufferSize || 40;
  1266. }
  1267. /**
  1268. * @desc: create rows from another part of buffer
  1269. * @type: private
  1270. * @topic: 0,2,7
  1271. */
  1272. this.addRowsFromBuffer = function() {
  1273. if (this.rowsBuffer[0].length == 0) {
  1274. if (!this.recordsNoMore) {
  1275. if ((this.xmlFileUrl != "") && (!this._startXMLLoading)) {
  1276. this._startXMLLoading = true;
  1277. this.loadXML(this.xmlFileUrl)
  1278. }
  1279. } else
  1280. return false;
  1281. }
  1282. var cnt = Math.min(this.rowsBufferOutSize, this.rowsBuffer[0].length)
  1283. var tree = this.cellType._dhx_find("tree");
  1284. // this.rowsBuffer.length
  1285. for (var i = 0; i < cnt; i++) {
  1286. var rowNode = this.rowsBuffer[1][0]
  1287. var rId = rowNode.getAttribute("id")
  1288. var pId = 0;
  1289. var cellsCol = rowNode.childNodes;
  1290. var strAr = new Array(0);
  1291. var jj = 0;
  1292. for (var j = 0; j < cellsCol.length; j++) {
  1293. if (cellsCol[j].tagName == 'cell') {
  1294. if (jj != tree)
  1295. strAr[strAr.length] = cellsCol[j].firstChild
  1296. ? cellsCol[j].firstChild.data
  1297. : "";
  1298. else
  1299. strAr[strAr.length] = rowNode.parentNode
  1300. .getAttribute("id")
  1301. || 0
  1302. + "^"
  1303. + (cellsCol[j].firstChild
  1304. ? cellsCol[j].firstChild.data
  1305. : "")
  1306. + "^"
  1307. + (rowNode.getAttribute("xmlkids") ? "1" : "0")
  1308. + "^"
  1309. + (cellsCol[j].getAttribute("image") || "leaf.gif");
  1310. jj++;
  1311. }
  1312. }
  1313. var r = this._addRow(rId, strAr)
  1314. // select row
  1315. if (rowNode.getAttribute("selected") == true) {
  1316. this.setSelectedRow(rId, false, false, rowNode
  1317. .getAttribute("call") == true)
  1318. }
  1319. // expand
  1320. if (rowNode.getAttribute("expand") == "1") {
  1321. r.expand = "";
  1322. }
  1323. this.rowsBuffer[0]._dhx_removeAt(0);
  1324. this.rowsBuffer[1]._dhx_removeAt(0);
  1325. }
  1326. return true;
  1327. }
  1328. /**
  1329. * @desc: allow multiselection
  1330. * @param: fl - false/true
  1331. * @type: public
  1332. * @before_init: 1
  1333. * @topic: 0,2,7
  1334. */
  1335. this.setMultiselect = function(fl) {
  1336. this.selMultiRows = fl;
  1337. }
  1338. /**
  1339. * @desc: deletes row
  1340. * @param: row_id - id of row to delete
  1341. * @type: public
  1342. * @topic: 2,9
  1343. */
  1344. this.deleteRow = function(row_id, node) {
  1345. this.editStop();
  1346. if (typeof(this.onBeforeRowDeleted) == "function"
  1347. && this.onBeforeRowDeleted(row_id) == false)
  1348. return false;
  1349. if (!node)
  1350. node = this.getRowById(row_id)
  1351. if (node != null) {
  1352. if (this.cellType._dhx_find("tree") != -1)
  1353. this._removeTrGrRow(node);
  1354. node.parentNode.removeChild(node);// nb:node.removeNode(true);
  1355. var ind = this.rowsCol._dhx_find(node);
  1356. this.rowsCol._dhx_removeAt(ind)
  1357. node = null;
  1358. }
  1359. this.rowsAr[row_id] = null;
  1360. if (this.onGridReconstructed)
  1361. this.onGridReconstructed();
  1362. this.setSizes();
  1363. }
  1364. /**
  1365. * @desc: called when row was double clicked
  1366. * @type: private
  1367. * @topic: 1,2
  1368. */
  1369. this.wasDblClicked = function(ev) {
  1370. var el = this.getFirstParentOfType(_isIE ? ev.srcElement : ev.target,
  1371. "TR");
  1372. if (el) {
  1373. var rowId = el.idd;
  1374. if (typeof(this.onRowDblClicked) == "function") {
  1375. return this.onRowDblClicked(rowId)
  1376. } else {
  1377. return true;
  1378. }
  1379. }
  1380. }
  1381. /**
  1382. * @desc: deletes selected row(s)
  1383. * @type: public
  1384. * @topic: 2
  1385. */
  1386. this.deleteSelectedItem = function() {
  1387. var num = this.selectedRows.length// this.obj.rows.length
  1388. if (num == 0)
  1389. return;
  1390. var tmpAr = this.selectedRows;
  1391. this.selectedRows = new Array(0)
  1392. for (var i = num - 1; i >= 0; i--) {
  1393. var node = tmpAr[i]
  1394. if (!this.deleteRow(node.idd, node)) {
  1395. this.selectedRows[this.selectedRows.length] = node;
  1396. } else {
  1397. if (node == this.row) {
  1398. var ind = i;
  1399. }
  1400. }
  1401. /*
  1402. * this.rowsAr[node.idd] = null; var posInCol =
  1403. * this.rowsCol._dhx_find(node)
  1404. * this.rowsCol[posInCol].parentNode.removeChild(this.rowsCol[posInCol]);//nb:this.rowsCol[posInCol].removeNode(true);
  1405. * this.rowsCol._dhx_removeAt(posInCol)
  1406. */
  1407. }
  1408. if (ind) {
  1409. try {
  1410. if (ind + 1 > this.rowsCol.length)// this.obj.rows.length)
  1411. ind--;
  1412. this.selectCell(ind, 0, true)
  1413. } catch (er) {
  1414. this.row = null
  1415. this.cell = null
  1416. }
  1417. }
  1418. }
  1419. /**
  1420. * @desc: gets selected row id
  1421. * @returns: id of selected row (list of ids with default delimiter) or null
  1422. * if non row selected
  1423. * @type: public
  1424. * @topic: 1,2,9
  1425. */
  1426. this.getSelectedId = function() {
  1427. var selAr = new Array(0);
  1428. for (var i = 0; i < this.selectedRows.length; i++) {
  1429. selAr[selAr.length] = this.selectedRows[i].idd
  1430. }
  1431. // ..
  1432. if (selAr.length == 0)
  1433. return null;
  1434. else
  1435. return selAr.join(this.delim);
  1436. }
  1437. /**
  1438. * @desc: gets index of selected cell
  1439. * @returns: index of selected cell or -1 if there is no selected sell
  1440. * @type: public
  1441. * @topic: 1,4
  1442. */
  1443. this.getSelectedCellIndex = function() {
  1444. if (this.cell != null)
  1445. return this.cell._cellIndex;
  1446. else
  1447. return -1;
  1448. }
  1449. /**
  1450. * @desc: gets width of specified column in pixels
  1451. * @param: ind - column index
  1452. * @returns: column width in pixels
  1453. * @type: public
  1454. * @topic: 3,7
  1455. */
  1456. this.getColWidth = function(ind) {
  1457. return parseInt(this.cellWidthPX[ind]) + ((_isFF) ? 2 : 0);
  1458. }
  1459. /**
  1460. * @desc: sets width of specified column in pixels (soen't works with
  1461. * procent based grid)
  1462. * @param: ind - column index
  1463. * @param: value - new width value
  1464. * @type: public
  1465. * @topic: 3,7
  1466. */
  1467. this.setColWidth = function(ind, value) {
  1468. this.cellWidthPX[ind] = parseInt(value);
  1469. this.setSizes();
  1470. }
  1471. /**
  1472. * @desc: gets row object by id
  1473. * @param: id - row id
  1474. * @returns: row object or null if there is no row with specified id
  1475. * @type: private
  1476. * @topic: 2,7,9
  1477. */
  1478. this.getRowById = function(id) {
  1479. var row = this.rowsAr[id]
  1480. if (row)
  1481. return row;
  1482. else
  1483. return null;
  1484. }
  1485. /**
  1486. * @desc: gets row index by id (grid only)
  1487. * @param: row_id - row id
  1488. * @returns: row index or -1 if there is no row with specified id
  1489. * @type: public
  1490. * @topic: 2
  1491. */
  1492. this.getRowIndex = function(row_id) {
  1493. var ind = this.rowsCol._dhx_find(this.getRowById(row_id));
  1494. if (ind != -1)
  1495. return ind;
  1496. else {
  1497. ind = this.rowsBuffer[0]._dhx_find(row_id)
  1498. if (ind != -1)
  1499. return ind + this.rowsCol.length;
  1500. return -1;
  1501. }
  1502. }
  1503. /**
  1504. * @desc: gets row id by index
  1505. * @param: ind - row index
  1506. * @returns: row id or null if there is no row with specified index
  1507. * @type: public
  1508. * @topic: 2
  1509. */
  1510. this.getRowId = function(ind) {
  1511. try {
  1512. return this.rowsCol[parseInt(ind)].idd;
  1513. } catch (er) {
  1514. return this.rowsBuffer[0][ind - this.rowsCol.length - 1]
  1515. // return null;
  1516. }
  1517. }
  1518. /**
  1519. * @desc: sets new id for row by its index
  1520. * @param: ind - row index
  1521. * @param: row_id - new row id
  1522. * @type: public
  1523. * @topic: 2
  1524. */
  1525. this.setRowId = function(ind, row_id) {
  1526. var r = this.rowsCol[ind]
  1527. this.changeRowId(r.idd, row_id)
  1528. }
  1529. /**
  1530. * @desc: changes id of the row to the new one
  1531. * @param: oldRowId - row id to change
  1532. * @param: newRowId - row id to set
  1533. * @type:public
  1534. * @topic: 2
  1535. */
  1536. this.changeRowId = function(oldRowId, newRowId) {
  1537. var row = this.rowsAr[oldRowId]
  1538. row.idd = newRowId;
  1539. if (this.UserData[oldRowId]) {
  1540. this.UserData[newRowId] = this.UserData[oldRowId]
  1541. this.UserData[oldRowId] = null;
  1542. }
  1543. if (this.loadedKidsHash) {
  1544. if (this.loadedKidsHash.get(oldRowId) != null) {
  1545. this.loadedKidsHash.put(newRowId, this.loadedKidsHash
  1546. .get(oldRowId));
  1547. this.loadedKidsHash.remove(oldRowId);
  1548. }
  1549. var parentsHash = this.loadedKidsHash.get("hashOfParents")
  1550. if (parentsHash != null) {
  1551. if (parentsHash.get(oldRowId) != null) {
  1552. parentsHash.put(newRowId, row);
  1553. parentsHash.remove(oldRowId);
  1554. this.loadedKidsHash.put("hashOfParents", parentsHash)
  1555. }
  1556. }
  1557. }
  1558. this.rowsAr[oldRowId] = null;
  1559. this.rowsAr[newRowId] = row;
  1560. }
  1561. /**
  1562. * @desc: sets ids to every column. Can be used then to retreive the index
  1563. * of the desired colum
  1564. * @param: [ids] - "," delimitered list of ids, or empty if to use values
  1565. * set earlier
  1566. * @type: public
  1567. * @topic: 3
  1568. */
  1569. this.setColumnIds = function(ids) {
  1570. if (ids)
  1571. this.columnIds = ids.split(",")
  1572. if (this.hdr.rows[0].cells.length >= this.columnIds.length) {
  1573. for (var i = 0; i < this.columnIds.length; i++) {
  1574. this.hdr.rows[0].cells[i].column_id = this.columnIds[i];
  1575. }
  1576. }
  1577. }
  1578. /**
  1579. * @desc: gets column index by column id
  1580. * @param: id - column id
  1581. * @returns: index of the column
  1582. * @type: public
  1583. * @topic: 3
  1584. */
  1585. this.getColIndexById = function(id) {
  1586. for (var i = 0; i < this.hdr.rows[0].cells.length; i++) {
  1587. if (this.hdr.rows[0].cells[i].column_id == id)
  1588. return i;
  1589. }
  1590. }
  1591. /**
  1592. * @desc: gets column id of column specified by index
  1593. * @param: cin - column index
  1594. * @returns: column id
  1595. * @type: public
  1596. * @topic: 3
  1597. */
  1598. this.getColumnId = function(cin) {
  1599. return this.hdr.rows[0].cells[cin].column_id
  1600. }
  1601. /**
  1602. * @desc: gets label of column specified by index
  1603. * @param: cin - column index
  1604. * @returns: column label
  1605. * @type: public
  1606. * @topic: 3
  1607. */
  1608. this.getHeaderCol = function(cin) {
  1609. return this.hdr.rows[0].cells[Number(cin)].innerHTML;
  1610. }
  1611. /**
  1612. * @desc: sets row text BOLD
  1613. * @param: row_id - row id
  1614. * @type: public
  1615. * @topic: 2,6
  1616. */
  1617. this.setRowTextBold = function(row_id) {
  1618. this.getRowById(row_id).style.fontWeight = "bold";
  1619. }
  1620. /**
  1621. * @desc: sets style to row
  1622. * @param: row_id - row id
  1623. * @param: styleString - style string in common format (exmpl:
  1624. * "color:red;border:1px solid gray;")
  1625. * @type: public
  1626. * @topic: 2,6
  1627. */
  1628. this.setRowTextStyle = function(row_id, styleString) {
  1629. var r = this.getRowById(row_id)
  1630. for (var i = 0; i < r.childNodes.length; i++) {
  1631. var pfix = "";
  1632. if ((this._hrrar) && (this._hrrar[i]))
  1633. pfix = "display:none;";
  1634. if (_isIE)
  1635. r.childNodes[i].style.cssText = pfix + "width:"
  1636. + r.childNodes[i].style.width + ";" + styleString;
  1637. else
  1638. r.childNodes[i].style.cssText = pfix + "width:"
  1639. + r.childNodes[i].style.width + ";" + styleString;
  1640. }
  1641. }
  1642. /**
  1643. * @desc: sets style to cell
  1644. * @param: row_id - row id
  1645. * @param: ind - cell index
  1646. * @param: styleString - style string in common format (exmpl:
  1647. * "color:red;border:1px solid gray;")
  1648. * @type: public
  1649. * @topic: 2,6
  1650. */
  1651. this.setCellTextStyle = function(row_id, ind, styleString) {
  1652. var r = this.getRowById(row_id)
  1653. if (!r)
  1654. return;
  1655. if (ind < r.childNodes.length) {
  1656. var pfix = "";
  1657. if ((this._hrrar) && (this._hrrar[i]))
  1658. pfix = "display:none;";
  1659. if (_isIE)
  1660. r.childNodes[ind].style.cssText = pfix + "width:"
  1661. + r.childNodes[ind].style.width + ";" + styleString;
  1662. else
  1663. r.childNodes[ind].style.cssText = pfix + "width:"
  1664. + r.childNodes[ind].style.width + ";" + styleString;
  1665. }
  1666. }
  1667. /**
  1668. * @desc: sets row text NORMAL
  1669. * @param: row_id - row id
  1670. * @type: public
  1671. * @topic: 2,6
  1672. */
  1673. this.setRowTextNormal = function(row_id) {
  1674. this.getRowById(row_id).style.fontWeight = "normal";
  1675. }
  1676. /**
  1677. * @desc: determines if row with specified id exists
  1678. * @param: row_id - row id
  1679. * @returns: true if exists, false otherwise
  1680. * @type: public
  1681. * @topic: 2,7
  1682. */
  1683. this.isItemExists = function(row_id) {
  1684. if (this.getRowById(row_id) != null)
  1685. return true
  1686. else
  1687. return false
  1688. }
  1689. /**
  1690. * @desc: gets a list of all row ids in grid
  1691. * @param: separator - delimiter to use in list
  1692. * @returns: list of all row ids in grid
  1693. * @type: public
  1694. * @topic: 2,7
  1695. */
  1696. this.getAllItemIds = function(separator) {
  1697. var ar = new Array(0)
  1698. for (i = 0; i < this.rowsCol.length; i++) {
  1699. ar[ar.length] = this.rowsCol[i].idd
  1700. }
  1701. for (i = 0; i < this.rowsBuffer[0].length; i++) {
  1702. ar[ar.length] = this.rowsBuffer[0][i]
  1703. }
  1704. return ar.join(separator || ",")
  1705. }
  1706. /**
  1707. * @desc: gets number of rows in grid
  1708. * @returns: number of rows in grid
  1709. * @type: public
  1710. * @topic: 2,7
  1711. */
  1712. this.getRowsNum = function() {
  1713. return this.rowsCol.length + this.rowsBuffer[0].length;
  1714. }
  1715. /**
  1716. * @desc: gets number of columns in grid
  1717. * @returns: number of columns in grid
  1718. * @type: public
  1719. * @topic: 3,7
  1720. */
  1721. this.getColumnCount = function() {
  1722. return this.hdr.rows[0].cells.length;
  1723. }
  1724. this.moveRowUp = function(row_id) {
  1725. var r = this.getRowById(row_id)
  1726. var rInd = this.rowsCol._dhx_find(r)
  1727. if (this.isTreeGrid()) {
  1728. if (this.rowsCol[rInd].parent_id != this.rowsCol[rInd - 1].parent_id)
  1729. return;
  1730. this.collapseKids(r);
  1731. }
  1732. this.rowsCol._dhx_swapItems(rInd, rInd - 1)
  1733. if (r.previousSibling) {
  1734. this.obj.firstChild.insertBefore(r, r.previousSibling)
  1735. this.setSizes();
  1736. }
  1737. }
  1738. /**
  1739. * @desc: moves row one position down if possible
  1740. * @param: row_id - row id
  1741. * @type: public
  1742. * @topic: 2
  1743. */
  1744. this.moveRowDown = function(row_id) {
  1745. var r = this.getRowById(row_id)
  1746. var rInd = this.rowsCol._dhx_find(r)
  1747. if (this.isTreeGrid())
  1748. if (this.rowsCol[rInd].parent_id != this.rowsCol[rInd + 1].parent_id)
  1749. return;
  1750. if (r.nextSibling) {
  1751. if (r.nextSibling.nextSibling)
  1752. this.obj.firstChild.insertBefore(r, r.nextSibling.nextSibling)
  1753. else
  1754. this.obj.firstChild.appendChild(r)
  1755. this.setSizes();
  1756. }
  1757. }
  1758. /**
  1759. * @desc: gets dhtmlXGridCellObject object (if no arguments then gets
  1760. * dhtmlXGridCellObject object of currently selected cell)
  1761. * @param: row_id - row id
  1762. * @param: col - column index
  1763. * @returns: dhtmlXGridCellObject object (see its methods below)
  1764. * @type: public
  1765. * @topic: 4
  1766. */
  1767. this.cells = function(row_id, col) {
  1768. if (arguments.length == 0) {
  1769. var c = this.cell;
  1770. return eval("new eXcell_" + this.cellType[this.cell._cellIndex]
  1771. + "(c)");
  1772. } else {
  1773. var c = this.getRowById(row_id);
  1774. if (!c)
  1775. return null;
  1776. return eval("new eXcell_" + this.cellType[col]
  1777. + "(c.childNodes[col])");
  1778. }
  1779. }
  1780. /**
  1781. * @desc: gets dhtmlXGridCellObject object
  1782. * @param: row_index - row index
  1783. * @param: col - column index
  1784. * @returns: dhtmlXGridCellObject object (see its methods below)
  1785. * @type: public
  1786. * @topic: 4
  1787. */
  1788. this.cells2 = function(row_index, col) {
  1789. var c = this.rowsCol[parseInt(row_index)].cells[parseInt(col)];
  1790. return eval("new eXcell_" + this.cellType[c._cellIndex] + "(c)");
  1791. }
  1792. this.cells3 = function(row, col) {
  1793. var c = row.childNodes[col];
  1794. return eval("new eXcell_" + this.cellType[c._cellIndex] + "(c)");
  1795. }
  1796. /**
  1797. * @desc: gets Combo object of specified column
  1798. * @type: public
  1799. * @topic: 3,4
  1800. * @param: col_ind - index of the column to get combo object for
  1801. */
  1802. this.getCombo = function(col_ind) {
  1803. if (this.cellType[col_ind].indexOf('co') == 0) {
  1804. if (!this.combos[col_ind]) {
  1805. this.combos[col_ind] = new dhtmlXGridComboObject();
  1806. }
  1807. return this.combos[col_ind];
  1808. } else {
  1809. return null;
  1810. }
  1811. }
  1812. /**
  1813. * @desc: sets user Data
  1814. * @param: row_id - row id. if empty then user data is for grid (not row)
  1815. * @param: name - name of user data
  1816. * @param: value - value of user data
  1817. * @type: public
  1818. * @topic: 2,5
  1819. */
  1820. this.setUserData = function(row_id, name, value) {
  1821. try {
  1822. if (row_id == "")
  1823. row_id = "gridglobaluserdata";
  1824. if (!this.UserData[row_id])
  1825. this.UserData[row_id] = new Hashtable()
  1826. this.UserData[row_id].put(name, value)
  1827. } catch (er) {
  1828. alert("UserData Error:" + er.description)
  1829. }
  1830. }
  1831. /**
  1832. * @desc: gets user Data
  1833. * @param: row_id - row id. if empty then user data is for grid (not row)
  1834. * @param: name - name of user data
  1835. * @returns: value of user data
  1836. * @type: public
  1837. * @topic: 2,5
  1838. */
  1839. this.getUserData = function(row_id, name) {
  1840. if (row_id == "")
  1841. row_id = "gridglobaluserdata";
  1842. var z = this.UserData[row_id];
  1843. return (z ? z.get(name) : "");
  1844. }
  1845. /**
  1846. * @desc: manage editibility of the grid
  1847. * @param: [fl] - set not editable if FALSE, set editable otherwise
  1848. * @type: public
  1849. * @topic: 7
  1850. */
  1851. this.setEditable = function(fl) {
  1852. if (fl != 'true' && fl != 1 && fl != true)
  1853. ifl = true;
  1854. else
  1855. ifl = false;
  1856. for (var j = 0; j < this.cellType.length; j++) {
  1857. if (this.cellType[j].indexOf('ra') == 0 || this.cellType[j] == 'ch') {
  1858. for (var i = 0; i < this.rowsCol.length; i++) {
  1859. var z = this.rowsCol[i].cells[j];
  1860. if ((z.childNodes.length > 0)
  1861. && (z.firstChild.nodeType == 1)) {
  1862. this.rowsCol[i].cells[j].firstChild.disabled = ifl;
  1863. }
  1864. }
  1865. }
  1866. }
  1867. this.isEditable = !ifl;
  1868. }
  1869. /**
  1870. * @desc: selects row
  1871. * @param: row_id - row id
  1872. * @param: multiFL - VOID. select multiple rows
  1873. * @param: show - VOID. scroll row to view
  1874. * @param: call - true to call function on select
  1875. * @type: public
  1876. * @topic: 1,2
  1877. */
  1878. this.setSelectedRow = function(row_id, multiFL, show, call) {
  1879. if (!call)
  1880. call = false;
  1881. this.selectCell(this.getRowById(row_id), 0, call, multiFL);// selectRow(this.getRowById(row_id),false)
  1882. if (arguments.length > 2 && show == true) {
  1883. this.moveToVisible(this.getRowById(row_id).cells[0])
  1884. }
  1885. }
  1886. /**
  1887. * @desc: removes selection from the grid
  1888. * @type: public
  1889. * @topic: 1,9
  1890. */
  1891. this.clearSelection = function() {
  1892. this.editStop()
  1893. for (var i = 0; i < this.selectedRows.length; i++) {
  1894. this.selectedRows[i].className = this.selectedRows[i].className
  1895. .replace(/rowselected/g, "");
  1896. }
  1897. // ..
  1898. this.selectedRows = new Array(0)
  1899. this.row = null;
  1900. if (this.cell != null) {
  1901. this.cell.className = this.cell.className.replace(/cellselected/g,
  1902. "");
  1903. this.cell = null;
  1904. }
  1905. }
  1906. /**
  1907. * @desc: copies row content to another existing row
  1908. * @param: from_row_id - id of the row to copy content from
  1909. * @param: to_row_id - id of the row to copy content to
  1910. * @type: public
  1911. * @topic: 2,5
  1912. */
  1913. this.copyRowContent = function(from_row_id, to_row_id) {
  1914. var frRow = this.getRowById(from_row_id)
  1915. if (!this.isTreeGrid)
  1916. for (i = 0; i < frRow.cells.length; i++) {
  1917. this.cells(to_row_id, i).setValue(this.cells(from_row_id, i)
  1918. .getValue())
  1919. }
  1920. else
  1921. this._copyTreeGridRowContent(frRow, from_row_id, to_row_id);
  1922. // for Mozilla (to avaoid visual glitches)
  1923. if (!isIE())
  1924. this.getRowById(from_row_id).cells[0].height = frRow.cells[0].offsetHeight
  1925. }
  1926. /**
  1927. * @desc: sets new column header label
  1928. * @param: col - header column index
  1929. * @param: label - new label for the cpecified header's column
  1930. * @type: public
  1931. * @topic: 3,6
  1932. */
  1933. this.setHeaderCol = function(col, label) {
  1934. if (!this.useImagesInHeader)
  1935. this.hdr.rows[0].cells[col].innerHTML = label;
  1936. else {// if images in header header
  1937. this.hdr.rows[0].cells[col].style.textAlign = "left";
  1938. this.hdr.rows[0].cells[col].innerHTML = "<img src='" + this.imgURL
  1939. + "" + label + "' onerror='this.src = \"" + this.imgURL
  1940. + "imageloaderror.gif\"'>";
  1941. // preload sorting headers (asc/desc)
  1942. var a = new Image();
  1943. a.src = this.imgURL + "" + label.replace(/(\.[a-z]+)/, ".desc$1");
  1944. this.preloadImagesAr[this.preloadImagesAr.length] = a;
  1945. var b = new Image();
  1946. b.src = this.imgURL + "" + label.replace(/(\.[a-z]+)/, ".asc$1");
  1947. this.preloadImagesAr[this.preloadImagesAr.length] = b;
  1948. }
  1949. // this.hdr.rows[0].cells[Number(col)].innerHTML = label;
  1950. }
  1951. /**
  1952. * @desc: deletes all rows in grid
  1953. * @type: public
  1954. * @topic: 5,7,9
  1955. */
  1956. this.clearAll = function() {
  1957. this.editStop();
  1958. // debugger;
  1959. var len = this.rowsCol.length;
  1960. for (var i = len - 1; i >= 0; i--) {
  1961. this.obj.firstChild.removeChild(this.rowsCol[i])// nb:this.rowsCol[i].removeNode(true);
  1962. this.rowsCol._dhx_removeAt(i);
  1963. }
  1964. // treegrid
  1965. if (this.loadedKidsHash != null) {
  1966. this.loadedKidsHash.clear();
  1967. this.loadedKidsHash.put("hashOfParents", new Hashtable());
  1968. }
  1969. // for some case
  1970. len = this.obj.rows.length
  1971. for (var i = len - 1; i >= 0; i--) {
  1972. this.obj.firstChild.removeChild(this.obj.rows[i])// nb:this.obj.rows[i].removeNode(true);
  1973. }
  1974. // ..
  1975. this.row = null;
  1976. this.cell = null;
  1977. this.rowsAr = new Array(0)
  1978. this.rowsCol = new Array(0)
  1979. this.rowsAr = new Array(0);// array of rows by idd
  1980. this.rowsBuffer = new Array(new Array(0), new Array(0));// buffer of
  1981. // rows loaded,
  1982. // but not
  1983. // rendered
  1984. // (array of
  1985. // ids, array of
  1986. // cell values
  1987. // arrays)
  1988. this.UserData = new Array(0)
  1989. this.setSizes();
  1990. // this.obj.scrollTop = 0;
  1991. }
  1992. this._sortField = function(ev) {
  1993. var el = this.getFirstParentOfType(ev.target || ev.srcElement, "TD");
  1994. this.sortField(el._cellIndex)
  1995. }
  1996. /**
  1997. * @desc: sorts grid by specified field
  1998. * @invoke: header click
  1999. * @param: [ind] - index of the field
  2000. * @param: [repeatFl] - if to repeat last sorting
  2001. * @type: private
  2002. * @topic: 3
  2003. */
  2004. this.sortField = function(ind, repeatFl) {
  2005. if ((this.onCLMS) && (!this.onCLMS(ind, this)))
  2006. return;
  2007. if (this.getRowsNum() == 0)
  2008. return false;
  2009. var el = this.hdr.rows[0].cells[ind];
  2010. if (!el)
  2011. return; // somehow
  2012. if (el.tagName == "TD" && (this.fldSort.length - 1) >= el._cellIndex
  2013. && this.fldSort[el._cellIndex] != 'na') {// this.entBox.fieldstosort!=""
  2014. // &&
  2015. if ((((this.sortImg.src.indexOf("_desc.gif") == -1) && (!repeatFl)) || ((this.sortImg.style.filter != "") && (repeatFl)))
  2016. && (this.fldSorted == el)) {// desc
  2017. var sortType = "desc";
  2018. this.sortImg.src = this.imgURL + "sort_desc.gif";
  2019. } else {// asc
  2020. var sortType = "asc";
  2021. this.sortImg.src = this.imgURL + "sort_asc.gif";
  2022. }
  2023. // for header images
  2024. if (this.useImagesInHeader) {
  2025. if (this.fldSorted != null) {
  2026. this.fldSorted.firstChild.src = this.fldSorted.firstChild.src
  2027. .replace(/\.[ascde]+\./, ".");
  2028. }
  2029. el.firstChild.src = el.firstChild.src.replace(/(\.[a-z]+)/, "."
  2030. + sortType + "$1")
  2031. }
  2032. // .
  2033. this.sortRows(el._cellIndex, this.fldSort[el._cellIndex], sortType)
  2034. this.fldSorted = el;
  2035. this.setSortImgPos();
  2036. }
  2037. }
  2038. /**
  2039. * @desc: set custom sorting (custom sort has three params -
  2040. * valueA,valueB,order; where order can be asc or des)
  2041. * @param: func - column index
  2042. * @param: col - str.int.date
  2043. * @type: public
  2044. * @edition: Professional
  2045. * @topic: 3
  2046. */
  2047. this.setCustomSorting = function(func, col) {
  2048. if (!this._customSorts)
  2049. this._customSorts = new Array();
  2050. this._customSorts[col] = func;
  2051. this.fldSort[col] = "cus";
  2052. }
  2053. /**
  2054. * @desc: specify if values passed to Header are images names
  2055. * @param: fl - true to treat column header values as image names
  2056. * @type: public
  2057. * @before_init: 1
  2058. * @topic: 0,3
  2059. */
  2060. this.enableHeaderImages = function(fl) {
  2061. this.useImagesInHeader = fl;
  2062. }
  2063. /**
  2064. * @desc: set header label and default params for new headers
  2065. * @param: hdrStr - header string with delimiters
  2066. * @type: public
  2067. * @before_init: 1
  2068. * @topic: 0,3
  2069. */
  2070. this.setHeader = function(hdrStr) {
  2071. var arLab = hdrStr.split(this.delim);
  2072. var arWdth = new Array(0);
  2073. var arTyp = new Array(0);
  2074. var arAlg = new Array(0);
  2075. var arVAlg = new Array(0);
  2076. var arSrt = new Array(0);
  2077. for (var i = 0; i < arLab.length; i++) {
  2078. arWdth[arWdth.length] = Math.round(100 / arLab.length);
  2079. arTyp[arTyp.length] = "ed";
  2080. arAlg[arAlg.length] = "left";
  2081. arVAlg[arVAlg.length] = "top";
  2082. arSrt[arSrt.length] = "na";
  2083. }
  2084. this.hdrLabels = arLab;
  2085. this.cellWidth = arWdth;
  2086. this.cellType = arTyp;
  2087. this.cellAlign = arAlg;
  2088. this.cellVAlign = arVAlg;
  2089. this.fldSort = arSrt;
  2090. }
  2091. /**
  2092. * @desc: set column types
  2093. * @param: typeStr - type codes list with default delimiter
  2094. * @before_init: 2
  2095. * @type: public
  2096. * @topic: 0,3,4
  2097. */
  2098. this.setColTypes = function(typeStr) {
  2099. this.cellType = typeStr.split(this.delim)
  2100. this._strangeParams = new Array();
  2101. for (var i = 0; i < this.cellType.length; i++)
  2102. if ((this.cellType[i].indexOf("[") != -1)) {
  2103. var z = this.cellType[i].split(/[\[\]]+/g);
  2104. this.cellType[i] = z[0];
  2105. this.defVal[i] = z[1];
  2106. if (z[1].indexOf("=") == 0) {
  2107. this.cellType[i] = "math";
  2108. this._strangeParams[i] = z[0];
  2109. }
  2110. }
  2111. }
  2112. /**
  2113. * @desc: set column sort types (avaialble: str, int, date, na)
  2114. * @param: sortStr - sort codes list with default delimiter
  2115. * @before_init: 1
  2116. * @type: public
  2117. * @topic: 0,3,4
  2118. */
  2119. this.setColSorting = function(sortStr) {
  2120. this.fldSort = sortStr.split(this.delim)
  2121. for (var i = 0; i < this.fldSort.length; i++)
  2122. if (((this.fldSort[i]).length > 4)
  2123. && (typeof(window[this.fldSort[i]]) == "function")) {
  2124. if (!this._customSorts)
  2125. this._customSorts = new Array();
  2126. this._customSorts[i] = window[this.fldSort[i]];
  2127. this.fldSort[i] = "cus";
  2128. }
  2129. }
  2130. /**
  2131. * @desc: set align of columns
  2132. * @param: alStr - align string with delimiters
  2133. * @before_init: 1
  2134. * @type: public
  2135. * @topic: 0,3
  2136. */
  2137. this.setColAlign = function(alStr) {
  2138. this.cellAlign = alStr.split(this.delim)
  2139. }
  2140. /**
  2141. * @desc: set vertical align of columns
  2142. * @param: alStr - align string with delimiters
  2143. * @before_init: 1
  2144. * @type: public
  2145. * @topic: 0,3
  2146. */
  2147. this.setColVAlign = function(alStr) {
  2148. this.cellVAlign = alStr.split(this.delim)
  2149. }
  2150. /**
  2151. * @desc: sets grid to multiline row support (call before init)
  2152. * @param: fl - true to set multiline support
  2153. * @type: deprecated
  2154. * @before_init: 1
  2155. * @topic: 0,2
  2156. */
  2157. this.setMultiLine = function(fl) {
  2158. if (fl == true)
  2159. this.multiLine = -1;
  2160. }
  2161. /**
  2162. * @desc: use to create grid with no header
  2163. * @param: fl - true to use no header in the grid
  2164. * @type: public
  2165. * @before_init: 1
  2166. * @topic: 0,7
  2167. */
  2168. this.setNoHeader = function(fl) {
  2169. if (fl == true)
  2170. this.noHeader = -1;
  2171. }
  2172. /**
  2173. * @desc: scrolls row to the visible area
  2174. * @param: rowID - row id
  2175. * @type: public
  2176. * @topic: 2,7
  2177. */
  2178. this.showRow = function(rowID) {
  2179. this.moveToVisible(this.getRowById(rowID).cells[0])
  2180. }
  2181. /**
  2182. * @desc: modify default style of grid and its elements. Call before or
  2183. * after Init
  2184. * @param: ss_header - style def. expression for header
  2185. * @param: ss_grid - style def. expression for grid cells
  2186. * @param: ss_selCell - style def. expression for selected cell
  2187. * @param: ss_selRow - style def. expression for selected Row
  2188. * @type: public
  2189. * @before_init: 2
  2190. * @topic: 0,6
  2191. */
  2192. this.setStyle = function(ss_header, ss_grid, ss_selCell, ss_selRow) {
  2193. this.ssModifier = new Array(4)
  2194. this.ssModifier[0] = ss_header;
  2195. this.ssModifier[1] = ss_grid;
  2196. this.ssModifier[2] = ss_selCell;
  2197. this.ssModifier[3] = ss_selRow;
  2198. this.styleSheet[0].addRule("#" + this.entBox.id + " table.hdr td",
  2199. this.ssHeader + "" + this.ssModifier[0]);
  2200. this.styleSheet[0].addRule("#" + this.entBox.id + " table.obj td",
  2201. this.ssGridCell + "" + this.ssModifier[1]);
  2202. this.styleSheet[0].addRule("#" + this.entBox.id
  2203. + " table.obj tr.rowselected td.cellselected",
  2204. this.ssSelectedCell + "" + this.ssModifier[2]);
  2205. this.styleSheet[0].addRule("#" + this.entBox.id
  2206. + " table.obj td.cellselected", this.ssSelectedCell
  2207. + "" + this.ssModifier[2])
  2208. this.styleSheet[0].addRule("#" + this.entBox.id
  2209. + " table.obj tr.rowselected td", this.ssSelectedRow
  2210. + "" + this.ssModifier[3]);
  2211. }
  2212. /**
  2213. * @desc: colorize columns.
  2214. * @param: clr - colors list
  2215. * @type: public
  2216. * @before_init: 1
  2217. * @topic: 3,6
  2218. */
  2219. this.setColumnColor = function(clr) {
  2220. this.columnColor = clr.split(this.delim)
  2221. }
  2222. /**
  2223. * @desc: set even/odd css styles
  2224. * @param: cssE - name of css class for even rows
  2225. * @param: cssU - name of css class for odd rows
  2226. * @type: public
  2227. * @edition: Professional
  2228. * @before_init: 1
  2229. * @topic: 3,6
  2230. */
  2231. this.enableAlterCss = function(cssE, cssU) {
  2232. if (cssE || cssU)
  2233. this.setOnGridReconstructedHandler(function() {
  2234. this._fixAlterCss();
  2235. });
  2236. this._cssEven = cssE;
  2237. this._cssUnEven = cssU;
  2238. }
  2239. /**
  2240. * @desc: recolor grid from defined point
  2241. * @type: private
  2242. * @before_init: 1
  2243. * @topic: 3,6
  2244. */
  2245. this._fixAlterCss = function(ind) {
  2246. ind = ind || 0;
  2247. var j = ind;
  2248. for (var i = ind; i < this.rowsCol.length; i++)
  2249. if (this.rowsCol[i].style.display != "none") {
  2250. if (this.rowsCol[i].className.indexOf("rowselected") != -1) {
  2251. if (j % 2 == 1)
  2252. this.rowsCol[i].className = this._cssUnEven
  2253. + " rowselected";
  2254. else
  2255. this.rowsCol[i].className = this._cssEven
  2256. + " rowselected";
  2257. } else {
  2258. if (j % 2 == 1)
  2259. this.rowsCol[i].className = this._cssUnEven;
  2260. else
  2261. this.rowsCol[i].className = this._cssEven;
  2262. }
  2263. j++;
  2264. }
  2265. }
  2266. /**
  2267. * @desc: dynamicaly scrolls grid content.
  2268. * @param: fl - if no fl initializes dynamic scroll, if up scroll page up,
  2269. * if dn scrolls page down
  2270. * @type: public
  2271. * @topic: 0,6,7,9
  2272. */
  2273. this.doDynScroll = function(fl) {
  2274. if (!this.dynScroll || this.dynScroll == 'false')
  2275. return false;
  2276. this.objBox.style.overflowY = "hidden";
  2277. this.setDynScrollPageSize();
  2278. var tmpAr = new Array(0)
  2279. if (fl && fl == 'up') {
  2280. this.dynScrollPos = Math.max(this.dynScrollPos
  2281. - this.dynScrollPageSize, 0);
  2282. } else if (fl
  2283. && fl == 'dn'
  2284. && this.dynScrollPos + this.dynScrollPageSize < this.rowsCol.length) {
  2285. if (this.dynScrollPos + this.dynScrollPageSize
  2286. + this.rowsBufferOutSize > this.rowsCol.length) {
  2287. this.addRowsFromBuffer()
  2288. }
  2289. this.dynScrollPos += this.dynScrollPageSize
  2290. }
  2291. var start = Math.max(this.dynScrollPos - this.dynScrollPageSize, 0);
  2292. for (var i = start; i < this.rowsCol.length; i++) {
  2293. if (i >= this.dynScrollPos
  2294. && i < this.dynScrollPos + this.dynScrollPageSize) {
  2295. tmpAr[tmpAr.length] = this.rowsCol[i];
  2296. }
  2297. this.rowsCol[i].removeNode(true);
  2298. }
  2299. for (var i = 0; i < tmpAr.length; i++) {
  2300. this.obj.childNodes[0].appendChild(tmpAr[i]);
  2301. if (this.obj.offsetHeight > this.objBox.offsetHeight)
  2302. this.dynScrollPos -= (this.dynScrollPageSize - i)
  2303. }
  2304. this.setSizes()
  2305. }
  2306. /**
  2307. * @desc: counts the number of rows to fit the grid for dyn scroll
  2308. * @type: private
  2309. * @topic: 0
  2310. */
  2311. this.setDynScrollPageSize = function() {
  2312. if (this.dynScroll && this.dynScroll != 'false') {
  2313. var rowsH = 0;
  2314. try {
  2315. var rowH = this.obj.rows[0].scrollHeight;
  2316. } catch (er) {
  2317. var rowH = 20
  2318. }
  2319. for (var i = 0; i < 1000; i++) {
  2320. rowsH = i * rowH;
  2321. if (this.objBox.offsetHeight < rowsH)
  2322. break
  2323. }
  2324. this.dynScrollPageSize = i + 2;// parseInt(i/3.5);
  2325. this.rowsBufferOutSize = this.dynScrollPageSize * 4
  2326. }
  2327. }
  2328. /*
  2329. * @BLOCKSTART: SERIALIZATION
  2330. */
  2331. this._sUDa = false;
  2332. this._sAll = false;
  2333. /**
  2334. * @desc: configure XML serialization
  2335. * @type: public
  2336. * @edition: Professional
  2337. * @param: userData - enable/disable user data serialization
  2338. * @param: fullXML - enable/disable full XML serialization (selection state)
  2339. * @param: config - serialize grid configuration
  2340. * @topic: 0,5,7
  2341. */
  2342. this.setSerializationLevel = function(userData, fullXML, config) {
  2343. this._sUDa = userData;
  2344. this._sAll = fullXML;
  2345. this._sConfig = config;
  2346. }
  2347. /**
  2348. * @desc: configure which column must be serialized
  2349. * @type: public
  2350. * @edition: Professional
  2351. * @param: list - list of true/false values separated by comma, if list
  2352. * empty then all fields will be serialized
  2353. * @topic: 0,5,7
  2354. */
  2355. this.setSerializableColumns = function(list) {
  2356. if (!list) {
  2357. this._srClmn = null;
  2358. return;
  2359. }
  2360. this._srClmn = (list || "").split(",");
  2361. for (var i = 0; i < this._srClmn.length; i++)
  2362. this._srClmn[i] = convertStringToBoolean(this._srClmn[i]);
  2363. }
  2364. this._serialise = function(rCol, inner, closed) {
  2365. this.editStop()
  2366. var out = "";
  2367. // rows collection
  2368. var i = 0;
  2369. var j = 0;
  2370. for (i; i < rCol.length; i++) {
  2371. var r = rCol[i];
  2372. var selStr = "";
  2373. // serialize selection
  2374. if (this._sAll && this.selectedRows._dhx_find(r) != -1)
  2375. selStr = " selected='1'";
  2376. out += "<row id='" + r.idd + "'" + selStr + " "
  2377. + ((r.expand == "") ? "open='1'" : "") + ">";
  2378. // userdata
  2379. if (this._sUDa && this.UserData[r.idd]) {
  2380. keysAr = this.UserData[r.idd].getKeys()
  2381. for (var ii = 0; ii < keysAr.length; ii++) {
  2382. out += "<userdata name='" + keysAr[ii] + "'>"
  2383. + this.UserData[r.idd].get(keysAr[ii])
  2384. + "</userdata>";
  2385. }
  2386. }
  2387. // cells
  2388. for (var jj = 0; jj < r.childNodes.length; jj++) {
  2389. if ((!this._srClmn) || (this._srClmn[jj])) {
  2390. var zx = this.cells(r.idd, jj)[this._agetm]();
  2391. if (this._sAll)
  2392. out += "<cell"
  2393. + (r.childNodes[jj]._aimage ? (" image='"
  2394. + r.childNodes[jj]._aimage + "'") : "")
  2395. + ">" + ((zx === null) ? "" : zx) + "</cell>";
  2396. else
  2397. out += "<cell>" + ((zx === null) ? "" : zx) + "</cell>";
  2398. }
  2399. }
  2400. if (this.loadedKidsHash) {
  2401. var z = this.loadedKidsHash.get(r.idd);
  2402. if (z) {
  2403. temp = this._serialise(z, 1, closed || r.expand !== "");
  2404. out += temp[0];
  2405. if ((!closed) && (r.expand === ""))
  2406. if (!inner)
  2407. i += temp[1];
  2408. else
  2409. j += temp[1];
  2410. }
  2411. }
  2412. out += "</row>";
  2413. }
  2414. return [out, j + i];
  2415. }
  2416. this._serialiseConfig = function() {
  2417. var out = "<head>";
  2418. for (var i = 0; i < this.hdr.rows[0].cells.length; i++) {
  2419. out += "<colum width='" + this.cellWidthPX[i] + "' align='"
  2420. + this.cellAlign[i] + "' type='" + this.cellType[i]
  2421. + "' sort='" + this.fldSort[i] + "' color='"
  2422. + this.columnColor[i] + "'>";
  2423. out += this.hdr.rows[0].cells[i].innerHTML;
  2424. var z = this.getCombo(i);
  2425. if (z)
  2426. for (var j = 0; j < z.keys.length; j++)
  2427. out += "<option value='" + z.keys[j] + "'>" + z.values[j]
  2428. + "<option>";
  2429. out += "</column>"
  2430. }
  2431. return out += "</head>";
  2432. }
  2433. /**
  2434. * @desc: return actual xml of grid
  2435. * @type: public
  2436. * @edition: Professional
  2437. * @topic: 5,7
  2438. */
  2439. this.serialize = function() {
  2440. var out = '<?xml version="1.0"?><rows>';
  2441. if (this._mathSerialization)
  2442. this._agetm = "getMathValue";
  2443. else
  2444. this._agetm = "getValue";
  2445. if (this._sUDa && this.UserData["gridglobaluserdata"]) {
  2446. var keysAr = this.UserData["gridglobaluserdata"].getKeys()
  2447. for (var i = 0; i < keysAr.length; i++) {
  2448. out += "<userdata name='" + keysAr[i] + "'>"
  2449. + this.UserData["gridglobaluserdata"].get(keysAr[i])
  2450. + "</userdata>";
  2451. }
  2452. }
  2453. if (this._sConfig)
  2454. out += this._serialiseConfig();
  2455. out += this._serialise(this.rowsCol)[0];
  2456. // rows buffer
  2457. var xmlSerializer;
  2458. if (!isIE()) {
  2459. xmlSerializer = new XMLSerializer();
  2460. }
  2461. for (var i = 0; i < this.rowsBuffer[1].length; i++) {
  2462. if (!xmlSerializer)// ie
  2463. out += this.rowsBuffer[1][i].xml;
  2464. else {// mozilla
  2465. out += xmlSerializer.serializeToString(this.rowsBuffer[1][i]);
  2466. }
  2467. }
  2468. out += '</rows>';
  2469. return out;
  2470. }
  2471. /*
  2472. * ================================================================================
  2473. * @BLOCKEND
  2474. */
  2475. this.dhx_attachEvent = function(original, catcher) {
  2476. // alert("2379 original = " + original)
  2477. if ((!this[original]) || (!this[original].dhx_addEvent)) {
  2478. var z = new this.dhx_eventCatcher();
  2479. z.dhx_addEvent(this[original]);
  2480. this[original] = z;
  2481. }
  2482. this[original].dhx_addEvent(catcher);
  2483. }
  2484. this.dhx_eventCatcher = function() {
  2485. var dhx_catch = new Array();
  2486. var z = function() {
  2487. if (dhx_catch)
  2488. var res = true;
  2489. for (var i = 0; i < dhx_catch.length; i++)
  2490. if (!dhx_catch[i].apply(this, arguments))
  2491. res = false;
  2492. return res;
  2493. }
  2494. z.dhx_addEvent = function(ev) {
  2495. if (typeof(ev) != "function")
  2496. ev = eval(ev);
  2497. if (ev)
  2498. dhx_catch[dhx_catch.length] = ev;
  2499. }
  2500. return z;
  2501. }
  2502. /* SET EVENT HANDLERS */
  2503. /**
  2504. * @desc: set function called when row selected
  2505. * @param: func - event handling function (or its name)
  2506. * @type: public
  2507. * @topic: 10
  2508. * @event: onRowSelect
  2509. * @eventdesc: Event raised immideatly after row was clicked.
  2510. * @eventparam: ID of clicked row
  2511. */
  2512. this.setOnRowSelectHandler = function(func) {
  2513. this.dhx_attachEvent("onRowSelect", func);
  2514. }
  2515. /**
  2516. * @desc: set function called when row added/deleted or grid reordered
  2517. * @param: func - event handling function (or its name)
  2518. * @type: public
  2519. * @topic: 10
  2520. * @event: OnGridReconstructed
  2521. * @eventdesc: Event raised immideatly after row was clicked.
  2522. * @eventparam: grid object
  2523. */
  2524. this.setOnGridReconstructedHandler = function(func) {
  2525. this.dhx_attachEvent("onGridReconstructed", func);
  2526. }
  2527. /**
  2528. * @desc: set function called on grid scrolling
  2529. * @param: func - event handling function (or its name)
  2530. * @type: public
  2531. * @topic: 10
  2532. * @event: onScroll
  2533. * @eventdesc: Event raised immideatly after scrolling occured
  2534. * @eventparam: scroll left
  2535. * @eventparam: scroll top
  2536. */
  2537. this.setOnScrollHandler = function(func) {
  2538. this.dhx_attachEvent("_onSCRL", func);
  2539. }
  2540. /**
  2541. * @desc: set function called when cell editted
  2542. * @param: func - event handling function (or its name)
  2543. * @type: public
  2544. * @topic: 10
  2545. * @event: onEditCell
  2546. * @eventdesc: Event raises 1-3 times depending on cell editibality.
  2547. * @eventparam: stage of editting (0-before start[can be canceled if returns
  2548. * false],1-editor opened,2-editor closed)
  2549. * @eventparam: ID or row
  2550. * @eventparam: index of cell
  2551. */
  2552. this.setOnEditCellHandler = function(func) {
  2553. this.dhx_attachEvent("onEditCell", func);
  2554. }
  2555. /**
  2556. * @desc: set function called when checkbox or radiobutton was clicked
  2557. * @param: func - event handling function (or its name)
  2558. * @type: public
  2559. * @topic: 10
  2560. * @event: onCheck
  2561. * @eventdesc: Event raises after state was changed.
  2562. * @eventparam: ID or row
  2563. * @eventparam: index of cell
  2564. * @eventparam: state of checkbox/radiobutton
  2565. */
  2566. this.setOnCheckHandler = function(func) {
  2567. this.dhx_attachEvent("onCheckbox", func);
  2568. }
  2569. /**
  2570. * @desc: set function called when user press Enter
  2571. * @param: func - event handling function (or its name)
  2572. * @type: public
  2573. * @topic: 10
  2574. * @event: onEnterPressed
  2575. * @eventdesc: Event raised immideatly after Enter pressed.
  2576. * @eventparam: ID or row
  2577. * @eventparam: index of cell
  2578. */
  2579. this.setOnEnterPressedHandler = function(func) {
  2580. this.dhx_attachEvent("onEnter", func);
  2581. }
  2582. /**
  2583. * @desc: set function called before row removed from grid
  2584. * @param: func - event handling function (or its name)
  2585. * @type: public
  2586. * @topic: 10
  2587. * @event: onBeforeRowDeleted
  2588. * @eventdesc: Event raised right before row deleted (if returns false,
  2589. * deletion canceled)
  2590. * @eventparam: ID or row
  2591. */
  2592. this.setOnBeforeRowDeletedHandler = function(func) {
  2593. this.dhx_attachEvent("onBeforeRowDeleted", func);
  2594. }
  2595. /**
  2596. * @desc: set function called after row added to grid
  2597. * @param: func - event handling function (or its name)
  2598. * @type: public
  2599. * @topic: 10
  2600. * @event: onRowAdded
  2601. * @eventdesc: Event raised right after row was added to grid
  2602. * @eventparam: ID or row
  2603. */
  2604. this.setOnRowAddedHandler = function(func) {
  2605. this.dhx_attachEvent("onRowAdded", func);
  2606. }
  2607. /**
  2608. * @desc: set function called when row was dbl clicked
  2609. * @param: func - event handling function (or its name)
  2610. * @type: public
  2611. * @topic: 10
  2612. * @edition: Professional
  2613. * @event: onRowDblClicked
  2614. * @eventdesc: Event raised right after row was double clicked, before cell
  2615. * editor opened by dbl click. If retuns false, event canceled;
  2616. * @eventparam: ID or row
  2617. */
  2618. this.setOnRowDblClickedHandler = function(func) {
  2619. this.dhx_attachEvent("onRowDblClicked", func);
  2620. }
  2621. /* TOOLS METHODS */
  2622. /**
  2623. * @desc: creates XML object from what was returned from specified URL (if
  2624. * possible)
  2625. * @returns: MS XML object
  2626. * @param: url - url of the xml formated page
  2627. * @type: private
  2628. * @topic: 8
  2629. */
  2630. /*
  2631. * this.loadXML = function(url){ if(/\?/g.test(url)) var s = "&"; else var s =
  2632. * "?"; var xmlDoc = new ActiveXObject("microsoft.XMLDOM"); xmlDoc.async =
  2633. * false;
  2634. * xmlDoc.load(url+""+s+"rowsLoaded="+this.getRowsNum()+"&"+Date.parse(new
  2635. * Date())) return xmlDoc; }
  2636. */
  2637. /**
  2638. * @desc: returns absolute left and top position of specified element
  2639. * @returns: array of two values: absolute Left and absolute Top positions
  2640. * @param: oNode - element to get position of
  2641. * @type: private
  2642. * @topic: 8
  2643. */
  2644. this.getPosition = function(oNode, pNode) {
  2645. if (!pNode)
  2646. var pNode = document.body
  2647. var oCurrentNode = oNode;
  2648. var iLeft = 0;
  2649. var iTop = 0;
  2650. while ((oCurrentNode) && (oCurrentNode != pNode)) {// .tagName!="BODY"){
  2651. iLeft += oCurrentNode.offsetLeft;
  2652. iTop += oCurrentNode.offsetTop;
  2653. oCurrentNode = oCurrentNode.offsetParent;// isIE()?:oCurrentNode.parentNode;
  2654. }
  2655. if (((_isKHTML) || (_isOpera)) && (pNode == document.body)) {
  2656. iLeft += document.body.offsetLeft;
  2657. iTop += document.body.offsetTop;
  2658. }
  2659. return new Array(iLeft, iTop);
  2660. }
  2661. /**
  2662. * @desc: gets nearest parent of specified type
  2663. * @param: obj - input object
  2664. * @param: tag - string. tag to find as parent
  2665. * @returns: object. nearest paraent object (including spec. obj) of
  2666. * specified type.
  2667. * @type: private
  2668. * @topic: 8
  2669. */
  2670. this.getFirstParentOfType = function(obj, tag) {
  2671. while (obj.tagName != tag && obj.tagName != "BODY") {
  2672. obj = obj.parentNode;
  2673. }
  2674. return obj;
  2675. }
  2676. /* METHODS deprecated */
  2677. /**
  2678. * @desc: deprecated. sets number of columns
  2679. * @param: cnt - number of columns
  2680. * @type: void
  2681. * @topic: 3,7
  2682. */
  2683. this.setColumnCount = function(cnt) {
  2684. alert('setColumnCount method deprecated')
  2685. }
  2686. /**
  2687. * @desc: deprecated. repaint of the grid
  2688. * @topic: 7
  2689. * @type: void
  2690. */
  2691. this.showContent = function() {
  2692. alert('showContent method deprecated')
  2693. }
  2694. /* INTERNAL EVENT HANDLERS */
  2695. this.objBox.onscroll = new Function("", "this.grid._doOnScroll()")
  2696. if (!_isOpera) {
  2697. this.hdr.onmousemove = new Function("e",
  2698. "this.grid.changeCursorState(e||window.event)");
  2699. this.hdr.onmousedown = new Function("e",
  2700. "this.grid.startColResize(e||window.event)");
  2701. }
  2702. this.obj.onmousemove = new Function(
  2703. "e",
  2704. "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;");
  2705. this.obj.onclick = new Function(
  2706. "e",
  2707. "this.grid._doClick(e||window.event); if (this.grid._sclE) this.grid.editCell(e||window.event) ");
  2708. this.entBox.onmousedown = new Function("e",
  2709. "return this.grid._doContClick(e||window.event);");
  2710. this.obj.ondblclick = new Function(
  2711. "e",
  2712. "if(!this.grid.wasDblClicked(e||window.event)){return false}; if (this.grid._dclE) this.grid.editCell(e||window.event)");
  2713. this.hdr.onclick = new Function("e",
  2714. "if(this.grid.resized==null)this.grid._sortField(e||window.event);");
  2715. // VOID this.grid.ondblclick = this.onDoubleClick;
  2716. document.onkeydown = new Function(
  2717. "e",
  2718. "if (globalActiveDHTMLGridObject) return globalActiveDHTMLGridObject.doKey(e||window.event); return true;");
  2719. // nb:document.body.attachEvent("onclick",new
  2720. // Function("","if(this.document.getElementById('"+this.entBox.id+"').grid.isActive==-1)this.document.getElementById('"+this.entBox.id+"').grid.setActive(false)"))
  2721. // activity management
  2722. this.entBox.onbeforeactivate = new Function("", "this.grid.setActive()");
  2723. this.entBox.onbeforedeactivate = new Function("", "this.grid.isActive=-1");
  2724. // postprocessing events (method can be redeclared to react on some events
  2725. // during processing)
  2726. this.doOnRowAdded = function(row) {
  2727. };
  2728. // ========add by sunzhigang 2007 11 22==============================
  2729. this._eSplit = function(str) {
  2730. if (![].push)
  2731. return str.split(this.delim);
  2732. var a = "r" + (allGetServerTime()).valueOf();
  2733. var z = this.delim.replace(/([ \|\+\*\^])/g, "\\$1")
  2734. return (str || "").replace(RegExp(z, "g"), a).replace(
  2735. RegExp("\\\\" + a, "g"), this.delim).split(a)
  2736. };
  2737. // =======================================
  2738. }
  2739. dhtmlXGridObject.prototype.isTreeGrid = function() {
  2740. return (this.cellType._dhx_find("tree") != -1);
  2741. }
  2742. /**
  2743. * @desc: adds row to the specified position
  2744. * @param: new_id - id for new row
  2745. * @param: text - Array of values or String(with delimiter as in delimiter
  2746. * parameter)
  2747. * @param: [ind] - index of row (0 by default)
  2748. * @returns: new row dom object
  2749. * @type: public
  2750. * @topic: 2
  2751. */
  2752. dhtmlXGridObject.prototype.addRow = function(new_id, text, ind) {
  2753. var r = this._addRow(new_id, text, ind);
  2754. if (typeof(this.onRowAdded) == 'function') {
  2755. this.onRowAdded(new_id);
  2756. }
  2757. this.setSizes();
  2758. return r;
  2759. }
  2760. /**
  2761. * @desc: adds row to the specified position
  2762. * @param: new_id - id for new row
  2763. * @param: text - Array of values or String(with delimiter as in delimiter
  2764. * parameter)
  2765. * @param: [ind] - index of row (0 by default)
  2766. * @returns: new row dom object
  2767. * @type: private
  2768. * @topic: 2
  2769. */
  2770. dhtmlXGridObject.prototype._addRow = function(new_id, text, ind) {
  2771. if (ind < 0)
  2772. ind = this.obj.rows.length;
  2773. this.math_off = true;
  2774. this.math_req = false;
  2775. if ((arguments.length < 3) || (ind === window.undefined))
  2776. ind = this.rowsCol.length// getRowsNum();
  2777. else {
  2778. if (ind > this.rowsCol.length)
  2779. ind = this.rowsCol.length;
  2780. }
  2781. if (typeof(text) != 'object')
  2782. text = text.split(this.delim)
  2783. if ((!this.dynScroll || this.dynScroll == 'false' || ind < this.obj.rows.length)
  2784. && ((ind) || (ind == 0))) {
  2785. if (_isKHTML)
  2786. if (ind == this.obj.rows.length) {
  2787. var r = document.createElement("TR");
  2788. this.obj.appendChild(r);
  2789. } else {
  2790. var r = document.createElement("TR");
  2791. this.obj.rows[ind].parentNode.insertBefore(r,
  2792. this.obj.rows[ind]);
  2793. }
  2794. else if (ind == this.obj.rows.length)
  2795. var r = this.obj.insertRow(ind);
  2796. else
  2797. var r = this.obj.insertRow(ind);
  2798. }
  2799. if (this.multiLine != true)
  2800. this.obj.className += " row20px";
  2801. r.idd = new_id;
  2802. r.grid = this;
  2803. for (var i = 0; i < this.hdr.rows[0].cells.length; i++) {
  2804. var c = r.insertCell(i)
  2805. // #cell_id:11052006{
  2806. if (this._enbCid)
  2807. c.id = "c_" + r.idd + "_" + i;
  2808. // #}
  2809. c._cellIndex = i;
  2810. if (this.dragAndDropOff)
  2811. this.dragger.addDraggableItem(c, this);
  2812. c.align = this.cellAlign[i];
  2813. c.style.verticalAlign = this.cellVAlign[i];
  2814. // add color to column
  2815. c.bgColor = this.columnColor[i] || ""
  2816. this.editStop();
  2817. if ((i < text.length) || (this.defVal[i])) {
  2818. var val = text[i]
  2819. if ((this.defVal[i]) && ((val == "") || (val === window.undefined)))
  2820. val = this.defVal[i];
  2821. eval("this.editor = new eXcell_" + this.cellType[i] + "(c)");
  2822. this.editor.setValue(val)
  2823. this.editor = this.editor.destructor();
  2824. } else {
  2825. var val = "&nbsp;";
  2826. c.innerHTML = val;
  2827. c._clearCell = true;
  2828. }
  2829. }
  2830. if (this._hrrar) {
  2831. var zl = this.hdr.rows[0].cells.length;
  2832. for (var i = 0; i < zl; i++)
  2833. if (this._hrrar[i])
  2834. r.childNodes[i].style.display = "none";
  2835. }
  2836. this.rowsAr[new_id] = r;
  2837. this.rowsCol._dhx_insertAt(ind, r);
  2838. if (this._cssEven) {
  2839. if (ind % 2 == 1)
  2840. r.className += " " + this._cssUnEven;
  2841. else
  2842. r.className += " " + this._cssEven;
  2843. if (ind != (this.rowsCol.length - 1))
  2844. this._fixAlterCss(ind + 1);
  2845. }
  2846. /*
  2847. * else{ r.removeNode(true) }
  2848. */
  2849. // this.chngCellWidth(ind)
  2850. this.doOnRowAdded(r);
  2851. this.math_off = false;
  2852. if ((this.math_req) && (!this._parsing_)) {
  2853. for (var i = 0; i < this.hdr.rows[0].cells.length; i++)
  2854. this._checkSCL(r.childNodes[i]);
  2855. }
  2856. return r;
  2857. }
  2858. /**
  2859. * @desc: hide/show row (warning! - this command doesn't affect row indexes,
  2860. * only visual appearance)
  2861. * @param: ind - column index
  2862. * @param: state - true/false - hide/show column
  2863. * @type: public
  2864. * @edition: Professional
  2865. */
  2866. dhtmlXGridObject.prototype.setRowHidden = function(id, state) {
  2867. var f = convertStringToBoolean(state);
  2868. var ind = this.getRowIndex(id);
  2869. if (id < 0)
  2870. return;
  2871. var row = this.rowsCol[ind];
  2872. if (row.expand === "")
  2873. this.collapseKids(row);
  2874. if ((state) && (row.style.display != "none")) {
  2875. row.style.display = "none";
  2876. var z = this.selectedRows._dhx_find(row);
  2877. if (z != -1) {
  2878. row.className = row.className.replace("rowselected", "");
  2879. for (var i = 0; i < row.childNodes.length; i++)
  2880. row.childNodes[i].className = row.childNodes[i].className
  2881. .replace(/cellselected/g, "");
  2882. this.selectedRows._dhx_removeAt(z);
  2883. }
  2884. if (this.onGridReconstructed)
  2885. this.onGridReconstructed();
  2886. }
  2887. if ((!state) && (row.style.display == "none")) {
  2888. row.style.display = "";
  2889. if (this.onGridReconstructed)
  2890. this.onGridReconstructed();
  2891. }
  2892. }
  2893. /**
  2894. * @desc: hide/show column
  2895. * @param: ind - column index
  2896. * @param: state - true/false - hide/show column
  2897. * @type: public
  2898. * @edition: Professional
  2899. */
  2900. dhtmlXGridObject.prototype.setColumnHidden = function(ind, state) {
  2901. // ===========2007/11/26=============
  2902. var anchors = document.getElementsByTagName("td");// ��ӵ�
  2903. if ((this.fldSorted) && (this.fldSorted.cellIndex == ind) && (state))
  2904. this.sortImg.style.display = "none";
  2905. var f = convertStringToBoolean(state);
  2906. if (f) {
  2907. if (!this._hrrar)
  2908. this._hrrar = new Array();
  2909. else if (this._hrrar[ind])
  2910. return;
  2911. this._hrrar[ind] = "display:none;";
  2912. this._hideShowColumn(ind, "none");
  2913. // ================2007/11/26=====add by xiaoxiao while hide the
  2914. // filtrate-div ..........
  2915. for (var i = 0; i < anchors.length; i++) {// ��ӵ�
  2916. anchor = anchors[i];
  2917. if (anchor.getAttribute("_cellIndexS") == ind) {
  2918. anchor.style.display = "none";
  2919. anchor.childNodes[0].style.display = "none";
  2920. // alert(anchor.childNodes[0]);
  2921. return;
  2922. }
  2923. }
  2924. } else {
  2925. if ((!this._hrrar) || (!this._hrrar[ind]))
  2926. return;
  2927. this._hrrar[ind] = "";
  2928. this._hideShowColumn(ind, "");
  2929. // =============2007/11/26=======add by xiaoxiao while show the
  2930. // filtrate-div ..........
  2931. for (var i = 0; i < anchors.length; i++) {// ��ӵ�
  2932. anchor = anchors[i];
  2933. if (anchor.getAttribute("_cellIndexS") == ind) {
  2934. anchor.style.display = "";
  2935. anchor.childNodes[0].style.display = "";
  2936. return;
  2937. }
  2938. }
  2939. }
  2940. if ((this.fldSorted) && (this.fldSorted.cellIndex == ind) && (!state))
  2941. this.sortImg.style.display = "inline";
  2942. }
  2943. /**
  2944. * @desc: get show/hidden status of column
  2945. * @param: ind - column index
  2946. * @type: public
  2947. * @returns: if column hidden then true else false
  2948. * @edition: Professional
  2949. */
  2950. dhtmlXGridObject.prototype.isColumnHidden = function(ind) {
  2951. if ((this._hrrar) && (this._hrrar[ind]))
  2952. return true;
  2953. return false;
  2954. }
  2955. /**
  2956. * @desc: set list of visible columns
  2957. * @param: list - list of true/false separated by comma
  2958. * @type: public
  2959. * @edition: Professional
  2960. * @topic:0
  2961. */
  2962. dhtmlXGridObject.prototype.setColHidden = function(list) {
  2963. this._ivizcol = list.split(",");
  2964. }
  2965. /**
  2966. * @desc: hide column
  2967. * @param: ind - column index
  2968. * @param: state - hide/show
  2969. * @type: private
  2970. * @edition: Professional
  2971. */
  2972. dhtmlXGridObject.prototype._hideShowColumn = function(ind, state) {
  2973. if (state == "none") {
  2974. this.hdr.rows[0].cells[ind]._oldWidth = this.hdr.rows[0].cells[ind].style.width;
  2975. this.hdr.rows[0].cells[ind]._oldWidthP = this.cellWidthPC[ind];
  2976. if (this.obj.rows.length)
  2977. this.obj.rows[0].cells[ind].style.width = "0px";
  2978. this.hdr.rows[0].cells[ind].style.width = "0px";
  2979. if (this.cellWidthPX[ind])
  2980. this.cellWidthPX[ind] = 0;
  2981. if (this.cellWidthPC[ind])
  2982. this.cellWidthPC[ind] = 0;
  2983. } else {
  2984. if (this.hdr.rows[0].cells[ind]._oldWidth) {
  2985. var zrow = this.hdr.rows[0].cells[ind];
  2986. if (this.obj.rows.length)
  2987. this.obj.rows[0].cells[ind].style.width = this.hdr.rows[0].cells[ind]._oldWidth;
  2988. zrow.style.width = zrow._oldWidth;
  2989. if (zrow._oldWidthP)
  2990. this.cellWidthPC[ind] = zrow._oldWidthP;
  2991. if (zrow._oldWidth)
  2992. this.cellWidthPX[ind] = parseInt(zrow._oldWidth);
  2993. }
  2994. }
  2995. this.setSizes();
  2996. for (var i = 0; i < this.rowsCol.length; i++)
  2997. this.rowsCol[i].childNodes[ind].style.display = state;
  2998. this.hdr.rows[0].childNodes[ind].style.display = state;
  2999. this.setSizes();
  3000. }
  3001. /**
  3002. * @desc: enable/disable hovering row under mouse
  3003. * @param: mode - true/false
  3004. * @param: cssClass - css class for hovered row
  3005. * @type: public
  3006. * @edition: Professional
  3007. */
  3008. dhtmlXGridObject.prototype.enableRowsHover = function(mode, cssClass) {
  3009. this._hvrCss = cssClass;
  3010. if (convertStringToBoolean(mode)) {
  3011. if (!this._elmnh) {
  3012. this.obj._honmousemove = this.obj.onmousemove;
  3013. this.obj.onmousemove = this._setRowHover;
  3014. if (_isIE)
  3015. this.obj.onmouseleave = this._unsetRowHover;
  3016. else
  3017. this.obj.onmouseout = this._unsetRowHover;
  3018. this._elmnh = true;
  3019. }
  3020. } else {
  3021. if (this._elmnh) {
  3022. this.obj.onmousemove = this.obj._honmousemove;
  3023. if (_isIE)
  3024. this.obj.onmouseleave = null;
  3025. else
  3026. this.obj.onmouseout = null;
  3027. this._elmnh = false;
  3028. }
  3029. }
  3030. };
  3031. /**
  3032. * @desc: enable/disable events which fire excell editing, mutual exclusive with
  3033. * enableLightMouseNavigation
  3034. * @param: click - true/false - enable/disable editing by single click
  3035. * @param: dblclick - true/false - enable/disable editing by double click
  3036. * @param: f2Key - enable/disable editing by pressing F2 key
  3037. * @type: public
  3038. * @edition: Professional
  3039. */
  3040. dhtmlXGridObject.prototype.enableEditEvents = function(click, dblclick, f2Key) {
  3041. this._sclE = convertStringToBoolean(click);
  3042. this._dclE = convertStringToBoolean(dblclick);
  3043. this._f2kE = convertStringToBoolean(f2Key);
  3044. }
  3045. /**
  3046. * @desc: enable/disable light mouse navigation mode (row selection with mouse
  3047. * over, editing with single click), mutual exclusive with
  3048. * enableEditEvents
  3049. * @param: mode - true/false
  3050. * @type: public
  3051. * @edition: Professional
  3052. */
  3053. dhtmlXGridObject.prototype.enableLightMouseNavigation = function(mode) {
  3054. if (convertStringToBoolean(mode)) {
  3055. if (!this._elmn) {
  3056. this.entBox._onclick = this.entBox.onclick;
  3057. this.entBox.onclick = function() {
  3058. return true;
  3059. };
  3060. this.obj.onclick = function(e) {
  3061. this.grid.editStop();
  3062. var c = this.grid.getFirstParentOfType(e
  3063. ? e.target
  3064. : event.srcElement, 'TD');
  3065. this.grid.doClick(c);
  3066. this.ondblclick(e);
  3067. }
  3068. this.obj._onmousemove = this.obj.onmousemove;
  3069. this.obj.onmousemove = this._autoMoveSelect;
  3070. this._elmn = true;
  3071. }
  3072. } else {
  3073. if (this._elmn) {
  3074. this.entBox.onclick = this.entBox._onclick;
  3075. this.obj.onclick = function() {
  3076. return true
  3077. };
  3078. this.obj.onmousemove = this.obj._onmousemove;
  3079. this._elmn = false;
  3080. }
  3081. }
  3082. }
  3083. dhtmlXGridObject.prototype._unsetRowHover = function(e, c) {
  3084. if (c)
  3085. that = this;
  3086. else
  3087. that = this.grid;
  3088. if ((that._lahRw) && (that._lahRw != c)) {
  3089. for (var i = 0; i < that._lahRw.childNodes.length; i++)
  3090. that._lahRw.childNodes[i].className = that._lahRw.childNodes[i].className
  3091. .replace(that._hvrCss, "");
  3092. that._lahRw = null;
  3093. }
  3094. }
  3095. dhtmlXGridObject.prototype._setRowHover = function(e) {
  3096. var c = this.grid.getFirstParentOfType(e ? e.target : event.srcElement,
  3097. 'TD');
  3098. if (c) {
  3099. this.grid._unsetRowHover(0, c);
  3100. c = c.parentNode;
  3101. for (var i = 0; i < c.childNodes.length; i++)
  3102. c.childNodes[i].className += " " + this.grid._hvrCss;
  3103. this.grid._lahRw = c;
  3104. }
  3105. this._honmousemove(e);
  3106. }
  3107. dhtmlXGridObject.prototype._autoMoveSelect = function(e) {
  3108. // this - grid.obj
  3109. if (!this.grid.editor) {
  3110. var c = this.grid.getFirstParentOfType(e ? e.target : event.srcElement,
  3111. 'TD');
  3112. this.grid.doClick(c, true, 0);
  3113. }
  3114. this._onmousemove(e);
  3115. }
  3116. /**
  3117. * @desc: enable/disable light mouse navigation mode
  3118. * @param: mode - true/false
  3119. * @param: count - count of nodes parsed by one step (the 10 by default)
  3120. * @param: time - time between parsing counts in milli seconds (the 250 by
  3121. * default)
  3122. * @type: public
  3123. * @edition: Professional
  3124. */
  3125. dhtmlXGridObject.prototype.enableDistributedParsing = function(mode, count,
  3126. time) {
  3127. count = count || 10;
  3128. time = time || 250;
  3129. if (convertStringToBoolean(mode)) {
  3130. this._ads_count = count;
  3131. this._ads_time = time;
  3132. } else
  3133. this._ads_count = 0;
  3134. }
  3135. function _contextCall(obj, name, rowsCol, startIndex, tree, pId, i, n) {
  3136. window.setTimeout(function() {
  3137. obj[name](rowsCol, startIndex, tree, pId, i);
  3138. }, n);
  3139. return this;
  3140. }
  3141. /**
  3142. * @desc: destructor, cleans used memory
  3143. * @type: public
  3144. * @topic: 0
  3145. */
  3146. dhtmlXGridObject.prototype.destructor = function() {
  3147. var a;
  3148. this.xmlLoader = this.xmlLoader.destructor();
  3149. for (var i = 0; i < this.rowsCol.length; i++)
  3150. this.rowsCol[i].grid = null;
  3151. for (var i = 0; i < this.rowsAr.length; i++)
  3152. if (this.rowsAr[i])
  3153. this.rowsAr[i].grid = null;
  3154. this.rowsCol = new Array();
  3155. this.rowsAr = new Array();
  3156. this.entBox.innerHTML = "";
  3157. this.entBox.onclick = function() {
  3158. };
  3159. this.entBox.onmousedown = function() {
  3160. };
  3161. this.entBox.onbeforeactivate = function() {
  3162. };
  3163. this.entBox.onbeforedeactivate = function() {
  3164. };
  3165. this.entBox.onbeforedeactivate = function() {
  3166. };
  3167. for (a in this)
  3168. this[a] = null;
  3169. if (this == globalActiveDHTMLGridObject)
  3170. globalActiveDHTMLGridObject = null;
  3171. return null;
  3172. }
  3173. /**
  3174. * @desc: set function called after xml loading/parsing ended
  3175. * @param: func - event handling function
  3176. * @type: public
  3177. * @edition: Professional
  3178. * @topic: 0
  3179. * @event: onXMLLoadingEnd
  3180. * @eventdesc: event fired simultaneously with ending XML parsing, new items
  3181. * already available in tree
  3182. * @eventparam: grid object
  3183. * @eventparam: count of nodes added
  3184. */
  3185. dhtmlXGridObject.prototype.setOnLoadingEnd = function(func) {
  3186. this.dhx_attachEvent("onXLE", func);
  3187. };
  3188. /**
  3189. * @desc: set function called before xml loading started
  3190. * @param: func - event handling function
  3191. * @type: public
  3192. * @edition: Professional
  3193. * @topic: 0
  3194. * @event: onXMLLoadingStart
  3195. * @eventdesc: event fired before request for new XML sent to server
  3196. * @eventparam: grid object
  3197. */
  3198. dhtmlXGridObject.prototype.setOnLoadingStart = function(func) {
  3199. this.dhx_attachEvent("onXLS", func);
  3200. };
  3201. /**
  3202. * @desc: set function called after resizing finished
  3203. * @param: func - event handling function
  3204. * @type: public
  3205. * @edition: Professional
  3206. * @topic: 0
  3207. * @event: OnResizeEnd
  3208. * @eventdesc: event fired after resizing of column finished
  3209. * @eventparam: grid object
  3210. */
  3211. dhtmlXGridObject.prototype.setOnResizeEnd = function(func) {
  3212. this.dhx_attachEvent("onRSE", func);
  3213. };
  3214. /**
  3215. * @desc: set function called on each resizing itteration
  3216. * @param: func - event handling function
  3217. * @type: public
  3218. * @edition: Professional
  3219. * @topic: 0
  3220. * @event: OnResize
  3221. * @eventdesc: event fired on each resize itteration
  3222. * @eventparam: cell index
  3223. * @eventparam: cell width
  3224. * @eventparam: grid object
  3225. * @eventreturns: if event returns false - the resizig denied
  3226. */
  3227. dhtmlXGridObject.prototype.setOnResize = function(func) {
  3228. this.dhx_attachEvent("onRSI", func);
  3229. };
  3230. /**
  3231. * @desc: set function called before sorting of data started, didn't occur while
  3232. * calling grid.sortRows
  3233. * @param: func - event handling function
  3234. * @type: public
  3235. * @edition: Professional
  3236. * @topic: 10
  3237. * @event: onBeforeSorting
  3238. * @eventdesc: event called before sorting of data started
  3239. * @eventparam: index of sorted column
  3240. * @eventparam: grid object
  3241. * @eventreturns: if event returns false - the sorting denied
  3242. */
  3243. dhtmlXGridObject.prototype.setOnColumnSort = function(func) {
  3244. this.dhx_attachEvent("onCLMS", func);
  3245. };
  3246. // ====================================================================
  3247. dhtmlXGridObject.prototype.setOnKeyPressed = function(func) {
  3248. this.dhx_attachEvent("onKeyPress", func);
  3249. };
  3250. /**
  3251. * @desc: get sorting state of grid
  3252. * @type: public
  3253. * @edition: Professional
  3254. * @returns: array, first element is index of sortef column, second - direction
  3255. * of sorting.
  3256. * @topic: 0
  3257. */
  3258. dhtmlXGridObject.prototype.getSortingState = function() {
  3259. var z = new Array();
  3260. if (this.fldSorted) {
  3261. z[0] = this.fldSorted._cellIndex;
  3262. z[1] = (this.sortImg.src.indexOf("sort_desc.gif") != -1)
  3263. ? "DES"
  3264. : "ASC";
  3265. }
  3266. return z;
  3267. };
  3268. /**
  3269. * @desc: enable autoheight of grid
  3270. * @param: mode - true/false
  3271. * @param: maxHeight - maximum height before scrolling appears (infinite by
  3272. * default)
  3273. * @type: public
  3274. * @edition: Professional
  3275. * @topic: 0
  3276. */
  3277. dhtmlXGridObject.prototype.enableAutoHeigth = function(mode, maxHeight) {
  3278. this._ahgr = convertStringToBoolean(mode);
  3279. this._ahgrM = maxHeight || null;
  3280. };
  3281. /**
  3282. * @desc: enable/disable hot keys in grid
  3283. * @param: mode - true/false
  3284. * @type: public
  3285. * @edition: Professional
  3286. * @topic: 0
  3287. */
  3288. dhtmlXGridObject.prototype.enableKeyboardSupport = function(mode) {
  3289. this._htkebl = !convertStringToBoolean(mode);
  3290. };
  3291. /**
  3292. * @desc: enable/disable context menu
  3293. * @param: menu object, if null - context menu will be disabled
  3294. * @type: public
  3295. * @edition: Professional
  3296. * @topic: 0
  3297. */
  3298. dhtmlXGridObject.prototype.enableContextMenu = function(menu) {
  3299. this._ctmndx = menu;
  3300. };
  3301. /**
  3302. * @desc: set event handler, which will be called immideatly before showing
  3303. * context menu
  3304. * @param: func - user defined function
  3305. * @type: public
  3306. * @event: OnBeforeContextMenu
  3307. * @eventdesc: Event raised immideatly before showing context menu
  3308. * @eventparam: ID of clicked row
  3309. * @eventparam: index of cell column
  3310. * @eventparam: grid object
  3311. * @eventreturns: if event returns false, then context menu is not shown
  3312. * @edition: Professional
  3313. * @topic: 0,10
  3314. */
  3315. dhtmlXGridObject.prototype.setOnBeforeContextMenu = function(func) {
  3316. this.dhx_attachEvent("onBCM", func);
  3317. };
  3318. /**
  3319. * @desc: set width of browser scrollbars, will be used for correct autoWidth
  3320. * calculations (by default grid will use 16 for IE and 19 for FF)
  3321. * @param: width - scrollbar width
  3322. * @type: public
  3323. * @edition: Professional
  3324. * @topic: 0
  3325. */
  3326. dhtmlXGridObject.prototype.setScrollbarWidthCorrection = function(width) {
  3327. this._scrFix = parseInt(width);
  3328. };
  3329. /**
  3330. * @desc: enable/disable tooltips for specified colums
  3331. * @param: list - list of true/false values, tooltips enabled for all columns by
  3332. * default
  3333. * @type: public
  3334. * @edition: Professional
  3335. * @topic: 0
  3336. */
  3337. dhtmlXGridObject.prototype.enableTooltips = function(list) {
  3338. this._enbTts = list.split(",");
  3339. for (var i = 0; i < this._enbTts.length; i++)
  3340. this._enbTts[i] = convertStringToBoolean(this._enbTts[i]);
  3341. };
  3342. /**
  3343. * @desc: enable/disable resizing for specified colums
  3344. * @param: list - list of true/false values, resizing enabled for all columns by
  3345. * default
  3346. * @type: public
  3347. * @edition: Professional
  3348. * @topic: 0
  3349. */
  3350. dhtmlXGridObject.prototype.enableResizing = function(list) {
  3351. this._drsclmn = list.split(",");
  3352. for (var i = 0; i < this._drsclmn.length; i++)
  3353. this._drsclmn[i] = convertStringToBoolean(this._drsclmn[i]);
  3354. };
  3355. // #cell_id:11052006{
  3356. /**
  3357. * @desc: enable/disable unique id for cells (�_RowId_colIndex)
  3358. * @param: mode - true/false - enable/disable
  3359. * @type: public
  3360. * @edition: Professional
  3361. * @topic: 0
  3362. */
  3363. dhtmlXGridObject.prototype.enableCellIds = function(mode) {
  3364. this._enbCid = convertStringToBoolean(mode);
  3365. };
  3366. // #}
  3367. // #locked_row:11052006{
  3368. /**
  3369. * @desc: lock/unlock row for editing
  3370. * @param: rowId - id of row
  3371. * @param: mode - true/false - lock/unlock
  3372. * @type: public
  3373. * @edition: Professional
  3374. * @topic: 0
  3375. */
  3376. dhtmlXGridObject.prototype.lockRow = function(rowId, mode) {
  3377. var z = this.getRowById(rowId);
  3378. if (z) {
  3379. z._locked = convertStringToBoolean(mode);
  3380. if ((this.cell) && (this.cell.parentNode.idd == rowId))
  3381. this.editStop();
  3382. }
  3383. };
  3384. // #}
  3385. dhtmlXGridObject.prototype._getRowArray = function(row) {
  3386. var text = new Array();
  3387. for (var ii = 0; ii < row.childNodes.length; ii++)
  3388. text[ii] = this.cells3(row, ii).getValue();
  3389. return text;
  3390. }
  3391. // #cell_mask:12052006{
  3392. /**
  3393. * @desc: set mask for formatting date
  3394. * @param: mask - date mask, d,m,y will mean day,month,year; for example d/m/y -
  3395. * 22/05/1985
  3396. * @type: public
  3397. * @edition: Professional
  3398. * @topic: 0
  3399. */
  3400. dhtmlXGridObject.prototype.setDateFormat = function(mask) {
  3401. this._dtmask = mask;
  3402. }
  3403. /**
  3404. * @desc: set mask for formatting numeric data
  3405. * @param: mask - numeric mask; for example 0,000.00 - 1,234.56
  3406. * @param: cInd - column index
  3407. * @type: public
  3408. * @edition: Professional
  3409. * @topic: 0
  3410. */
  3411. dhtmlXGridObject.prototype.setNumberFormat = function(mask, cInd, p_sep, d_sep) {
  3412. var nmask = mask.replace(/[^0\,\.]*/g, "");
  3413. var pfix = nmask.indexOf(".");
  3414. if (pfix > -1)
  3415. pfix = nmask.length - pfix - 1;
  3416. var dfix = nmask.indexOf(",");
  3417. if (dfix > -1)
  3418. dfix = nmask.length - pfix - 2 - dfix;
  3419. p_sep = p_sep || ".";
  3420. d_sep = d_sep || ",";
  3421. var pref = mask.split(nmask)[0];
  3422. var postf = mask.split(nmask)[1];
  3423. this._maskArr[cInd] = [pfix, dfix, pref, postf, p_sep, d_sep];
  3424. }
  3425. dhtmlXGridObject.prototype._aplNFb = function(data, ind) {
  3426. var a = this._maskArr[ind];
  3427. if (!a)
  3428. return data;
  3429. var ndata = parseFloat(data.toString().replace(/[^0-9]*/g, ""));
  3430. if (data.toString().substr(0, 1) == "-")
  3431. ndata = ndata * -1;
  3432. if (a[0] > 0)
  3433. ndata = ndata / Math.pow(10, a[0]);
  3434. return ndata;
  3435. }
  3436. dhtmlXGridObject.prototype._aplNF = function(data, ind) {
  3437. var a = this._maskArr[ind];
  3438. if (!a)
  3439. return data;
  3440. var c = (parseFloat(data) < 0 ? "-" : "") + a[2];
  3441. data = Math.abs(Math.round(parseFloat(data)
  3442. * Math.pow(10, a[0] > 0 ? a[0] : 0))).toString();
  3443. data = (data.length < a[0] ? Math.pow(10, a[0] + 1 - data.length)
  3444. .toString().substr(1, a[0] + 1)
  3445. + data.toString() : data).split("").reverse();
  3446. data[a[0]] = (data[a[0]] || "0") + a[4];
  3447. if (a[1] > 0)
  3448. for (var j = (a[0] > 0 ? 0 : 1) + a[0] + a[1]; j < data.length; j += a[1])
  3449. data[j] += a[5];
  3450. return c + data.reverse().join("") + a[3];
  3451. }
  3452. // #}
  3453. /**
  3454. * @desc: populate grid with data from xml file (if passed parameter contains
  3455. * '.') or island
  3456. * @param: [xml] - xml island will be found by grid id (id_xml) if no file or
  3457. * island id is specified. This also can be ready-to-use XML object
  3458. * @param: [startIndex] - index of row in grid to start insertion from
  3459. * @type: public
  3460. * @topic: 2,5
  3461. */
  3462. dhtmlXGridObject.prototype.parseXML = function(xml, startIndex) {
  3463. // debugger;
  3464. this._xml_ready = true;
  3465. var pid = null;
  3466. var zpid = null;
  3467. if (!xml)
  3468. try {
  3469. var xmlDoc = eval(this.entBox.id + "_xml").XMLDocument;
  3470. } catch (er) {
  3471. var xmlDoc = this.loadXML(this.xmlFileUrl)
  3472. }
  3473. else {
  3474. if (typeof(xml) == "object") {
  3475. var xmlDoc = xml;
  3476. } else {
  3477. if (xml.indexOf(".") != -1) {
  3478. if (this.xmlFileUrl == "")
  3479. this.xmlFileUrl = xml
  3480. var xmlDoc = this.loadXML(xml)
  3481. return;
  3482. } else
  3483. var xmlDoc = eval(xml).XMLDocument;
  3484. }
  3485. }
  3486. // debugger;
  3487. var rowsCol = this.xmlLoader.doXPath("//rows/row", xmlDoc);
  3488. if (rowsCol.length == 0) {
  3489. this.recordsNoMore = true;
  3490. var pid = 0;
  3491. } else {
  3492. pid = (rowsCol[0].parentNode.getAttribute("parent") || "0");
  3493. zpid = this.getRowById(pid);
  3494. if (zpid)
  3495. zpid._xml_await = false;
  3496. else
  3497. pid = 0;
  3498. startIndex = this.getRowIndex(pid) + 1;
  3499. }
  3500. var ar = new Array();
  3501. var idAr = new Array();
  3502. // global(grid) user data
  3503. var gudCol = this.xmlLoader.doXPath("//rows/userdata", xmlDoc);
  3504. if (gudCol.length > 0) {
  3505. this.UserData["gridglobaluserdata"] = new Hashtable();
  3506. for (var j = 0; j < gudCol.length; j++) {
  3507. this.UserData["gridglobaluserdata"].put(gudCol[j]
  3508. .getAttribute("name"), gudCol[j].firstChild
  3509. ? gudCol[j].firstChild.data
  3510. : "");
  3511. }
  3512. }
  3513. // head
  3514. var hheadCol = this.xmlLoader.doXPath("//rows/head", xmlDoc);
  3515. if (hheadCol.length) {
  3516. var headCol = this.xmlLoader.doXPath("//rows/head/column", hheadCol[0]);
  3517. var asettings = this.xmlLoader.doXPath("//rows/head/settings",
  3518. hheadCol[0]);
  3519. var awidthmet = "setInitWidths";
  3520. if (asettings.length) {
  3521. for (var s = 0; s < asettings.length; s++)
  3522. switch (asettings[0].childNodes[s].tagName) {
  3523. case "colwidth" :
  3524. if (asettings[0].childNodes[s].firstChild
  3525. && asettings[0].childNodes[s].firstChild.data == "%")
  3526. awidthmet = "setInitWidthsP";
  3527. break;
  3528. }
  3529. }
  3530. if (headCol.length > 0) {
  3531. var a_list = "";
  3532. var b_list = "";
  3533. var c_list = "";
  3534. var d_list = "";
  3535. var e_list = "";
  3536. var f_list = "";
  3537. for (var i = 0; i < headCol.length; i++) {
  3538. a_list += headCol[i].getAttribute("width") + ",";
  3539. b_list += headCol[i].getAttribute("type") + ",";
  3540. c_list += headCol[i].getAttribute("align") + ",";
  3541. d_list += headCol[i].getAttribute("sort") + ",";
  3542. e_list += (headCol[i].getAttribute("color") != null
  3543. ? headCol[i].getAttribute("color")
  3544. : "")
  3545. + ",";
  3546. f_list += (headCol[i].firstChild
  3547. ? headCol[i].firstChild.data
  3548. : "")
  3549. + ",";
  3550. }
  3551. this.setHeader(f_list.substr(0, f_list.length - 1));
  3552. this[awidthmet](a_list.substr(0, a_list.length - 1));
  3553. this.setColAlign(c_list.substr(0, c_list.length - 1));
  3554. this.setColTypes(b_list.substr(0, b_list.length - 1));
  3555. this.setColSorting(d_list.substr(0, d_list.length - 1));
  3556. this.setColumnColor(e_list.substr(0, e_list.length - 1));
  3557. for (var i = 0; i < headCol.length; i++) {
  3558. if (this.cellType[i].indexOf('co') == 0) {
  3559. var optCol = this.xmlLoader.doXPath("./option", headCol[i]);
  3560. for (var j = 0; j < optCol.length; j++)
  3561. this.getCombo(i).put(
  3562. optCol[j].getAttribute("value"),
  3563. optCol[j].firstChild
  3564. ? optCol[j].firstChild.data
  3565. : "");
  3566. }
  3567. }
  3568. this.init();
  3569. }
  3570. }
  3571. // rows
  3572. var tree = this.cellType._dhx_find("tree");
  3573. if (tree == -1)
  3574. tree = this.cellType._dhx_find("3d");
  3575. this._innerParse(rowsCol, startIndex, tree, pid);
  3576. if (zpid)
  3577. this.expandKids(zpid);
  3578. if (this.dynScroll && this.dynScroll != 'false') {
  3579. this.doDynScroll()
  3580. }
  3581. if (tree != -1) {
  3582. var oCol = this.xmlLoader.doXPath("//row[@open]", xmlDoc);
  3583. for (var i = 0; i < oCol.length; i++)
  3584. this.openItem(oCol[i].getAttribute("id"));
  3585. }
  3586. this.setSizes();
  3587. if (_isOpera) {
  3588. this.obj.style.border = 1;
  3589. this.obj.style.border = 0;
  3590. }
  3591. this._startXMLLoading = false;
  3592. try {
  3593. } catch (er) {
  3594. dhtmlxError.throwError("ParseXML", "Error parsing XML - "
  3595. + er.description, xml)
  3596. return;
  3597. }
  3598. if (this.onXLE)
  3599. this.onXLE(this, rowsCol.length);
  3600. }
  3601. dhtmlXGridObject.prototype._innerParse = function(rowsCol, startIndex, tree,
  3602. pId, i) {
  3603. i = i || 0;
  3604. var imax = i + this._ads_count;
  3605. var r = null;
  3606. for (var i; i < rowsCol.length; i++) {
  3607. if (this._ads_count && i == imax) {
  3608. new _contextCall(this, "_innerParse", rowsCol, startIndex, tree,
  3609. pId, i, this._ads_time);
  3610. return;
  3611. }
  3612. if ((pId)
  3613. || (i <= this.rowsBufferOutSize || this.rowsBufferOutSize == 0)) {
  3614. var rId = rowsCol[i].getAttribute("id")
  3615. var xstyle = rowsCol[i].getAttribute("style");
  3616. // user data
  3617. var udCol = this.xmlLoader.doXPath("./userdata", rowsCol[i]);
  3618. if (udCol.length > 0) {
  3619. this.UserData[rId] = new Hashtable();
  3620. for (var j = 0; j < udCol.length; j++) {
  3621. this.UserData[rId]
  3622. .put(udCol[j].getAttribute("name"),
  3623. udCol[j].firstChild
  3624. ? udCol[j].firstChild.data
  3625. : "");
  3626. }
  3627. }
  3628. var cellsCol = this.xmlLoader.doXPath("./cell", rowsCol[i]);
  3629. var strAr = new Array(0);
  3630. for (var j = 0; j < cellsCol.length; j++) {
  3631. if (j != tree)
  3632. strAr[strAr.length] = cellsCol[j].firstChild
  3633. ? cellsCol[j].firstChild.data
  3634. : "";
  3635. else
  3636. strAr[strAr.length] = pId
  3637. + "^"
  3638. + (cellsCol[j].firstChild
  3639. ? cellsCol[j].firstChild.data
  3640. : "") + "^"
  3641. + (rowsCol[i].getAttribute("xmlkids") ? "1" : "0")
  3642. + "^"
  3643. + (cellsCol[j].getAttribute("image") || "leaf.gif");
  3644. }
  3645. this._parsing_ = true;
  3646. if (startIndex) {
  3647. r = this._addRow(rId, strAr, startIndex)
  3648. startIndex++;
  3649. } else {
  3650. r = this._addRow(rId, strAr)
  3651. }
  3652. // #td_tr_classes:06062006{
  3653. var css1 = rowsCol[i].getAttribute("class");
  3654. if (css1)
  3655. r.className += " " + css1;
  3656. for (var j = 0; j < cellsCol.length; j++) {
  3657. css1 = cellsCol[j].getAttribute("class");
  3658. if (css1)
  3659. r.childNodes[j].className += " " + css1;
  3660. }
  3661. // #}
  3662. // #locked_row:11052006{
  3663. if (rowsCol[i].getAttribute("locked")) {
  3664. r._locked = true;
  3665. // r.style.color='#696969';
  3666. }
  3667. // #}
  3668. this._parsing_ = false;
  3669. // select row
  3670. if (rowsCol[i].getAttribute("selected") == true) {
  3671. this.setSelectedRow(rId, this.selMultiRows, false, rowsCol[i]
  3672. .getAttribute("call") == true)
  3673. }
  3674. // expand row
  3675. if (rowsCol[i].getAttribute("expand") == "1") {
  3676. r.expand = "";
  3677. }
  3678. } else {
  3679. var len = this.rowsBuffer[0].length
  3680. this.rowsBuffer[1][len] = rowsCol[i]
  3681. this.rowsBuffer[0][len] = rowsCol[i].getAttribute("id")
  3682. // this.rowsBuffer[1][len] = ar[i]
  3683. }
  3684. if (tree != -1) {
  3685. var rowsCol2 = this.xmlLoader.doXPath("./row", rowsCol[i]);
  3686. if (rowsCol2.length != 0)
  3687. startIndex = this._innerParse(rowsCol2, startIndex, tree, rId);
  3688. }
  3689. if (xstyle)
  3690. this.setRowTextStyle(rId, xstyle);
  3691. }
  3692. if ((r) && (this._checkSCL))
  3693. for (var i = 0; i < this.hdr.rows[0].cells.length; i++)
  3694. this._checkSCL(r.childNodes[i]);
  3695. return startIndex;
  3696. }
  3697. // ====add bu sunzhigang from grid 1.4
  3698. // =======================================================
  3699. dhtmlXGridObject.prototype.attachHeader = function(values, style, _type) {
  3700. if (typeof(values) == "string")
  3701. values = this._eSplit(values);
  3702. if (typeof(style) == "string")
  3703. style = style.split(this.delim);
  3704. _type = _type || "_aHead";
  3705. if (this.hdr.rows.length) {
  3706. if (values)
  3707. this._createHRow([values, style], this[(_type == "_aHead")
  3708. ? "hdr"
  3709. : "ftr"]);
  3710. else if (this[_type])
  3711. for (var i = 0; i < this[_type].length; i++)
  3712. this.attachHeader.apply(this, this[_type][i])
  3713. } else {
  3714. if (!this[_type])
  3715. this[_type] = new Array();
  3716. this[_type][this[_type].length] = [values, style, _type]
  3717. }
  3718. };
  3719. dhtmlXGridObject.prototype._createHRow = function(data, parent) {
  3720. if (!parent) {
  3721. this.entBox.style.position = "relative";
  3722. var z = document.createElement("DIV");
  3723. z.className = "c_ftr".substr(2);
  3724. this.entBox.appendChild(z);
  3725. var t = document.createElement("TABLE");
  3726. t.cellPadding = t.cellSpacing = 0;
  3727. if (!_isIE) {
  3728. t.width = "100%";
  3729. t.style.paddingRight = "20px"
  3730. };
  3731. t.style.tableLayout = "fixed";
  3732. z.appendChild(t);
  3733. t.appendChild(document.createElement("TBODY"));
  3734. this.ftr = parent = t;
  3735. var hdrRow = t.insertRow(0);
  3736. var thl = ((this.hdrLabels.length <= 1)
  3737. ? data[0].length
  3738. : this.hdrLabels.length);
  3739. for (var i = 0; i < thl; i++) {
  3740. hdrRow.appendChild(document.createElement("TH"));
  3741. hdrRow.childNodes[i]._cellIndex = i
  3742. };
  3743. if (_isIE)
  3744. hdrRow.style.position = "absolute";
  3745. else
  3746. hdrRow.style.height = 'auto'
  3747. };
  3748. var st1 = data[1];
  3749. var z = document.createElement("TR");
  3750. parent.rows[0].parentNode.appendChild(z);
  3751. for (var i = 0; i < data[0].length; i++) {
  3752. if (data[0][i] == "#cspan") {
  3753. var pz = z.cells[z.cells.length - 1];
  3754. pz.colSpan = (pz.colSpan || 1) + 1;
  3755. continue
  3756. };
  3757. if ((data[0][i] == "#rspan") && (parent.rows.length > 1)) {
  3758. var pind = parent.rows.length - 2;
  3759. var found = false;
  3760. var pz = null;
  3761. while (!found) {
  3762. var pz = parent.rows[pind];
  3763. for (var j = 0; j < pz.cells.length; j++)
  3764. if (pz.cells[j]._cellIndex == i) {
  3765. found = j + 1;
  3766. break
  3767. };
  3768. pind--
  3769. };
  3770. pz = pz.cells[found - 1];
  3771. pz.rowSpan = (pz.rowSpan || 1) + 1;
  3772. continue
  3773. };
  3774. var w = document.createElement("TD");
  3775. w._cellIndex = w._cellIndexS = i;
  3776. if (this.forceDivInHeader)
  3777. w.innerHTML = "<div class='hdrcell'>" + data[0][i] + "</div>";
  3778. else
  3779. w.innerHTML = data[0][i];
  3780. var t;
  3781. if (((t = (data[0][i] || "")).indexOf("#") == 0)
  3782. && (this[t = "_in_header_" + t.substr(1)]))
  3783. this[t]((this.forceDivInHeader ? w.firstChild : w), i);
  3784. if (st1)
  3785. w.style.cssText = st1[i];
  3786. z.appendChild(w)
  3787. };
  3788. var self = parent;
  3789. if (_isKHTML) {
  3790. if (parent._kTimer)
  3791. window.clearTimeout(parent._kTimer);
  3792. parent._kTimer = window.setTimeout(function() {
  3793. parent.rows[1].style.display = 'none';
  3794. window.setTimeout(function() {
  3795. parent.rows[1].style.display = ''
  3796. }, 1)
  3797. }, 500)
  3798. }
  3799. };
  3800. // ============================================