2 * (c) 2005-2009 Richard Cowin (http://openrico.org)
3 * (c) 2005-2009 Matt Brown (http://dowdybrown.com)
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
6 * file except in compliance with the License. You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software distributed under the
11 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
12 * either express or implied. See the License for the specific language governing permissions
13 * and limitations under the License.
16 if(typeof Rico=='undefined') throw("LiveGrid requires the Rico JavaScript framework");
20 if (!Rico.Buffer) Rico.Buffer = {};
22 Rico.Buffer.Base = function(dataTable, options) {
23 this.initialize(dataTable, options);
25 /** @lends Rico.Buffer.Base# */
26 Rico.Buffer.Base.prototype = {
28 * @class Defines the static buffer class (no AJAX).
29 * Loads buffer with data that already exists in the document as an HTML table or passed via javascript.
30 * Also serves as a base class for AJAX-enabled buffers.
33 initialize: function(dataTable, options) {
35 this.updateInProgress = false;
37 this.rcvdRowCount = false; // true if an eof element was included in the last xml response
38 this.foundRowCount = false; // true if an xml response is ever received with eof true
40 this.rowcntContent = "";
44 canFilter : true, // does buffer object support filtering?
45 isEncoded : true, // is the data received via ajax html encoded?
46 acceptAttr : [] // attributes that can be copied from original/ajax data (e.g. className, style, id)
48 Rico.extend(this.options, options || {});
50 this.loadRowsFromTable(dataTable,this.options.fixedHdrRows);
56 registerGrid: function(liveGrid) {
57 this.liveGrid = liveGrid;
60 setTotalRows: function( newTotalRows ) {
61 if (typeof(newTotalRows)!='number') newTotalRows=this.size;
62 if (this.totalRows == newTotalRows) return;
63 this.totalRows = newTotalRows;
64 if (!this.liveGrid) return;
65 Rico.log("setTotalRows, newTotalRows="+newTotalRows);
66 switch (this.liveGrid.sizeTo) {
68 this.liveGrid.resizeWindow();
71 this.liveGrid.setPageSize(newTotalRows);
74 this.liveGrid.updateHeightDiv();
79 loadRowsFromTable: function(tableElement,firstRow) {
80 var newRows = new Array();
81 var trs = tableElement.getElementsByTagName("tr");
82 for ( var i=firstRow || 0; i < trs.length; i++ ) {
83 var row = new Array();
84 var cells = trs[i].getElementsByTagName("td");
85 for ( var j=0; j < cells.length ; j++ )
86 row[j]=cells[j].innerHTML;
89 this.loadRows(newRows);
92 loadRowsFromArray: function(array2D) {
93 for ( var i=0; i < array2D.length; i++ ) {
94 for ( var j=0; j < array2D[i].length ; j++ ) {
95 array2D[i][j]=array2D[i][j].toString();
98 this.loadRows(array2D);
101 loadRows: function(jstable) {
102 this.baseRows = jstable;
104 this.size = this.baseRows.length;
107 dom2jstable: function(rowsElement) {
108 Rico.log('dom2jstable: encoded='+this.options.isEncoded);
109 var newRows = new Array();
110 var trs = rowsElement.getElementsByTagName("tr");
111 for ( var i=0; i < trs.length; i++ ) {
112 var row = new Array();
113 var cells = trs[i].getElementsByTagName("td");
114 for ( var j=0; j < cells.length ; j++ )
115 row[j]=Rico.getContentAsString(cells[j],this.options.isEncoded);
121 dom2jstableAttr: function(rowsElement,firstRow) {
122 var acceptAttr=this.options.acceptAttr;
123 Rico.log("dom2jstableAttr start, # attr="+acceptAttr.length);
124 var newRows = new Array();
125 var trs = rowsElement.getElementsByTagName("tr");
126 for ( var i=firstRow || 0; i < trs.length; i++ ) {
127 var row = new Array();
128 var cells = trs[i].getElementsByTagName("td");
129 for ( var j=0; j < cells.length ; j++ ) {
131 for (var k=0; k<acceptAttr.length; k++)
132 row[j]['_'+acceptAttr[k]]=cells[j].getAttribute(acceptAttr[k]);
133 if (Rico.isIE) row[j]._class=cells[j].getAttribute('className');
137 Rico.log("dom2jstableAttr end");
141 _blankRow: function() {
143 for (var i=0; i<this.liveGrid.columns.length; i++) {
149 deleteRows: function(rowIndex,cnt) {
150 this.baseRows.splice(rowIndex,typeof(cnt)=='number' ? cnt : 1);
151 this.liveGrid.isPartialBlank=true;
152 this.size=this.baseRows.length;
155 insertRow: function(beforeRowIndex) {
156 var r=this._blankRow();
157 this.baseRows.splice(beforeRowIndex,0,r);
158 this.size=this.baseRows.length;
159 this.liveGrid.isPartialBlank=true;
160 if (this.startPos < 0) this.startPos=0;
164 appendRows: function(cnt) {
166 for (var i=0; i<cnt; i++) {
167 var r=this._blankRow();
168 this.baseRows.push(r);
171 this.size=this.baseRows.length;
172 this.liveGrid.isPartialBlank=true;
173 if (this.startPos < 0) this.startPos=0;
177 sortFunc: function(coltype) {
180 case 'number': return function(a,b) { return self._sortNumeric(a,b); };
181 case 'control':return function(a,b) { return self._sortControl(a,b); };
182 default: return function(a,b) { return self._sortAlpha(a,b); };
186 sortBuffer: function(colnum) {
187 if (!this.baseRows) {
188 this.delayedSortCol=colnum;
191 this.liveGrid.showMsg(Rico.getPhraseById("sorting"));
192 this.sortColumn=colnum;
193 var col=this.liveGrid.columns[colnum];
194 this.getValFunc=col._sortfunc;
195 this.baseRows.sort(this.sortFunc(col.format.type));
196 if (col.getSortDirection()=='DESC') this.baseRows.reverse();
199 _sortAlpha: function(a,b) {
200 var aa = this.sortColumn<a.length ? Rico.getInnerText(a[this.sortColumn]) : '';
201 var bb = this.sortColumn<b.length ? Rico.getInnerText(b[this.sortColumn]) : '';
202 if (aa==bb) return 0;
203 if (aa<bb) return -1;
207 _sortNumeric: function(a,b) {
208 var aa = this.sortColumn<a.length ? this.nan2zero(Rico.getInnerText(a[this.sortColumn])) : 0;
209 var bb = this.sortColumn<b.length ? this.nan2zero(Rico.getInnerText(b[this.sortColumn])) : 0;
213 nan2zero: function(n) {
214 if (typeof(n)=='string') n=parseFloat(n);
215 return isNaN(n) || typeof(n)=='undefined' ? 0 : n;
218 _sortControl: function(a,b) {
219 var aa = this.sortColumn<a.length ? Rico.getInnerText(a[this.sortColumn]) : '';
220 var bb = this.sortColumn<b.length ? Rico.getInnerText(b[this.sortColumn]) : '';
221 if (this.getValFunc) {
222 aa=this.getValFunc(aa);
223 bb=this.getValFunc(bb);
225 if (aa==bb) return 0;
226 if (aa<bb) return -1;
238 isInRange: function(position) {
239 var lastRow=Math.min(this.totalRows, position + this.liveGrid.pageSize);
240 return (position >= this.startPos) && (lastRow <= this.endPos()); // && (this.size != 0);
244 return this.startPos + this.rows.length;
247 fetch: function(offset) {
248 Rico.log('fetch '+this.liveGrid.tableId+': offset='+offset);
251 this.rcvdRowCount = true;
252 this.foundRowCount = true;
253 if (offset < 0) offset=0;
254 this.liveGrid.refreshContents(offset);
259 * @return a 2D array of buffer data representing the rows that are currently visible on the grid
261 visibleRows: function() {
262 return this.rows.slice(this.windowStart,this.windowEnd);
265 setWindow: function(startrow, endrow) {
266 this.windowStart = startrow - this.startPos; // position in the buffer of first visible row
267 Rico.log('setWindow '+this.liveGrid.tableId+': '+startrow+', '+endrow+', newstart='+this.windowStart);
268 this.windowEnd = Math.min(endrow,this.size); // position in the buffer of last visible row containing data+1
269 this.windowPos = startrow; // position in the dataset of first visible row
273 * @return true if bufRow is currently visible in the grid
275 isVisible: function(bufRow) {
276 return bufRow < this.rows.length && bufRow >= this.windowStart && bufRow < this.windowEnd;
280 * takes a window row index and returns the corresponding buffer row index
282 bufferRow: function(windowRow) {
283 return this.windowStart+windowRow;
287 * @return buffer cell at the specified visible row/col index
289 getWindowCell: function(windowRow,col) {
290 var bufrow=this.bufferRow(windowRow);
291 return this.isVisible(bufrow) && col < this.rows[bufrow].length ? this.rows[bufrow][col] : null;
294 getWindowAttr: function(windowRow,col) {
295 var bufrow=this.bufferRow(windowRow);
296 return this.attr && this.isVisible(bufrow) && col < this.attr[bufrow].length ? this.attr[bufrow][col] : null;
299 getWindowValue: function(windowRow,col) {
300 return this.getWindowCell(windowRow,col);
303 setWindowValue: function(windowRow,col,newval) {
304 var bufrow=this.bufferRow(windowRow);
305 if (bufrow >= this.windowEnd) return false;
306 return this.setValue(bufrow,col,newval);
309 getCell: function(bufRow,col) {
310 return bufRow < this.size ? this.rows[bufRow][col] : null;
313 getValue: function(bufRow,col) {
314 return this.getCell(bufRow,col);
317 setValue: function(bufRow,col,newval,newstyle) {
318 if (bufRow>=this.size) return false;
319 if (!this.rows[bufRow][col]) this.rows[bufRow][col]={};
320 this.rows[bufRow][col]=newval;
321 if (typeof newstyle=='string') this.rows[bufRow][col]._style=newstyle;
322 this.rows[bufRow][col].modified=true;
326 getRows: function(start, count) {
327 var begPos = start - this.startPos;
328 var endPos = Math.min(begPos + count,this.size);
329 var results = new Array();
330 for ( var i=begPos; i < endPos; i++ ) {
331 results.push(this.rows[i]);
336 applyFilters: function() {
337 var newRows=[],re=[];
338 var r,c,n,i,showRow,filtercnt;
339 var cols=this.liveGrid.columns;
340 for (n=0,filtercnt=0; n<cols.length; n++) {
342 if (c.filterType == Rico.ColumnConst.UNFILTERED) continue;
344 if (c.filterOp=='LIKE') re[n]=new RegExp(c.filterValues[0],'i');
346 Rico.log('applyFilters: # of filters='+filtercnt);
348 this.rows = this.baseRows;
350 for (r=0; r<this.baseRows.length; r++) {
352 for (n=0; n<cols.length && showRow; n++) {
354 if (c.filterType == Rico.ColumnConst.UNFILTERED) continue;
355 switch (c.filterOp) {
357 showRow=re[n].test(this.baseRows[r][n]);
360 showRow=this.baseRows[r][n]==c.filterValues[0];
363 for (i=0; i<c.filterValues.length && showRow; i++)
364 showRow=this.baseRows[r][n]!=c.filterValues[i];
367 if (c.format.type=='number')
368 showRow=this.nan2zero(this.baseRows[r][n])<=this.nan2zero(c.filterValues[0]);
370 showRow=this.baseRows[r][n]<=c.filterValues[0];
373 if (c.format.type=='number')
374 showRow=this.nan2zero(this.baseRows[r][n])>=this.nan2zero(c.filterValues[0]);
376 showRow=this.baseRows[r][n]>=c.filterValues[0];
379 showRow=this.baseRows[r][n]=='';
382 showRow=this.baseRows[r][n]!='';
386 if (showRow) newRows.push(this.baseRows[r]);
390 this.rowcntContent = this.size = this.rows.length;
393 printAll: function(exportType) {
394 this.liveGrid.showMsg(Rico.getPhraseById('exportInProgress'));
395 Rico.runLater(10,this,'_printAll',exportType); // allow message to paint
399 * Support function for printAll()
401 _printAll: function(exportType) {
402 this.liveGrid.exportStart();
403 this.exportBuffer(this.getRows(0,this.totalRows));
404 this.liveGrid.exportFinish(exportType);
408 * Copies visible rows to a new window as a simple html table.
410 printVisible: function(exportType) {
411 this.liveGrid.showMsg(Rico.getPhraseById('exportInProgress'));
412 Rico.runLater(10,this,'_printVisible',exportType); // allow message to paint
415 _printVisible: function(exportType) {
416 this.liveGrid.exportStart();
417 this.exportBuffer(this.visibleRows());
418 this.liveGrid.exportFinish(exportType);
422 * Send all rows to print/export window
424 exportBuffer: function(rows,startPos) {
425 var r,c,v,col,exportText;
426 Rico.log("exportBuffer: "+rows.length+" rows");
427 var exportStyles=this.liveGrid.getExportStyles(this.liveGrid.tbody[0]);
429 var totalcnt=startPos || 0;
430 var cols=this.liveGrid.columns;
431 for (c=0; c<cols.length; c++) {
432 if (cols[c].visible) tdstyle[c]=this.liveGrid.exportStyle(cols[c].cell(0),exportStyles); // assumes row 0 style applies to all rows
434 for(r=0; r < rows.length; r++) {
436 for (c=0; c<cols.length; c++) {
437 if (!cols[c].visible) continue;
439 col.expStyle=tdstyle[c];
440 v=col._export(rows[r][c],rows[r]);
441 if (v=='') v=' ';
442 exportText+="<td style='"+col.expStyle+"'>"+v+"</td>";
444 this.liveGrid.exportRows.push(exportText);
446 if (totalcnt % 10 == 0) window.status=Rico.getPhraseById('exportStatus',totalcnt);
453 // Rico.LiveGrid -----------------------------------------------------
455 Rico.LiveGrid = function(tableId, buffer, options) {
456 this.initialize(tableId, buffer, options);
460 * @lends Rico.LiveGrid#
461 * @property tableId id string for this grid
462 * @property options the options object passed to the constructor extended with defaults
463 * @property buffer the buffer object containing the data for this grid
464 * @property columns array of {@link Rico.LiveGridColumn} objects
466 Rico.LiveGrid.prototype = {
468 * @class Buffered LiveGrid component
469 * @extends Rico.GridCommon
472 initialize: function( tableId, buffer, options ) {
473 Rico.extend(this, Rico.GridCommon);
474 Rico.extend(this, Rico.LiveGridMethods);
476 this.tableId = tableId;
477 this.buffer = buffer;
478 this.actionId='_action_'+tableId;
479 Rico.setDebugArea(tableId+"_debugmsgs"); // if used, this should be a textarea
481 Rico.extend(this.options, {
482 visibleRows : -3, // -1 or 'window'=size grid to client window; -2 or 'data'=size grid to min(window,data); -3 or 'body'=size so body does not have a scrollbar; -4 or 'parent'=size to parent element (e.g. if grid is inside a div)
484 offset : 0, // first row to be displayed
485 prefetchBuffer : true, // load table on page load?
488 canSortDefault : true, // can be overridden in the column specs
489 canFilterDefault : buffer.options.canFilter, // can be overridden in the column specs
490 canHideDefault : true, // can be overridden in the column specs
492 // highlight & selection parameters
493 highlightElem : 'none',// what gets highlighted/selected (cursorRow, cursorCell, menuRow, menuCell, selection, or none)
494 highlightSection : 3, // which section gets highlighted (frozen=1, scrolling=2, all=3, none=0)
495 highlightMethod : 'class', // outline, class, both (outline is less CPU intensive on the client)
496 highlightClass : Rico.theme.gridHighlightClass || 'ricoLG_selection',
498 // export/print parameters
499 maxPrint : 5000, // max # of rows that can be printed/exported, 0=disable print/export feature
501 // heading parameters
502 headingSort : 'link', // link: make headings a link that will sort column, hover: make headings a hoverset, none: events on headings are disabled
503 hdrIconsFirst : true, // true: put sort & filter icons before header text, false: after
504 filterImg : 'filtercol.gif'
507 // sortCol: initial sort column
510 this.options.sortHandler = function() { self.sortHandler(); };
511 this.options.filterHandler = function() { self.filterHandler(); };
512 this.options.onRefreshComplete = function(firstrow,lastrow) { self.bookmarkHandler(firstrow,lastrow); };
513 this.options.rowOverHandler = Rico.eventHandle(this,'rowMouseOver');
514 this.options.mouseDownHandler = Rico.eventHandle(this,'selectMouseDown');
515 this.options.mouseOverHandler = Rico.eventHandle(this,'selectMouseOver');
516 this.options.mouseUpHandler = Rico.eventHandle(this,'selectMouseUp');
517 Rico.extend(this.options, options || {});
519 switch (typeof this.options.visibleRows) {
521 this.sizeTo=this.options.visibleRows;
522 switch (this.options.visibleRows) {
523 case 'data': this.options.visibleRows=-2; break;
524 case 'body': this.options.visibleRows=-3; break;
525 case 'parent': this.options.visibleRows=-4; break;
526 case 'datamax':this.options.visibleRows=-5; break;
527 default: this.options.visibleRows=-1; break;
531 switch (this.options.visibleRows) {
532 case -1: this.sizeTo='window'; break;
533 case -2: this.sizeTo='data'; break;
534 case -3: this.sizeTo='body'; break;
535 case -4: this.sizeTo='parent'; break;
536 case -5: this.sizeTo='datamax'; break;
537 default: this.sizeTo='fixed'; break;
542 this.options.visibleRows=-3;
545 this.highlightEnabled=this.options.highlightSection>0;
548 if (this.headerColCnt==0) {
549 alert('ERROR: no columns found in "'+this.tableId+'"');
552 this.createColumnArray('LiveGridColumn');
553 if (this.options.headingSort=='hover')
554 this.createHoverSet();
556 this.bookmark=document.getElementById(this.tableId+"_bookmark");
558 var filterUIrow=this.buffer.options.canFilter ? this.options.FilterLocation : false;
559 if (typeof(filterUIrow)=='number' && filterUIrow<0)
560 filterUIrow=this.addHeadingRow('ricoLG_FilterRow');
561 this.createDataCells(this.options.visibleRows);
562 if (this.pageSize == 0) return;
563 this.buffer.registerGrid(this);
564 if (this.buffer.setBufferSize) this.buffer.setBufferSize(this.pageSize);
565 this.scrollTimeout = null;
566 this.lastScrollPos = 0;
567 this.attachMenuEvents();
569 // preload the images...
570 new Image().src = Rico.imgDir+this.options.filterImg;
571 Rico.log("images preloaded");
573 this.setSortUI( this.options.sortCol, this.options.sortDir );
575 if (this.listInvisible().length==this.columns.length)
576 this.columns[0].showColumn();
578 this.scrollDiv.style.display="";
579 if (this.buffer.totalRows>0)
580 this.updateHeightDiv();
581 if (this.options.prefetchBuffer) {
582 if (this.bookmark) this.bookmark.innerHTML = Rico.getPhraseById('bookmarkLoading');
583 if (this.options.canFilterDefault && this.options.getQueryParms)
584 this.checkForFilterParms();
585 this.scrollToRow(this.options.offset);
586 this.buffer.fetch(this.options.offset);
588 if (typeof(filterUIrow)=='number')
589 this.createFilters(filterUIrow);
590 this.scrollEventFunc=Rico.eventHandle(this,'handleScroll');
591 this.wheelEventFunc=Rico.eventHandle(this,'handleWheel');
592 this.wheelEvent=(Rico.isIE || Rico.isOpera || Rico.isWebKit) ? 'mousewheel' : 'DOMMouseScroll';
593 if (this.options.offset && this.options.offset < this.buffer.totalRows)
594 Rico.runLater(50,this,'scrollToRow',this.options.offset); // Safari requires a delay
596 this.setHorizontalScroll();
597 Rico.log("setHorizontalScroll done");
598 if (this.options.windowResize)
599 Rico.runLater(100,this,'pluginWindowResize');
600 Rico.log("initialize complete for "+this.tableId);
605 Rico.LiveGridMethods = {
606 /** @lends Rico.LiveGrid# */
608 createHoverSet: function() {
610 for( var c=0; c < this.headerColCnt; c++ ) {
611 if (this.columns[c].sortable) {
\r
612 hdrs.push(this.columns[c].hdrCellDiv);
615 this.hoverSet = new Rico.HoverSet(hdrs);
618 checkForFilterParms: function() {
619 var s=window.location.search;
620 if (s.charAt(0)=='?') s=s.substring(1);
621 var pairs = s.split('&');
622 for (var i=0; i<pairs.length; i++) {
623 if (pairs[i].match(/^f\[\d+\]/)) {
624 this.buffer.options.requestParameters.push(pairs[i]);
630 * Refreshes a detail grid from a master grid
631 * @returns row index on master table on success, -1 otherwise
633 drillDown: function(e,masterColNum,detailColNum) {
634 var cell=Rico.eventElement(e || window.event);
635 cell=Rico.getParentByTagName(cell,'div','ricoLG_cell');
636 if (!cell) return -1;
637 var idx=this.winCellIndex(cell);
638 if (idx.row >= this.buffer.totalRows) return -1
640 this.menuIdx=idx; // ensures selection gets cleared when menu is displayed
642 var drillValue=this.buffer.getWindowCell(idx.row,masterColNum);
643 for (var i=3; i<arguments.length; i++)
644 arguments[i].setDetailFilter(detailColNum,drillValue);
649 * set filter on a detail grid that is in a master-detail relationship
651 setDetailFilter: function(colNumber,filterValue) {
652 var c=this.columns[colNumber];
653 c.format.ColData=filterValue;
654 c.setSystemFilter('EQ',filterValue);
658 * Create one table for frozen columns and one for scrolling columns.
659 * Also create div's to contain them.
660 * @returns true on success
662 createTables: function() {
663 var insertloc,hdrSrc,i;
664 var table = document.getElementById(this.tableId) || document.getElementById(this.tableId+'_outerDiv');
665 if (!table) return false;
666 if (table.tagName.toLowerCase()=='table') {
667 var theads=table.getElementsByTagName("thead");
668 if (theads.length == 1) {
669 Rico.log("createTables: using thead section, id="+this.tableId);
670 if (this.options.PanelNamesOnTabHdr && this.options.panels) {
671 var r=theads[0].insertRow(0);
672 this.insertPanelNames(r, 0, this.options.frozenColumns, 'ricoFrozen');
673 this.insertPanelNames(r, this.options.frozenColumns, this.options.columnSpecs.length);
675 hdrSrc=theads[0].rows;
677 Rico.log("createTables: using tbody section, id="+this.tableId);
678 hdrSrc=new Array(table.rows[0]);
681 } else if (this.options.columnSpecs.length > 0) {
682 if (!table.id.match(/_outerDiv$/)) insertloc=table;
683 Rico.log("createTables: inserting at "+table.tagName+", id="+this.tableId);
685 alert("ERROR!\n\nUnable to initialize '"+this.tableId+"'\n\nLiveGrid terminated");
690 this.scrollContainer = this.createDiv("scrollContainer",this.structTabLR);
691 this.scrollContainer.appendChild(this.scrollDiv); // move scrollDiv
692 this.scrollTab = this.createDiv("scrollTab",this.scrollContainer);
693 this.shadowDiv = this.createDiv("shadow",this.scrollDiv);
694 this.shadowDiv.style.direction='ltr'; // avoid FF bug
695 this.scrollDiv.style.display="none";
696 this.scrollDiv.scrollTop=0;
697 if (this.options.highlightMethod!='class') {
698 this.highlightDiv=[];
699 switch (this.options.highlightElem) {
702 this.highlightDiv[0] = this.createDiv("highlight",this.outerDiv);
703 this.highlightDiv[0].style.display="none";
707 for (i=0; i<2; i++) {
708 this.highlightDiv[i] = this.createDiv("highlight",i==0 ? this.frozenTabs : this.scrollTab);
709 this.highlightDiv[i].style.display="none";
710 this.highlightDiv[i].id+=i;
714 // create one div for each side of the rectangle
715 var parentDiv=this.options.highlightSection==1 ? this.frozenTabs : this.scrollTab;
716 for (i=0; i<4; i++) {
717 this.highlightDiv[i] = this.createDiv("highlight",parentDiv);
718 this.highlightDiv[i].style.display="none";
719 this.highlightDiv[i].style.overflow="hidden";
720 this.highlightDiv[i].id+=i;
721 this.highlightDiv[i].style[i % 2==0 ? 'height' : 'width']="0px";
728 for (i=0; i<3; i++) {
729 this.tabs[i] = document.createElement("table");
730 this.tabs[i].className = 'ricoLG_table';
731 this.tabs[i].border=0;
732 this.tabs[i].cellPadding=0;
733 this.tabs[i].cellSpacing=0;
734 this.tabs[i].id = this.tableId+"_tab"+i;
737 for (i=0; i<2; i++) {
738 this.thead[i]=this.tabs[i].createTHead();
739 Rico.addClass(this.tabs[i],'ricoLG_top');
740 //this.thead[i].className='ricoLG_top';
741 if (Rico.theme.gridheader) Rico.addClass(this.thead[i],Rico.theme.gridheader);
744 for (i=0; i<2; i++) {
745 this.tbody[i]=Rico.getTBody(this.tabs[i==0?0:2]);
746 this.tbody[i].className='ricoLG_bottom';
747 if (Rico.theme.gridcontent) Rico.addClass(this.tbody[i],Rico.theme.gridcontent);
748 this.tbody[i].insertRow(-1);
750 this.frozenTabs.appendChild(this.tabs[0]);
751 this.innerDiv.appendChild(this.tabs[1]);
752 this.scrollTab.appendChild(this.tabs[2]);
753 if (insertloc) insertloc.parentNode.insertBefore(this.outerDiv,insertloc);
755 this.headerColCnt = this.getColumnInfo(hdrSrc);
756 this.loadHdrSrc(hdrSrc);
758 this.createHdr(0,0,this.options.frozenColumns);
759 this.createHdr(1,this.options.frozenColumns,this.options.columnSpecs.length);
760 if (this.options.PanelNamesOnTabHdr && this.options.panels) {
761 this.insertPanelNames(this.thead[0].insertRow(0), 0, this.options.frozenColumns);
762 this.insertPanelNames(this.thead[1].insertRow(0), this.options.frozenColumns, this.options.columnSpecs.length);
765 this.headerColCnt = this.getColumnInfo(this.thead[i].rows);
767 for( var c=0; c < this.headerColCnt; c++ )
768 this.tbody[c<this.options.frozenColumns ? 0 : 1].rows[0].insertCell(-1);
769 if (insertloc) table.parentNode.removeChild(table);
770 Rico.log('createTables end');
774 createDataCells: function(visibleRows) {
775 if (visibleRows < 0) {
776 for (var i=0; i<this.options.minPageRows; i++)
777 this.appendBlankRow();
779 this.autoAppendRows(this.remainingHt());
781 for( var r=0; r < visibleRows; r++ )
782 this.appendBlankRow();
784 var s=this.options.highlightSection;
785 if (s & 1) this.attachHighlightEvents(this.tbody[0]);
786 if (s & 2) this.attachHighlightEvents(this.tbody[1]);
790 * @param colnum column number
791 * @return id string for a filter element
793 filterId: function(colnum) {
794 return 'RicoFilter_'+this.tableId+'_'+colnum;
798 * Create filter elements in heading
799 * Reads this.columns[].filterUI to determine type of filter element for each column (t=text box, s=select list, c=custom)
800 * @param r heading row where filter elements will be placed
802 createFilters: function(r) {
803 for( var c=0; c < this.headerColCnt; c++ ) {
804 var col=this.columns[c];
806 if (typeof fmt.filterUI!='string') continue;
807 var cell=this.hdrCells[r][c].cell;
808 var field,name=this.filterId(c);
\r
809 var divs=cell.getElementsByTagName('div');
810 // copy text alignment from data cell
811 var align=Rico.getStyle(this.cell(0,c),'textAlign');
812 divs[1].style.textAlign=align;
813 switch (fmt.filterUI.charAt(0)) {
816 field=Rico.createFormField(divs[1],'input','text',name,name);
817 var size=fmt.filterUI.match(/\d+/);
818 field.maxLength=fmt.Length || 50;
\r
819 field.size=size ? parseInt(size,10) : 10;
820 divs[1].appendChild(Rico.clearButton(Rico.eventHandle(col,'filterClear')));
821 if (col.filterType==Rico.ColumnConst.USERFILTER && col.filterOp=='LIKE') {
822 var v=col.filterValues[0];
823 if (v.charAt(0)=='*') v=v.substr(1);
824 if (v.slice(-1)=='*') v=v.slice(0,-1);
828 Rico.eventBind(field,'keyup',Rico.eventHandle(col,'filterKeypress'),false);
829 col.filterField=field;
\r
835 field=Rico.createFormField(divs[1],'select',null,name);
\r
836 Rico.addSelectOption(field,this.options.FilterAllToken,Rico.getPhraseById("filterAll"));
\r
837 col.filterField=field;
839 Rico.extend(options, this.buffer.ajaxOptions);
840 var colnum=typeof(fmt.filterCol)=='number' ? fmt.filterCol : c;
841 options.parameters = {id: this.tableId, distinct:colnum};
842 options.parameters[this.actionId]="query";
843 options.onComplete = this.filterValuesUpdateFunc(c);
844 new Rico.ajaxRequest(this.buffer.dataSource, options);
848 if (typeof col._createFilters == 'function')
849 col._createFilters(divs[1], name);
853 this.initFilterImage(r);
856 filterValuesUpdateFunc: function(colnum) {
858 return function (request) { self.filterValuesUpdate(colnum,request); };
862 * update select list filter with values in AJAX response
863 * @returns true on success
865 filterValuesUpdate: function(colnum,request) {
866 var response = request.responseXML.getElementsByTagName("ajax-response");
867 Rico.log("filterValuesUpdate: "+request.status);
868 if (response == null || response.length != 1) return false;
869 response=response[0];
870 var error = response.getElementsByTagName('error');
871 if (error.length > 0) {
872 Rico.log("Data provider returned an error:\n"+Rico.getContentAsString(error[0],this.buffer.isEncoded));
873 alert(Rico.getPhraseById("requestError",Rico.getContentAsString(error[0],this.buffer.isEncoded)));
876 response=response.getElementsByTagName('response')[0];
\r
877 var rowsElement = response.getElementsByTagName('rows')[0];
\r
878 var col=this.columns[parseInt(colnum,10)];
879 var rows = this.buffer.dom2jstable(rowsElement);
\r
881 if (col.filterType==Rico.ColumnConst.USERFILTER && col.filterOp=='EQ') v=col.filterValues[0];
882 Rico.log('filterValuesUpdate: col='+colnum+' rows='+rows.length);
883 switch (col.format.filterUI.charAt(0)) {
886 col.mFilter = document.body.appendChild(document.createElement("div"));
887 col.mFilter.className = 'ricoLG_mFilter'
888 Rico.hide(col.mFilter);
889 var contentDiv = col.mFilter.appendChild(document.createElement("div"));
890 contentDiv.className = 'ricoLG_mFilter_content'
891 var buttonDiv = col.mFilter.appendChild(document.createElement("div"));
892 buttonDiv.className = 'ricoLG_mFilter_button'
893 col.mFilterButton=buttonDiv.appendChild(document.createElement("button"));
894 col.mFilterButton.innerHTML=Rico.getPhraseById("ok");
895 var eventName=Rico.isWebKit ? 'mousedown' : 'click';
896 Rico.eventBind(col.filterField,eventName,Rico.eventHandle(col,'mFilterSelectClick'));
897 Rico.eventBind(col.mFilterButton,'click',Rico.eventHandle(col,'mFilterFinish'));
898 //col.filterField.options[0].text=$('AllLabel').innerHTML;
899 tab = contentDiv.appendChild(document.createElement("table"));
903 //tbody=(tab.tBodies.length==0) ? tab.appendChild(document.createElement("tbody")) : tab.tBodies[0];
904 var baseId=this.filterId(colnum)+'_';
905 this.createMFilterItem(tab,this.options.FilterAllToken,Rico.getPhraseById("filterAll"),baseId+'all',Rico.eventHandle(col,'mFilterAllClick'));
906 var handle=Rico.eventHandle(col,'mFilterOtherClick')
907 for (var i=0; i<rows.length; i++) {
908 if (rows[i].length>0) {
910 this.createMFilterItem(tab,c,c || Rico.getPhraseById("filterBlank"),baseId+i,handle);
913 col.mFilterInputs=contentDiv.getElementsByTagName('input');
914 col.mFilterLabels=contentDiv.getElementsByTagName('label');
915 col.mFilterFocus=col.mFilterInputs.length ? col.mFilterInputs[0] : col.mFilterButton;
920 for (var i=0; i<rows.length; i++) {
921 if (rows[i].length>0) {
923 opt=Rico.addSelectOption(col.filterField,c,c || Rico.getPhraseById("filterBlank"));
924 if (col.filterType==Rico.ColumnConst.USERFILTER && c==v) opt.selected=true;
927 Rico.eventBind(col.filterField,'change',Rico.eventHandle(col,'filterChange'));
933 createMFilterItem: function(table,code,description,id,eventHandle) {
934 var tr=table.insertRow(-1);
936 if (tr.rowIndex % 2 == 1) tr.className='ricoLG_mFilter_oddrow';
937 var td1=tr.insertCell(-1)
938 var td2=tr.insertCell(-1)
939 var field=Rico.createFormField(td1,'input','checkbox',id);
942 var label = td2.appendChild(document.createElement("label"));
944 label.innerHTML=description;
945 Rico.eventBind(field,'click',eventHandle);
948 unplugHighlightEvents: function() {
949 var s=this.options.highlightSection;
950 if (s & 1) this.detachHighlightEvents(this.tbody[0]);
951 if (s & 2) this.detachHighlightEvents(this.tbody[1]);
955 * place panel names on first row of grid header (used by LiveGridForms)
957 insertPanelNames: function(r,start,limit,cellClass) {
958 Rico.log('insertPanelNames: start='+start+' limit='+limit);
959 r.className='ricoLG_hdg';
960 var lastIdx=-1, span, newCell=null, spanIdx=0;
961 for( var c=start; c < limit; c++ ) {
962 if (lastIdx == this.options.columnSpecs[c].panelIdx) {
965 if (newCell) newCell.colSpan=span;
966 newCell = r.insertCell(-1);
967 if (cellClass) newCell.className=cellClass;
969 lastIdx=this.options.columnSpecs[c].panelIdx;
970 newCell.innerHTML=this.options.panels[lastIdx];
973 if (newCell) newCell.colSpan=span;
977 * create grid header for table i (if none was provided)
979 createHdr: function(i,start,limit) {
980 Rico.log('createHdr: i='+i+' start='+start+' limit='+limit);
981 var mainRow = this.thead[i].insertRow(-1);
982 mainRow.id=this.tableId+'_tab'+i+'h_main';
983 mainRow.className='ricoLG_hdg';
984 for( var c=start; c < limit; c++ ) {
985 var newCell = mainRow.insertCell(-1);
986 newCell.innerHTML=this.options.columnSpecs[c].Hdg;
991 * move header cells in original table to grid
993 loadHdrSrc: function(hdrSrc) {
994 var i,h,c,r,newrow,cells;
995 Rico.log('loadHdrSrc start');
996 for (i=0; i<2; i++) {
997 for (r=0; r<hdrSrc.length; r++) {
998 newrow = this.thead[i].insertRow(-1);
999 newrow.className='ricoLG_hdg '+this.tableId+'_hdg'+r;
1002 if (hdrSrc.length==1) {
1003 cells=hdrSrc[0].cells;
1004 for (c=0; cells.length > 0; c++)
1005 this.thead[c<this.options.frozenColumns ? 0 : 1].rows[0].appendChild(cells[0]);
1007 for (r=0; r<hdrSrc.length; r++) {
1008 cells=hdrSrc[r].cells;
1009 for (c=0,h=0; cells.length > 0; c++) {
1010 if (cells[0].className=='ricoFrozen') {
1011 if (r==this.headerRowIdx) this.options.frozenColumns=c+1;
1015 this.thead[h].rows[r].appendChild(cells[0]);
1019 Rico.log('loadHdrSrc end');
1025 sizeDivs: function() {
1026 Rico.log('sizeDivs: '+this.tableId);
1027 //this.cancelMenu();
1029 this.baseSizeDivs();
1030 var firstVisible=this.firstVisible();
1031 if (this.pageSize == 0 || firstVisible < 0) return;
1032 var totRowHt=this.columns[firstVisible].dataColDiv.offsetHeight;
1033 this.rowHeight = Math.round(totRowHt/this.pageSize);
1034 var scrHt=this.dataHt;
1035 if (this.scrTabWi0 == this.scrTabWi) {
1036 // no scrolling columns - horizontal scroll bar not needed
1037 this.innerDiv.style.height=(this.hdrHt+1)+'px';
1038 this.scrollDiv.style.overflowX='hidden';
1040 this.scrollDiv.style.overflowX='scroll';
1041 scrHt+=this.options.scrollBarWidth;
1043 this.scrollDiv.style.height=scrHt+'px';
1044 this.innerDiv.style.width=(this.scrWi)+'px';
1045 this.scrollTab.style.width=(this.scrWi-this.options.scrollBarWidth)+'px';
1046 //this.resizeDiv.style.height=this.frozenTabs.style.height=this.innerDiv.style.height=(this.hdrHt+this.dataHt+1)+'px';
1047 this.resizeDiv.style.height=(this.hdrHt+this.dataHt+1)+'px';
1048 Rico.log('sizeDivs scrHt='+scrHt+' innerHt='+this.innerDiv.style.height+' rowHt='+this.rowHeight+' pageSize='+this.pageSize);
1049 var pad=(this.scrWi-this.scrTabWi < this.options.scrollBarWidth) ? 2 : 0;
1050 this.shadowDiv.style.width=(this.scrTabWi+pad)+'px';
1051 this.outerDiv.style.height=(this.hdrHt+scrHt)+'px';
1052 this.setHorizontalScroll();
1055 setHorizontalScroll: function() {
1056 var newLeft=(-this.scrollDiv.scrollLeft)+'px';
1057 this.tabs[1].style.marginLeft=newLeft;
1058 this.tabs[2].style.marginLeft=newLeft;
1061 remainingHt: function() {
1063 var winHt=Rico.windowHeight();
1064 var margin=Rico.isIE ? 15 : 10;
1065 // if there is a horizontal scrollbar take it into account
1066 if (!Rico.isIE && window.frameElement && window.frameElement.scrolling=='yes' && this.sizeTo!='parent') margin+=this.options.scrollBarWidth;
1067 switch (this.sizeTo) {
1069 var divTop=Rico.cumulativeOffset(this.outerDiv).top;
1070 tabHt=Math.max(this.tabs[0].offsetHeight,this.tabs[1].offsetHeight);
1071 Rico.log("remainingHt, winHt="+winHt+' tabHt='+tabHt+' gridY='+divTop);
1072 return winHt-divTop-tabHt-this.options.scrollBarWidth-margin; // allow for scrollbar and some margin
1074 var offset=this.offsetFromParent(this.outerDiv);
1075 tabHt=Math.max(this.tabs[0].offsetHeight,this.tabs[1].offsetHeight);
1076 if (Rico.isIE) Rico.hide(this.outerDiv);
1077 var parentHt=this.outerDiv.parentNode.offsetHeight;
1078 if (Rico.isIE) Rico.show(this.outerDiv);
1079 Rico.log("remainingHt, parentHt="+parentHt+' gridY='+offset+' winHt='+winHt+' tabHt='+tabHt);
1080 return parentHt - tabHt - offset - this.options.scrollBarWidth;
1083 var bodyHt=Rico.isIE ? document.body.scrollHeight : document.body.offsetHeight;
1084 //alert("remainingHt\n document.height="+document.height+"\n body.offsetHeight="+document.body.offsetHeight+"\n body.scrollHeight="+document.body.scrollHeight+"\n documentElement.scrollHeight="+document.documentElement.scrollHeight);
1085 var remHt=winHt-bodyHt-margin;
1086 if (!Rico.isWebKit) remHt-=this.options.scrollBarWidth;
1087 Rico.log("remainingHt, winHt="+winHt+' pageHt='+bodyHt+' remHt='+remHt);
1090 tabHt=Math.max(this.tabs[0].offsetHeight,this.tabs[1].offsetHeight);
1091 Rico.log("remainingHt, winHt="+winHt+' tabHt='+tabHt);
1092 if (this.sizeTo.slice(-1)=='%') winHt*=parseFloat(this.sizeTo)/100.0;
1093 else if (this.sizeTo.slice(-2)=='px') winHt=parseInt(this.sizeTo,10);
1094 return winHt-tabHt-this.options.scrollBarWidth-margin; // allow for scrollbar and some margin
1098 offsetFromParent: function(element) {
1100 var elParent=element.parentNode;
1102 //Rico.log("offsetFromParent: "+element.tagName+' id='+element.id+' otop='+element.offsetTop);
1103 valueT += element.offsetTop || 0;
1104 element = element.offsetParent;
1105 if (!element || element==null) break;
1106 var p = Rico.getStyle(element, 'position');
1107 if (element.tagName=='BODY' || element.tagName=='HTML' || p=='absolute') return valueT-elParent.offsetTop;
1108 } while (element != elParent);
1112 adjustPageSize: function() {
1113 var remHt=this.remainingHt();
1114 Rico.log('adjustPageSize remHt='+remHt+' lastRow='+this.lastRowPos);
1115 if (remHt > this.rowHeight)
1116 this.autoAppendRows(remHt);
1117 else if (remHt < 0 || this.sizeTo=='data')
1118 this.autoRemoveRows(-remHt);
1121 setPageSize: function(newRowCount) {
1122 newRowCount=Math.min(newRowCount,this.options.maxPageRows);
1123 newRowCount=Math.max(newRowCount,this.options.minPageRows);
1124 this.sizeTo='fixed';
1125 var oldSize=this.pageSize;
1126 while (this.pageSize > newRowCount) {
1129 while (this.pageSize < newRowCount) {
1130 this.appendBlankRow();
1132 this.finishResize(oldSize);
1135 pluginWindowResize: function() {
1136 Rico.log("pluginWindowResize");
1137 this.resizeWindowHandler=Rico.eventHandle(this,'resizeWindow');
1138 Rico.eventBind(window, "resize", this.resizeWindowHandler, false);
1141 unplugWindowResize: function() {
1142 if (!this.resizeWindowHandler) return;
1143 Rico.eventUnbind(window,"resize", this.resizeWindowHandler, false);
1144 this.resizeWindowHandler=null;
1147 resizeWindow: function() {
1148 Rico.log('resizeWindow '+this.tableId+' lastRow='+this.lastRowPos);
1149 if (this.resizeState=='finish') {
1150 Rico.log('resizeWindow postponed');
1151 this.resizeState='resize';
1154 if (!this.sizeTo || this.sizeTo=='fixed') {
1158 if (this.sizeTo=='parent' && Rico.getStyle(this.outerDiv.parentNode,'display') == 'none') return;
1159 var oldSize=this.pageSize;
1160 this.adjustPageSize();
1161 this.finishResize(oldSize);
1164 finishResize: function(oldSize) {
1165 if (this.pageSize > oldSize && this.buffer.totalRows>0) {
1166 this.isPartialBlank=true;
1167 var adjStart=this.adjustRow(this.lastRowPos);
1168 this.buffer.fetch(adjStart);
1169 } else if (this.pageSize < oldSize) {
1170 if (this.options.onRefreshComplete) this.options.onRefreshComplete(this.contentStartPos,this.contentStartPos+this.pageSize-1); // update bookmark
1172 this.resizeState='finish';
1173 Rico.runLater(20,this,'finishResize2');
1174 Rico.log('Resize '+this.tableId+' complete. old size='+oldSize+' new size='+this.pageSize);
1177 finishResize2: function() {
1179 this.updateHeightDiv();
1180 if (this.resizeState=='resize') {
1181 this.resizeWindow();
1183 this.resizeState='';
1187 topOfLastPage: function() {
1188 return Math.max(this.buffer.totalRows-this.pageSize,0);
1191 updateHeightDiv: function() {
1192 var notdisp=this.topOfLastPage();
1193 var ht = notdisp ? this.scrollDiv.clientHeight + Math.floor(this.rowHeight * (notdisp + 0.4)) : 1;
1194 Rico.log("updateHeightDiv, ht="+ht+' scrollDiv.clientHeight='+this.scrollDiv.clientHeight+' rowsNotDisplayed='+notdisp);
1195 this.shadowDiv.style.height=ht+'px';
1198 autoRemoveRows: function(overage) {
1199 if (!this.rowHeight) return;
1200 var removeCnt=Math.ceil(overage / this.rowHeight);
1201 if (this.sizeTo=='data')
1202 removeCnt=Math.max(removeCnt,this.pageSize-this.buffer.totalRows);
1203 Rico.log("autoRemoveRows overage="+overage+" removeCnt="+removeCnt);
1204 for (var i=0; i<removeCnt; i++)
1208 removeRow: function() {
1209 if (this.pageSize <= this.options.minPageRows) return;
1211 for( var c=0; c < this.headerColCnt; c++ ) {
1212 var cell=this.columns[c].cell(this.pageSize);
1213 this.columns[c].dataColDiv.removeChild(cell);
1217 autoAppendRows: function(overage) {
1218 if (!this.rowHeight) return;
1219 var addCnt=Math.floor(overage / this.rowHeight);
1220 Rico.log("autoAppendRows overage="+overage+" cnt="+addCnt+" rowHt="+this.rowHeight);
1221 for (var i=0; i<addCnt; i++) {
1222 if (this.sizeTo=='data' && this.pageSize>=this.buffer.totalRows) break;
1223 this.appendBlankRow();
1228 * on older systems, this can be fairly slow
1230 appendBlankRow: function() {
1231 if (this.pageSize >= this.options.maxPageRows) return;
1232 Rico.log("appendBlankRow #"+this.pageSize);
1233 var cls=this.defaultRowClass(this.pageSize);
1234 for( var c=0; c < this.headerColCnt; c++ ) {
1235 var newdiv = document.createElement("div");
1236 newdiv.className = 'ricoLG_cell '+cls;
1237 newdiv.id=this.tableId+'_'+this.pageSize+'_'+c;
1238 this.columns[c].dataColDiv.appendChild(newdiv);
1239 if (this.columns[c].format.canDrag && Rico.registerDraggable)
1240 Rico.registerDraggable( new Rico.LiveGridDraggable(this, this.pageSize, c), this.options.dndMgrIdx );
1241 newdiv.innerHTML=' '; // this seems to be required by IE
1242 if (this.columns[c]._create) {
1243 this.columns[c]._create(newdiv,this.pageSize);
1249 defaultRowClass: function(rownum) {
1251 if (rownum % 2==0) {
1252 cls='ricoLG_evenRow';
1253 //if (Rico.theme.primary) cls+=' '+Rico.theme.primary;
1255 cls='ricoLG_oddRow';
1256 //if (Rico.theme.secondary) cls+=' '+Rico.theme.secondary;
1261 handleMenuClick: function(e) {
1262 if (!this.menu) return;
1264 this.unhighlight(); // in case highlighting was invoked externally
1266 var cell=Rico.eventElement(e);
1267 if (cell.className=='ricoLG_highlightDiv') {
1268 idx=this.highlightIdx;
1270 cell=Rico.getParentByTagName(cell,'div','ricoLG_cell');
1272 idx=this.winCellIndex(cell);
1273 if ((this.options.highlightSection & (idx.tabIdx+1))==0) return;
1275 this.highlight(idx);
1276 this.highlightEnabled=false;
1277 if (this.hideScroll) this.scrollDiv.style.overflow="hidden";
1279 if (!this.menu.div) this.menu.createDiv();
1280 this.menu.liveGrid=this;
1281 if (this.menu.buildGridMenu) {
1282 var showMenu=this.menu.buildGridMenu(idx.row, idx.column, idx.tabIdx);
1283 if (!showMenu) return;
1285 if (this.options.highlightElem=='selection' && !this.isSelected(idx.cell)) {
1286 this.selectCell(idx.cell);
1289 this.menu.showmenu(e,function() { self.closeMenu(); });
1292 closeMenu: function() {
1293 if (!this.menuIdx) return;
1294 if (this.hideScroll) this.scrollDiv.style.overflow="";
1295 //this.unhighlight();
1296 this.highlightEnabled=true;
1301 * @return index of cell within the window
1303 winCellIndex: function(cell) {
1304 var l=cell.id.lastIndexOf('_',cell.id.length);
1305 var l2=cell.id.lastIndexOf('_',l-1)+1;
1306 var c=parseInt(cell.id.substr(l+1));
1307 var r=parseInt(cell.id.substr(l2,l));
1308 return {row:r, column:c, tabIdx:this.columns[c].tabIdx, cell:cell};
1312 * @return index of cell within the dataset
1314 datasetIndex: function(cell) {
1315 var idx=this.winCellIndex(cell);
1316 idx.row+=this.buffer.windowPos;
1317 idx.onBlankRow=(idx.row >= this.buffer.endPos());
1321 attachHighlightEvents: function(tBody) {
1322 switch (this.options.highlightElem) {
1324 Rico.eventBind(tBody,"mousedown", this.options.mouseDownHandler, false);
1326 tBody.ondrag = function () { return false; };
1328 tBody.onselectstart = function () { return false; };
1332 Rico.eventBind(tBody,"mouseover", this.options.rowOverHandler, false);
1337 detachHighlightEvents: function(tBody) {
1338 switch (this.options.highlightElem) {
1340 Rico.eventUnbind(tBody,"mousedown", this.options.mouseDownHandler, false);
1341 tBody.ondrag = null;
1342 tBody.onselectstart = null;
1346 Rico.eventUnbind(tBody,"mouseover", this.options.rowOverHandler, false);
1352 * @return array of objects containing row/col indexes (index values are relative to the start of the window)
1354 getVisibleSelection: function() {
1356 if (this.SelectIdxStart && this.SelectIdxEnd) {
1357 var r1=Math.max(Math.min(this.SelectIdxEnd.row,this.SelectIdxStart.row)-this.buffer.startPos,this.buffer.windowStart);
1358 var r2=Math.min(Math.max(this.SelectIdxEnd.row,this.SelectIdxStart.row)-this.buffer.startPos,this.buffer.windowEnd-1);
1359 var c1=Math.min(this.SelectIdxEnd.column,this.SelectIdxStart.column);
1360 var c2=Math.max(this.SelectIdxEnd.column,this.SelectIdxStart.column);
1361 //Rico.log("getVisibleSelection "+r1+','+c1+' to '+r2+','+c2+' ('+this.SelectIdxStart.row+',startPos='+this.buffer.startPos+',windowPos='+this.buffer.windowPos+',windowEnd='+this.buffer.windowEnd+')');
1362 for (var r=r1; r<=r2; r++) {
1363 for (var c=c1; c<=c2; c++)
1364 cellList.push({row:r-this.buffer.windowStart,column:c});
1367 if (this.SelectCtrl) {
1368 for (var i=0; i<this.SelectCtrl.length; i++) {
1369 if (this.SelectCtrl[i].row>=this.buffer.windowStart && this.SelectCtrl[i].row<this.buffer.windowEnd)
1370 cellList.push({row:this.SelectCtrl[i].row-this.buffer.windowStart,column:this.SelectCtrl[i].column});
1376 updateSelectOutline: function() {
1377 if (!this.SelectIdxStart || !this.SelectIdxEnd) return;
1378 var r1=Math.max(Math.min(this.SelectIdxEnd.row,this.SelectIdxStart.row), this.buffer.windowStart);
1379 var r2=Math.min(Math.max(this.SelectIdxEnd.row,this.SelectIdxStart.row), this.buffer.windowEnd-1);
1381 this.HideSelection();
1384 var c1=Math.min(this.SelectIdxEnd.column,this.SelectIdxStart.column);
1385 var c2=Math.max(this.SelectIdxEnd.column,this.SelectIdxStart.column);
1386 var top1=this.columns[c1].cell(r1-this.buffer.windowStart).offsetTop;
1387 var cell2=this.columns[c1].cell(r2-this.buffer.windowStart);
1388 var bottom2=cell2.offsetTop+cell2.offsetHeight;
1389 var left1=this.columns[c1].dataCell.offsetLeft;
1390 var left2=this.columns[c2].dataCell.offsetLeft;
1391 var right2=left2+this.columns[c2].dataCell.offsetWidth;
1392 //window.status='updateSelectOutline: '+r1+' '+r2+' top='+top1+' bot='+bottom2;
1393 this.highlightDiv[0].style.top=this.highlightDiv[3].style.top=this.highlightDiv[1].style.top=(this.hdrHt+top1-1) + 'px';
1394 this.highlightDiv[2].style.top=(this.hdrHt+bottom2-1)+'px';
1395 this.highlightDiv[3].style.left=(left1-2)+'px';
1396 this.highlightDiv[0].style.left=this.highlightDiv[2].style.left=(left1-1)+'px';
1397 this.highlightDiv[1].style.left=(right2-1)+'px';
1398 this.highlightDiv[0].style.width=this.highlightDiv[2].style.width=(right2-left1-1) + 'px';
1399 this.highlightDiv[1].style.height=this.highlightDiv[3].style.height=(bottom2-top1) + 'px';
1400 //this.highlightDiv[0].style.right=this.highlightDiv[2].style.right=this.highlightDiv[1].style.right=()+'px';
1401 //this.highlightDiv[2].style.bottom=this.highlightDiv[3].style.bottom=this.highlightDiv[1].style.bottom=(this.hdrHt+bottom2) + 'px';
1402 for (var i=0; i<4; i++)
1403 this.highlightDiv[i].style.display='';
1406 HideSelection: function() {
1408 if (this.options.highlightMethod!='class') {
1409 for (i=0; i<this.highlightDiv.length; i++)
1410 this.highlightDiv[i].style.display='none';
1412 if (this.options.highlightMethod!='outline') {
1413 var cellList=this.getVisibleSelection();
1414 Rico.log("HideSelection "+cellList.length);
1415 for (i=0; i<cellList.length; i++)
1416 this.unhighlightCell(this.columns[cellList[i].column].cell(cellList[i].row));
1420 ShowSelection: function() {
1421 if (this.options.highlightMethod!='class')
1422 this.updateSelectOutline();
1423 if (this.options.highlightMethod!='outline') {
1424 var cellList=this.getVisibleSelection();
1425 for (var i=0; i<cellList.length; i++)
1426 this.highlightCell(this.columns[cellList[i].column].cell(cellList[i].row));
1430 ClearSelection: function() {
1431 Rico.log("ClearSelection");
1432 this.HideSelection();
1433 this.SelectIdxStart=null;
1434 this.SelectIdxEnd=null;
1438 selectCell: function(cell) {
1439 this.ClearSelection();
1440 this.SelectIdxStart=this.SelectIdxEnd=this.datasetIndex(cell);
1441 this.ShowSelection();
1444 AdjustSelection: function(cell) {
1445 var newIdx=this.datasetIndex(cell);
1446 if (this.SelectIdxStart.tabIdx != newIdx.tabIdx) return;
1447 this.HideSelection();
1448 this.SelectIdxEnd=newIdx;
1449 this.ShowSelection();
1452 RefreshSelection: function() {
1453 var cellList=this.getVisibleSelection();
1454 for (var i=0; i<cellList.length; i++) {
1455 this.columns[cellList[i].column].displayValue(cellList[i].row);
1459 FillSelection: function(newVal,newStyle) {
1460 if (this.SelectIdxStart && this.SelectIdxEnd) {
1461 var r1=Math.min(this.SelectIdxEnd.row,this.SelectIdxStart.row);
1462 var r2=Math.max(this.SelectIdxEnd.row,this.SelectIdxStart.row);
1463 var c1=Math.min(this.SelectIdxEnd.column,this.SelectIdxStart.column);
1464 var c2=Math.max(this.SelectIdxEnd.column,this.SelectIdxStart.column);
1465 for (var r=r1; r<=r2; r++) {
1466 for (var c=c1; c<=c2; c++) {
1467 this.buffer.setValue(r,c,newVal,newStyle);
1471 if (this.SelectCtrl) {
1472 for (var i=0; i<this.SelectCtrl.length; i++) {
1473 this.buffer.setValue(this.SelectCtrl[i].row,this.SelectCtrl[i].column,newVal,newStyle);
1476 this.RefreshSelection();
1480 * Process mouse down event
1481 * @param e event object
1483 selectMouseDown: function(e) {
1484 if (this.highlightEnabled==false) return true;
1486 var cell=Rico.eventElement(e);
1487 if (!Rico.eventLeftClick(e)) return true;
1488 cell=Rico.getParentByTagName(cell,'div','ricoLG_cell');
1489 if (!cell) return true;
1491 var newIdx=this.datasetIndex(cell);
1492 if (newIdx.onBlankRow) return true;
1493 Rico.log("selectMouseDown @"+newIdx.row+','+newIdx.column);
1495 if (!this.SelectIdxStart || this.options.highlightMethod!='class') return true;
1496 if (!this.isSelected(cell)) {
1497 this.highlightCell(cell);
1498 this.SelectCtrl.push(this.datasetIndex(cell));
1500 for (var i=0; i<this.SelectCtrl.length; i++) {
1501 if (this.SelectCtrl[i].row==newIdx.row && this.SelectCtrl[i].column==newIdx.column) {
1502 this.unhighlightCell(cell);
1503 this.SelectCtrl.splice(i,1);
1508 } else if (e.shiftKey) {
1509 if (!this.SelectIdxStart) return true;
1510 this.AdjustSelection(cell);
1512 this.selectCell(cell);
1513 this.pluginSelect();
1518 pluginSelect: function() {
1519 if (this.selectPluggedIn) return;
1520 var tBody=this.tbody[this.SelectIdxStart.tabIdx];
1521 Rico.eventBind(tBody,"mouseover", this.options.mouseOverHandler, false);
1522 Rico.eventBind(this.outerDiv,"mouseup", this.options.mouseUpHandler, false);
1523 this.selectPluggedIn=true;
1526 unplugSelect: function() {
1527 if (!this.selectPluggedIn) return;
1528 var tBody=this.tbody[this.SelectIdxStart.tabIdx];
1529 Rico.eventUnbind(tBody,"mouseover", this.options.mouseOverHandler , false);
1530 Rico.eventUnbind(this.outerDiv,"mouseup", this.options.mouseUpHandler , false);
1531 this.selectPluggedIn=false;
1534 selectMouseUp: function(e) {
1535 this.unplugSelect();
1536 var cell=Rico.eventElement(e);
1537 cell=Rico.getParentByTagName(cell,'div','ricoLG_cell');
1539 if (this.SelectIdxStart && this.SelectIdxEnd)
1540 this.AdjustSelection(cell);
1542 this.ClearSelection();
1545 selectMouseOver: function(e) {
1546 var cell=Rico.eventElement(e);
1547 cell=Rico.getParentByTagName(cell,'div','ricoLG_cell');
1549 this.AdjustSelection(cell);
1553 isSelected: function(cell) {
1554 if (this.options.highlightMethod!='outline') return Rico.hasClass(cell,this.options.highlightClass);
1555 if (!this.SelectIdxStart || !this.SelectIdxEnd) return false;
1556 var r1=Math.max(Math.min(this.SelectIdxEnd.row,this.SelectIdxStart.row), this.buffer.windowStart);
1557 var r2=Math.min(Math.max(this.SelectIdxEnd.row,this.SelectIdxStart.row), this.buffer.windowEnd-1);
1558 if (r1 > r2) return false;
1559 var c1=Math.min(this.SelectIdxEnd.column,this.SelectIdxStart.column);
1560 var c2=Math.max(this.SelectIdxEnd.column,this.SelectIdxStart.column);
1561 var curIdx=this.datasetIndex(cell);
1562 return (r1<=curIdx.row && curIdx.row<=r2 && c1<=curIdx.column && curIdx.column<=c2);
1565 highlightCell: function(cell) {
1566 Rico.addClass(cell,this.options.highlightClass);
1569 unhighlightCell: function(cell) {
1570 if (cell==null) return;
1571 Rico.removeClass(cell,this.options.highlightClass);
1574 selectRow: function(r) {
1575 for (var c=0; c<this.columns.length; c++)
1576 this.highlightCell(this.columns[c].cell(r));
1579 unselectRow: function(r) {
1580 for (var c=0; c<this.columns.length; c++)
1581 this.unhighlightCell(this.columns[c].cell(r));
1584 rowMouseOver: function(e) {
1585 if (!this.highlightEnabled) return;
1586 var cell=Rico.eventElement(e);
1587 cell=Rico.getParentByTagName(cell,'div','ricoLG_cell');
1589 var newIdx=this.winCellIndex(cell);
1590 if ((this.options.highlightSection & (newIdx.tabIdx+1))==0) return;
1591 this.highlight(newIdx);
1594 highlight: function(newIdx) {
1595 if (this.options.highlightMethod!='outline') this.cursorSetClass(newIdx);
1596 if (this.options.highlightMethod!='class') this.cursorOutline(newIdx);
1597 this.highlightIdx=newIdx;
1600 cursorSetClass: function(newIdx) {
1601 switch (this.options.highlightElem) {
1604 if (this.highlightIdx) this.unhighlightCell(this.highlightIdx.cell);
1605 this.highlightCell(newIdx.cell);
1609 if (this.highlightIdx) this.unselectRow(this.highlightIdx.row);
1610 var s1=this.options.highlightSection & 1;
1611 var s2=this.options.highlightSection & 2;
1612 var c0=s1 ? 0 : this.options.frozenColumns;
1613 var c1=s2 ? this.columns.length : this.options.frozenColumns;
1614 for (var c=c0; c<c1; c++)
1615 this.highlightCell(this.columns[c].cell(newIdx.row));
1621 cursorOutline: function(newIdx) {
1623 switch (this.options.highlightElem) {
1626 div=this.highlightDiv[newIdx.tabIdx];
1627 div.style.left=(this.columns[newIdx.column].dataCell.offsetLeft-1)+'px';
1628 div.style.width=this.columns[newIdx.column].colWidth;
1629 this.highlightDiv[1-newIdx.tabIdx].style.display='none';
1633 div=this.highlightDiv[0];
1634 var s1=this.options.highlightSection & 1;
1635 var s2=this.options.highlightSection & 2;
1636 div.style.left=s1 ? '0px' : this.frozenTabs.style.width;
1637 div.style.width=((s1 ? this.frozenTabs.offsetWidth : 0) + (s2 ? this.innerDiv.offsetWidth : 0) - 4)+'px';
1641 div.style.top=(this.hdrHt+newIdx.row*this.rowHeight-1)+'px';
1642 div.style.height=(this.rowHeight-1)+'px';
1643 div.style.display='';
1646 unhighlight: function() {
1647 switch (this.options.highlightElem) {
1649 //this.highlightIdx=this.menuIdx;
1652 if (this.highlightIdx) this.unhighlightCell(this.highlightIdx.cell);
1653 if (!this.highlightDiv) return;
1654 for (var i=0; i<2; i++)
1655 this.highlightDiv[i].style.display='none';
1658 //this.highlightIdx=this.menuIdx;
1661 if (this.highlightIdx) this.unselectRow(this.highlightIdx.row);
1662 if (this.highlightDiv) this.highlightDiv[0].style.display='none';
1667 resetContents: function() {
1668 Rico.log("resetContents");
1669 this.ClearSelection();
1670 this.buffer.clear();
1672 this.clearBookmark();
1675 setImages: function() {
1676 for (var n=0; n<this.columns.length; n++)
1677 this.columns[n].setImage();
1681 * @return column index, or -1 if there are no sorted columns
1683 findSortedColumn: function() {
1684 for (var n=0; n<this.columns.length; n++) {
1685 if (this.columns[n].isSorted()) return n;
1690 findColumnName: function(name) {
1691 for (var n=0; n<this.columns.length; n++) {
1692 if (this.columns[n].fieldName == name) return n;
1698 * Searches options.columnSpecs colAttr for matching colValue
1699 * @return array of matching column indexes
1701 findColumnsBySpec: function(colAttr, colValue) {
1703 for (var n=0; n<this.options.columnSpecs.length; n++) {
1704 if (this.options.columnSpecs[n][colAttr] == colValue) result.push(n);
1712 setSortUI: function( columnNameOrNum, sortDirection ) {
1713 Rico.log("setSortUI: "+columnNameOrNum+' '+sortDirection);
1714 var colnum=this.findSortedColumn();
1716 sortDirection=this.columns[colnum].getSortDirection();
1718 if (typeof sortDirection!='string') {
1719 sortDirection=Rico.ColumnConst.SORT_ASC;
1721 sortDirection=sortDirection.toUpperCase();
1722 if (sortDirection != Rico.ColumnConst.SORT_DESC) sortDirection=Rico.ColumnConst.SORT_ASC;
1724 switch (typeof columnNameOrNum) {
1726 colnum=this.findColumnName(columnNameOrNum);
1729 colnum=columnNameOrNum;
1733 if (typeof(colnum)!='number' || colnum < 0) return;
1735 this.columns[colnum].setSorted(sortDirection);
1736 this.buffer.sortBuffer(colnum);
1740 * clear sort flag on all columns
1742 clearSort: function() {
1743 for (var x=0;x<this.columns.length;x++)
1744 this.columns[x].setUnsorted();
1748 * clear filters on all columns
1750 clearFilters: function() {
1751 for (var x=0;x<this.columns.length;x++) {
1752 this.columns[x].setUnfiltered(true);
1754 if (this.options.filterHandler) {
1755 this.options.filterHandler();
1760 * returns number of columns with a user filter set
1762 filterCount: function() {
1763 for (var x=0,cnt=0;x<this.columns.length;x++) {
1764 if (this.columns[x].isFiltered()) cnt++;
1769 sortHandler: function() {
1771 this.ClearSelection();
1773 var n=this.findSortedColumn();
1775 Rico.log("sortHandler: sorting column "+n);
1776 this.buffer.sortBuffer(n);
1778 this.scrollDiv.scrollTop = 0;
1779 this.buffer.fetch(0);
1782 filterHandler: function() {
1783 Rico.log("filterHandler");
1785 if (this.buffer.processingRequest) {
1786 this.queueFilter=true;
1789 this.unplugScroll();
1790 this.ClearSelection();
1792 this.clearBookmark();
1794 this.buffer.fetch(-1);
1795 Rico.runLater(10,this,'pluginScroll'); // resetting ht div can cause a scroll event, triggering an extra fetch
1798 clearBookmark: function() {
1799 if (this.bookmark) this.bookmark.innerHTML=" ";
1802 bookmarkHandler: function(firstrow,lastrow) {
1804 if (isNaN(firstrow) || !this.bookmark) return;
1805 var totrows=this.buffer.totalRows;
1806 if (totrows < lastrow) lastrow=totrows;
1808 newhtml = Rico.getPhraseById('bookmarkNoMatch');
1809 } else if (lastrow<0) {
1810 newhtml = Rico.getPhraseById('bookmarkNoRec');
1811 } else if (this.buffer.foundRowCount) {
1812 newhtml = Rico.getPhraseById('bookmarkExact',firstrow,lastrow,totrows);
1814 newhtml = Rico.getPhraseById('bookmarkAbout',firstrow,lastrow,totrows);
1816 this.bookmark.innerHTML = newhtml;
1819 clearRows: function() {
1820 if (this.isBlank==true) return;
1821 for (var c=0; c < this.columns.length; c++)
1822 this.columns[c].clearColumn();
1823 this.isBlank = true;
1826 refreshContents: function(startPos) {
1827 Rico.log("refreshContents1 "+this.tableId+": startPos="+startPos+" lastRow="+this.lastRowPos+" PartBlank="+this.isPartialBlank+" pageSize="+this.pageSize);
1830 this.unhighlight(); // in case highlighting was manually invoked
1831 if (this.queueFilter) {
1832 Rico.log("refreshContents: cancelling refresh because filter has changed");
1833 this.queueFilter=false;
1834 this.filterHandler();
1837 this.highlightEnabled=this.options.highlightSection!='none';
1838 var viewPrecedesBuffer = this.buffer.startPos > startPos;
1839 var contentStartPos = viewPrecedesBuffer ? this.buffer.startPos: startPos;
1840 this.contentStartPos = contentStartPos+1;
1841 var contentEndPos = Math.min(this.buffer.startPos + this.buffer.size, startPos + this.pageSize);
1842 this.buffer.setWindow(contentStartPos, contentEndPos);
1843 Rico.log('refreshContents2 '+this.tableId+': cStartPos='+contentStartPos+' cEndPos='+contentEndPos+' vPrecedesBuf='+viewPrecedesBuffer+' b.startPos='+this.buffer.startPos);
1844 if (startPos == this.lastRowPos && !this.isPartialBlank && !this.isBlank) return;
1845 this.isBlank = false;
1846 var onRefreshComplete = this.options.onRefreshComplete;
1848 if ((startPos + this.pageSize < this.buffer.startPos) ||
1849 (this.buffer.startPos + this.buffer.size < startPos) ||
1850 (this.buffer.size == 0)) {
1852 if (onRefreshComplete) onRefreshComplete(this.contentStartPos,contentEndPos); // update bookmark
1856 Rico.log('refreshContents: contentStartPos='+contentStartPos+' contentEndPos='+contentEndPos+' viewPrecedesBuffer='+viewPrecedesBuffer);
1857 var rowSize = contentEndPos - contentStartPos;
1858 var blankSize = this.pageSize - rowSize;
1859 var blankOffset = viewPrecedesBuffer ? 0: rowSize;
1860 var contentOffset = viewPrecedesBuffer ? blankSize: 0;
1862 for (var r=0; r < rowSize; r++) { //initialize what we have
1863 for (var c=0; c < this.columns.length; c++)
1864 this.columns[c].displayValue(r + contentOffset);
1866 for (var i=0; i < blankSize; i++) // blank out the rest
1867 this.blankRow(i + blankOffset);
1868 if (this.options.highlightElem=='selection') this.ShowSelection();
1869 this.isPartialBlank = blankSize > 0;
1870 this.lastRowPos = startPos;
1871 Rico.log("refreshContents complete, startPos="+startPos);
1872 if (onRefreshComplete) onRefreshComplete(this.contentStartPos,contentEndPos); // update bookmark
1875 scrollToRow: function(rowOffset) {
1876 var p=this.rowToPixel(rowOffset);
1877 Rico.log("scrollToRow, rowOffset="+rowOffset+" pixel="+p);
1878 this.scrollDiv.scrollTop = p; // this causes a scroll event
1879 if ( this.options.onscroll )
1880 this.options.onscroll( this, rowOffset );
1883 scrollUp: function() {
1884 this.moveRelative(-1);
1887 scrollDown: function() {
1888 this.moveRelative(1);
1891 pageUp: function() {
1892 this.moveRelative(-this.pageSize);
1895 pageDown: function() {
1896 this.moveRelative(this.pageSize);
1899 adjustRow: function(rowOffset) {
1900 var notdisp=this.topOfLastPage();
1901 if (notdisp == 0 || !rowOffset) return 0;
1902 return Math.min(notdisp,rowOffset);
1905 rowToPixel: function(rowOffset) {
1906 return this.adjustRow(rowOffset) * this.rowHeight;
1910 * @returns row to display at top of scroll div
1912 pixeltorow: function(p) {
1913 var notdisp=this.topOfLastPage();
1914 if (notdisp == 0) return 0;
1915 var prow=parseInt(p/this.rowHeight,10);
1916 return Math.min(notdisp,prow);
1919 moveRelative: function(relOffset) {
1920 var newoffset=Math.max(this.scrollDiv.scrollTop+relOffset*this.rowHeight,0);
1921 newoffset=Math.min(newoffset,this.scrollDiv.scrollHeight);
1922 //Rico.log("moveRelative, newoffset="+newoffset);
1923 this.scrollDiv.scrollTop=newoffset;
1926 pluginScroll: function() {
1927 if (this.scrollPluggedIn) return;
1928 Rico.log("pluginScroll: wheelEvent="+this.wheelEvent);
1929 Rico.eventBind(this.scrollDiv,"scroll",this.scrollEventFunc, false);
1930 for (var t=0; t<2; t++)
1931 Rico.eventBind(this.tabs[t],this.wheelEvent,this.wheelEventFunc, false);
1932 this.scrollPluggedIn=true;
1935 unplugScroll: function() {
1936 if (!this.scrollPluggedIn) return;
1937 Rico.log("unplugScroll");
1938 Rico.eventUnbind(this.scrollDiv,"scroll", this.scrollEventFunc , false);
1939 for (var t=0; t<2; t++)
1940 Rico.eventUnbind(this.tabs[t],this.wheelEvent,this.wheelEventFunc, false);
1941 this.scrollPluggedIn=false;
1944 handleWheel: function(e) {
1948 delta = e.wheelDelta/120;
1949 else if (Rico.isWebKit)
1950 delta = -e.wheelDelta/12;
1952 delta = -e.wheelDelta/120;
1953 } else if (e.detail) {
1954 delta = e.detail/3; /* Mozilla/Gecko */
1956 if (delta) this.moveRelative(delta);
1961 handleScroll: function(e) {
1962 if ( this.scrollTimeout )
1963 clearTimeout( this.scrollTimeout );
1964 this.setHorizontalScroll();
1965 var scrtop=this.scrollDiv.scrollTop;
1966 var vscrollDiff = this.lastScrollPos-scrtop;
1967 if (vscrollDiff == 0.00) return;
1968 var newrow=this.pixeltorow(scrtop);
1969 if (newrow == this.lastRowPos && !this.isPartialBlank && !this.isBlank) return;
1970 var stamp1 = new Date();
1971 Rico.log("handleScroll, newrow="+newrow+" scrtop="+scrtop);
1972 if (this.options.highlightElem=='selection') this.HideSelection();
1973 this.buffer.fetch(newrow);
1974 if (this.options.onscroll) this.options.onscroll(this, newrow);
1975 this.scrollTimeout = Rico.runLater(1200,this,'scrollIdle');
1976 this.lastScrollPos = this.scrollDiv.scrollTop;
1977 var stamp2 = new Date();
1978 //Rico.log("handleScroll, time="+(stamp2.getTime()-stamp1.getTime()));
1981 scrollIdle: function() {
1982 if ( this.options.onscrollidle )
1983 this.options.onscrollidle();
1989 Rico.LiveGridColumn = function(grid,colIdx,hdrInfo,tabIdx) {
1990 this.initialize(grid,colIdx,hdrInfo,tabIdx);
1993 Rico.LiveGridColumn.prototype =
1994 /** @lends Rico.LiveGridColumn# */
1997 * Implements a LiveGrid column. Also contains static properties used by SimpleGrid columns.
1998 * @extends Rico.TableColumnBase
2001 initialize: function(liveGrid,colIdx,hdrInfo,tabIdx) {
2002 Rico.extend(this, new Rico.TableColumnBase());
2003 this.baseInit(liveGrid,colIdx,hdrInfo,tabIdx);
2004 this.buffer=liveGrid.buffer;
2005 if (typeof(this.format.type)!='string' || this.format.EntryType=='tinyMCE') this.format.type='raw';
2006 if (typeof this.isNullable!='boolean') this.isNullable = /number|date/.test(this.format.type);
2007 this.isText = /raw|text|showTags/.test(this.format.type);
2008 Rico.log(" sortable="+this.sortable+" filterable="+this.filterable+" hideable="+this.hideable+" isNullable="+this.isNullable+' isText='+this.isText);
2009 this.fixHeaders(this.liveGrid.tableId, this.options.hdrIconsFirst);
2010 if (this['format_'+this.format.type]) {
2011 this._format=this['format_'+this.format.type];
2013 if (this.format.control) {
2014 // copy all properties/methods that start with '_'
2015 if (typeof this.format.control=='string') {
2016 this.format.control=eval(this.format.control);
2018 for (var property in this.format.control) {
2019 if (property.charAt(0)=='_') {
2020 Rico.log("Copying control property "+property+ ' to ' + this);
2021 this[property] = this.format.control[property];
2028 * Sorts the column in ascending order
2030 sortAsc: function() {
2031 this.setColumnSort(Rico.ColumnConst.SORT_ASC);
2035 * Sorts the column in descending order
2037 sortDesc: function() {
2038 this.setColumnSort(Rico.ColumnConst.SORT_DESC);
2042 * Sorts the column in the specified direction
2043 * @param direction must be one of Rico.ColumnConst.UNSORTED, .SORT_ASC, or .SORT_DESC
2045 setColumnSort: function(direction) {
2046 this.liveGrid.clearSort();
2047 this.setSorted(direction);
2048 if (this.liveGrid.options.saveColumnInfo.sort)
2049 this.liveGrid.setCookie();
2050 if (this.options.sortHandler)
2051 this.options.sortHandler();
2055 * @returns true if this column is allowed to be sorted
2057 isSortable: function() {
2058 return this.sortable;
2062 * @returns true if this column is currently sorted
2064 isSorted: function() {
2065 return this.currentSort != Rico.ColumnConst.UNSORTED;
2069 * @returns Rico.ColumnConst.UNSORTED, .SORT_ASC, or .SORT_DESC
2071 getSortDirection: function() {
2072 return this.currentSort;
2076 * toggle the sort sequence for this column
2078 toggleSort: function() {
2079 if (this.buffer && this.buffer.totalRows==0) return;
2080 if (this.currentSort == Rico.ColumnConst.SORT_ASC)
2087 * Flags that this column is not sorted
2089 setUnsorted: function() {
2090 this.setSorted(Rico.ColumnConst.UNSORTED);
2094 * Flags that this column is sorted, but doesn't actually carry out the sort
2095 * @param direction must be one of Rico.ColumnConst.UNSORTED, .SORT_ASC, or .SORT_DESC
2097 setSorted: function(direction) {
2098 this.currentSort = direction;
2102 * @returns true if this column is allowed to be filtered
2104 canFilter: function() {
2105 return this.filterable;
2109 * @returns a textual representation of how this column is filtered
2111 getFilterText: function() {
2113 for (var i=0; i<this.filterValues.length; i++) {
2114 var v=this.filterValues[i];
2115 vals.push(v=='' ? Rico.getPhraseById('filterBlank') : v);
2117 switch (this.filterOp) {
2118 case 'EQ': return '= '+vals.join(', ');
2119 case 'NE': return Rico.getPhraseById('filterNot',vals.join(', '));
2120 case 'LE': return '<= '+vals[0];
2121 case 'GE': return '>= '+vals[0];
2122 case 'LIKE': return Rico.getPhraseById('filterLike',vals[0]);
2123 case 'NULL': return Rico.getPhraseById('filterEmpty');
2124 case 'NOTNULL': return Rico.getPhraseById('filterNotEmpty');
2130 * @returns returns the query string representation of the filter
2132 getFilterQueryParm: function() {
2133 if (this.filterType == Rico.ColumnConst.UNFILTERED) return '';
2134 var retval='&f['+this.index+'][op]='+this.filterOp;
2135 retval+='&f['+this.index+'][len]='+this.filterValues.length;
2136 for (var i=0; i<this.filterValues.length; i++) {
2137 retval+='&f['+this.index+']['+i+']='+escape(this.filterValues[i]);
2143 * removes the filter from this column
2145 setUnfiltered: function(skipHandler) {
2146 this.filterType = Rico.ColumnConst.UNFILTERED;
2147 if (this.liveGrid.options.saveColumnInfo.filter)
2148 this.liveGrid.setCookie();
2149 if (this.removeFilterFunc)
2150 this.removeFilterFunc();
2151 if (this.options.filterHandler && !skipHandler)
2152 this.options.filterHandler();
2155 setFilterEQ: function() {
2156 this.setUserFilter('EQ');
2158 setFilterNE: function() {
2159 this.setUserFilter('NE');
2161 addFilterNE: function() {
2162 this.filterValues.push(this.userFilter);
2163 if (this.liveGrid.options.saveColumnInfo.filter)
2164 this.liveGrid.setCookie();
2165 if (this.options.filterHandler)
2166 this.options.filterHandler();
2168 setFilterGE: function() { this.setUserFilter('GE'); },
2169 setFilterLE: function() { this.setUserFilter('LE'); },
2170 setFilterKW: function(keyword) {
2171 if (keyword!='' && keyword!=null) {
2172 this.setFilter('LIKE',keyword,Rico.ColumnConst.USERFILTER);
2174 this.setUnfiltered(false);
2178 setUserFilter: function(relop) {
2179 this.setFilter(relop,this.userFilter,Rico.ColumnConst.USERFILTER);
2182 setSystemFilter: function(relop,filter) {
2183 this.setFilter(relop,filter,Rico.ColumnConst.SYSTEMFILTER);
2186 setFilter: function(relop,filter,type,removeFilterFunc) {
2187 this.filterValues = typeof(filter)=='object' ? filter : [filter];
2188 this.filterType = type;
2189 this.filterOp = relop;
2190 if (type == Rico.ColumnConst.USERFILTER && this.liveGrid.options.saveColumnInfo.filter)
2191 this.liveGrid.setCookie();
2192 this.removeFilterFunc=removeFilterFunc;
2193 if (this.options.filterHandler)
2194 this.options.filterHandler();
2197 isFiltered: function() {
2198 return this.filterType == Rico.ColumnConst.USERFILTER;
2201 filterChange: function(e) {
\r
2202 var selbox=Rico.eventElement(e);
2203 if (selbox.value==this.liveGrid.options.FilterAllToken)
\r
2204 this.setUnfiltered();
\r
2206 this.setFilter('EQ',selbox.value,Rico.ColumnConst.USERFILTER,function() {selbox.selectedIndex=0;});
\r
2209 filterClear: function(e) {
\r
2210 this.filterField.value='';
2211 this.setUnfiltered();
\r
2214 filterKeypress: function(e) {
\r
2215 var txtbox=Rico.eventElement(e);
2216 if (typeof this.lastKeyFilter != 'string') this.lastKeyFilter='';
\r
2217 if (this.lastKeyFilter==txtbox.value) return;
\r
2218 var v=txtbox.value;
\r
2219 Rico.log("filterKeypress: "+this.index+' '+v);
\r
2220 this.lastKeyFilter=v;
2221 if (v=='' || v=='*')
\r
2222 this.setUnfiltered();
\r
2224 this.setFilter('LIKE', v, Rico.ColumnConst.USERFILTER, function() {txtbox.value='';});
2228 mFilterSelectClick: function(e) {
2230 if (this.mFilter.style.display!='none') {
2231 this.mFilterFinish(e);
2232 if (Rico.isIE && Rico.ieVersion <= 6) {
2233 this.filterField.focus();
2235 this.filterField.blur();
2238 var offset=Rico.cumulativeOffset(this.filterField);
2239 this.mFilter.style.top=(offset.top+this.filterField.offsetHeight)+'px';
2240 this.mFilter.style.left=offset.left+'px';
2241 this.mFilter.style.width=Math.min(this.filterField.offsetWidth,parseInt(this.colWidth,10))+'px';
2242 Rico.show(this.mFilter);
2243 this.mFilterFocus.focus();
2247 mFilterFinish: function(e) {
2248 if (!this.mFilterChange) {
2249 Rico.hide(this.mFilter);
2252 if (this.mFilterInputs[0].checked) {
2253 this.mFilterReset();
2254 Rico.hide(this.mFilter);
2255 this.setUnfiltered();
2260 for (var i=1; i<this.mFilterInputs.length; i++) {
2261 if (this.mFilterInputs[i].checked) {
2262 newValues.push(this.mFilterInputs[i].value)
2263 newLabels.push(this.mFilterLabels[i].innerHTML)
2266 if (newValues.length > 0) {
2267 var newText=newLabels.join(', ');
2268 this.filterField.options[0].text=newText;
2269 this.filterField.title=newText;
2270 Rico.hide(this.mFilter);
2271 this.mFilterChange=false;
2273 this.setFilter('EQ',newValues,Rico.ColumnConst.USERFILTER,function() { self.mFilterReset(); });
2275 alert('Please select at least one value');
2279 mFilterReset: function() {
2280 var newText=this.mFilterLabels[0].innerHTML; // all
2281 this.filterField.options[0].text=newText;
2282 this.filterField.title=newText;
2285 mFilterAllClick: function(e) {
2286 var allChecked=this.mFilterInputs[0].checked;
2287 for (var i=1; i<this.mFilterInputs.length; i++) {
2288 this.mFilterInputs[i].checked=allChecked;
2290 this.mFilterChange=true;
2293 mFilterOtherClick: function(e) {
2294 this.mFilterInputs[0].checked=false;
2295 this.mFilterChange=true;
2298 format_text: function(v) {
2299 if (typeof v!='string')
2302 return Rico.stripTags(v);
2305 format_showTags: function(v) {
2306 if (typeof v!='string')
2309 return v.replace(/&/g, '&').replace(/</g,'<').replace(/>/g,'>');
2312 format_number: function(v) {
2313 if (typeof v=='undefined' || v=='' || v==null)
2316 return Rico.formatNumber(v,this.format);
2319 format_datetime: function(v) {
2320 if (typeof v=='undefined' || v=='' || v==null)
2323 var d=Rico.setISO8601(v);
2325 return (this.format.prefix || '')+Rico.formatDate(d,this.format.dateFmt || 'translateDateTime')+(this.format.suffix || '');
2329 // converts GMT/UTC to local time
2330 format_UTCasLocalTime: function(v) {
2331 if (typeof v=='undefined' || v=='' || v==null)
2335 var d=Rico.setISO8601(v,-tz.getTimezoneOffset());
2337 return (this.format.prefix || '')+Rico.formatDate(d,this.format.dateFmt || 'translateDateTime')+(this.format.suffix || '');
2341 format_date: function(v) {
2342 if (typeof v=='undefined' || v==null || v=='')
2345 var d=Rico.setISO8601(v);
2347 return (this.format.prefix || '')+Rico.formatDate(d,this.format.dateFmt || 'translateDate')+(this.format.suffix || '');
2351 fixHeaders: function(prefix, iconsfirst) {
2352 if (this.sortable) {
2353 var handler=Rico.eventHandle(this,'toggleSort');
2354 switch (this.options.headingSort) {
2356 var a=Rico.wrapChildren(this.hdrCellDiv,'ricoSort',undefined,'a');
2357 a.href = "javascript:void(0)";
2358 Rico.eventBind(a,"click", handler);
2361 Rico.eventBind(this.hdrCellDiv,"click", handler);
2365 this.imgFilter = document.createElement('img');
2366 this.imgFilter.style.display='none';
2367 this.imgFilter.src=Rico.imgDir+this.options.filterImg;
2368 this.imgFilter.className='ricoLG_HdrIcon';
2369 this.imgSort = document.createElement('span');
2370 this.imgSort.style.display='none';
2372 this.hdrCellDiv.insertBefore(this.imgSort,this.hdrCellDiv.firstChild);
2373 this.hdrCellDiv.insertBefore(this.imgFilter,this.hdrCellDiv.firstChild);
2375 this.hdrCellDiv.appendChild(this.imgFilter);
2376 this.hdrCellDiv.appendChild(this.imgSort);
2378 if (!this.format.filterUI) {
2379 Rico.eventBind(this.imgFilter, 'click', Rico.eventHandle(this,'filterClick'), false);
2383 filterClick: function(e) {
2384 if (this.filterType==Rico.ColumnConst.USERFILTER && this.filterOp=='LIKE') {
2385 this.liveGrid.openKeyword(this.index);
2389 getValue: function(windowRow) {
2390 return this.buffer.getWindowCell(windowRow,this.index);
2393 getBufferAttr: function(windowRow) {
2394 return this.buffer.getWindowAttr(windowRow,this.index);
2397 setValue: function(windowRow,newval) {
2398 this.buffer.setWindowValue(windowRow,this.index,newval);
2401 _format: function(v) {
2405 _display: function(v,gridCell) {
2406 gridCell.innerHTML=this._format(v);
2409 _export: function(v) {
2410 return this._format(v);
2413 exportBuffer: function(bufRow) {
2414 return this._export(this.buffer.getValue(bufRow,this.index));
2417 displayValue: function(windowRow) {
2418 var bufval=this.getValue(windowRow);
2420 this.clearCell(windowRow);
2423 var gridCell=this.cell(windowRow);
2424 this._display(bufval,gridCell,windowRow);
2425 var acceptAttr=this.buffer.options.acceptAttr;
2426 if (acceptAttr.length==0) return;
2427 var bufAttr=this.getBufferAttr(windowRow);
2428 if (bufAttr==null) return;
2429 for (var k=0; k<acceptAttr.length; k++) {
2430 bufAttr=bufAttr['_'+acceptAttr[k]] || '';
2431 switch (acceptAttr[k]) {
2432 case 'style': gridCell.style.cssText=bufAttr; break;
2433 case 'class': gridCell.className=bufAttr; break;
2434 default: gridCell['_'+acceptAttr[k]]=bufAttr; break;