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() {
394 this.liveGrid.showMsg(Rico.getPhraseById('exportInProgress'));
395 Rico.runLater(10,this,'_printAll'); // allow message to paint
399 * Support function for printAll()
401 _printAll: function() {
402 this.liveGrid.exportStart();
403 this.exportBuffer(this.getRows(0,this.totalRows));
404 this.liveGrid.exportFinish();
408 * Copies visible rows to a new window as a simple html table.
410 printVisible: function() {
411 this.liveGrid.showMsg(Rico.getPhraseById('exportInProgress'));
412 Rico.runLater(10,this,'_printVisible'); // allow message to paint
415 _printVisible: function() {
416 this.liveGrid.exportStart();
417 this.exportBuffer(this.visibleRows());
418 this.liveGrid.exportFinish();
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
506 // sortCol: initial sort column
509 this.options.sortHandler = function() { self.sortHandler(); };
510 this.options.filterHandler = function() { self.filterHandler(); };
511 this.options.onRefreshComplete = function(firstrow,lastrow) { self.bookmarkHandler(firstrow,lastrow); };
512 this.options.rowOverHandler = Rico.eventHandle(this,'rowMouseOver');
513 this.options.mouseDownHandler = Rico.eventHandle(this,'selectMouseDown');
514 this.options.mouseOverHandler = Rico.eventHandle(this,'selectMouseOver');
515 this.options.mouseUpHandler = Rico.eventHandle(this,'selectMouseUp');
516 Rico.extend(this.options, options || {});
518 switch (typeof this.options.visibleRows) {
520 this.sizeTo=this.options.visibleRows;
521 switch (this.options.visibleRows) {
522 case 'data': this.options.visibleRows=-2; break;
523 case 'body': this.options.visibleRows=-3; break;
524 case 'parent': this.options.visibleRows=-4; break;
525 case 'datamax':this.options.visibleRows=-5; break;
526 default: this.options.visibleRows=-1; break;
530 switch (this.options.visibleRows) {
531 case -1: this.sizeTo='window'; break;
532 case -2: this.sizeTo='data'; break;
533 case -3: this.sizeTo='body'; break;
534 case -4: this.sizeTo='parent'; break;
535 case -5: this.sizeTo='datamax'; break;
536 default: this.sizeTo='fixed'; break;
541 this.options.visibleRows=-3;
544 this.highlightEnabled=this.options.highlightSection>0;
547 if (this.headerColCnt==0) {
548 alert('ERROR: no columns found in "'+this.tableId+'"');
551 this.createColumnArray('LiveGridColumn');
552 if (this.options.headingSort=='hover')
553 this.createHoverSet();
555 this.bookmark=document.getElementById(this.tableId+"_bookmark");
557 var filterUIrow=this.buffer.options.canFilter ? this.options.FilterLocation : false;
558 if (typeof(filterUIrow)=='number' && filterUIrow<0)
559 filterUIrow=this.addHeadingRow('ricoLG_FilterRow');
560 this.createDataCells(this.options.visibleRows);
561 if (this.pageSize == 0) return;
562 this.buffer.registerGrid(this);
563 if (this.buffer.setBufferSize) this.buffer.setBufferSize(this.pageSize);
564 this.scrollTimeout = null;
565 this.lastScrollPos = 0;
566 this.attachMenuEvents();
568 this.setSortUI( this.options.sortCol, this.options.sortDir );
570 if (this.listInvisible().length==this.columns.length)
571 this.columns[0].showColumn();
573 this.scrollDiv.style.display="";
574 if (this.buffer.totalRows>0)
575 this.updateHeightDiv();
576 if (this.options.prefetchBuffer) {
577 if (this.bookmark) this.bookmark.innerHTML = Rico.getPhraseById('bookmarkLoading');
578 if (this.options.canFilterDefault && this.options.getQueryParms)
579 this.checkForFilterParms();
580 this.scrollToRow(this.options.offset);
581 this.buffer.fetch(this.options.offset);
583 if (typeof(filterUIrow)=='number')
584 this.createFilters(filterUIrow);
585 this.scrollEventFunc=Rico.eventHandle(this,'handleScroll');
586 this.wheelEventFunc=Rico.eventHandle(this,'handleWheel');
587 this.wheelEvent=(Rico.isIE || Rico.isOpera || Rico.isWebKit) ? 'mousewheel' : 'DOMMouseScroll';
588 if (this.options.offset && this.options.offset < this.buffer.totalRows)
589 Rico.runLater(50,this,'scrollToRow',this.options.offset); // Safari requires a delay
591 this.setHorizontalScroll();
592 Rico.log("setHorizontalScroll done");
593 if (this.options.windowResize)
594 Rico.runLater(100,this,'pluginWindowResize');
595 Rico.log("initialize complete for "+this.tableId);
600 Rico.LiveGridMethods = {
601 /** @lends Rico.LiveGrid# */
603 createHoverSet: function() {
605 for( var c=0; c < this.headerColCnt; c++ ) {
606 if (this.columns[c].sortable) {
\r
607 hdrs.push(this.columns[c].hdrCellDiv);
610 this.hoverSet = new Rico.HoverSet(hdrs);
613 checkForFilterParms: function() {
614 var s=window.location.search;
615 if (s.charAt(0)=='?') s=s.substring(1);
616 var pairs = s.split('&');
617 for (var i=0; i<pairs.length; i++) {
618 if (pairs[i].match(/^f\[\d+\]/)) {
619 this.buffer.options.requestParameters.push(pairs[i]);
625 * Refreshes a detail grid from a master grid
626 * @returns row index on master table on success, -1 otherwise
628 drillDown: function(e,masterColNum,detailColNum) {
629 var cell=Rico.eventElement(e || window.event);
630 cell=Rico.getParentByTagName(cell,'div','ricoLG_cell');
631 if (!cell) return -1;
632 var idx=this.winCellIndex(cell);
633 if (idx.row >= this.buffer.totalRows) return -1
635 this.menuIdx=idx; // ensures selection gets cleared when menu is displayed
637 var drillValue=this.buffer.getWindowCell(idx.row,masterColNum);
638 for (var i=3; i<arguments.length; i++)
639 arguments[i].setDetailFilter(detailColNum,drillValue);
644 * set filter on a detail grid that is in a master-detail relationship
646 setDetailFilter: function(colNumber,filterValue) {
647 var c=this.columns[colNumber];
648 c.format.ColData=filterValue;
649 c.setSystemFilter('EQ',filterValue);
653 * Create one table for frozen columns and one for scrolling columns.
654 * Also create div's to contain them.
655 * @returns true on success
657 createTables: function() {
658 var insertloc,hdrSrc,i;
659 var table = document.getElementById(this.tableId) || document.getElementById(this.tableId+'_outerDiv');
660 if (!table) return false;
661 if (table.tagName.toLowerCase()=='table') {
662 var theads=table.getElementsByTagName("thead");
663 if (theads.length == 1) {
664 Rico.log("createTables: using thead section, id="+this.tableId);
665 if (this.options.PanelNamesOnTabHdr && this.options.panels) {
666 var r=theads[0].insertRow(0);
667 this.insertPanelNames(r, 0, this.options.frozenColumns, 'ricoFrozen');
668 this.insertPanelNames(r, this.options.frozenColumns, this.options.columnSpecs.length);
670 hdrSrc=theads[0].rows;
672 Rico.log("createTables: using tbody section, id="+this.tableId);
673 hdrSrc=new Array(table.rows[0]);
676 } else if (this.options.columnSpecs.length > 0) {
677 if (!table.id.match(/_outerDiv$/)) insertloc=table;
678 Rico.log("createTables: inserting at "+table.tagName+", id="+this.tableId);
680 alert("ERROR!\n\nUnable to initialize '"+this.tableId+"'\n\nLiveGrid terminated");
685 this.scrollContainer = this.createDiv("scrollContainer",this.structTabLR);
686 this.scrollContainer.appendChild(this.scrollDiv); // move scrollDiv
687 this.scrollTab = this.createDiv("scrollTab",this.scrollContainer);
688 this.shadowDiv = this.createDiv("shadow",this.scrollDiv);
689 this.shadowDiv.style.direction='ltr'; // avoid FF bug
690 this.scrollDiv.style.display="none";
691 this.scrollDiv.scrollTop=0;
692 if (this.options.highlightMethod!='class') {
693 this.highlightDiv=[];
694 switch (this.options.highlightElem) {
697 this.highlightDiv[0] = this.createDiv("highlight",this.outerDiv);
698 this.highlightDiv[0].style.display="none";
702 for (i=0; i<2; i++) {
703 this.highlightDiv[i] = this.createDiv("highlight",i==0 ? this.frozenTabs : this.scrollTab);
704 this.highlightDiv[i].style.display="none";
705 this.highlightDiv[i].id+=i;
709 // create one div for each side of the rectangle
710 var parentDiv=this.options.highlightSection==1 ? this.frozenTabs : this.scrollTab;
711 for (i=0; i<4; i++) {
712 this.highlightDiv[i] = this.createDiv("highlight",parentDiv);
713 this.highlightDiv[i].style.display="none";
714 this.highlightDiv[i].style.overflow="hidden";
715 this.highlightDiv[i].id+=i;
716 this.highlightDiv[i].style[i % 2==0 ? 'height' : 'width']="0px";
723 for (i=0; i<3; i++) {
724 this.tabs[i] = document.createElement("table");
725 this.tabs[i].className = 'ricoLG_table';
726 this.tabs[i].border=0;
727 this.tabs[i].cellPadding=0;
728 this.tabs[i].cellSpacing=0;
729 this.tabs[i].id = this.tableId+"_tab"+i;
732 for (i=0; i<2; i++) {
733 this.thead[i]=this.tabs[i].createTHead();
734 Rico.addClass(this.tabs[i],'ricoLG_top');
735 //this.thead[i].className='ricoLG_top';
736 if (Rico.theme.gridheader) Rico.addClass(this.thead[i],Rico.theme.gridheader);
739 for (i=0; i<2; i++) {
740 this.tbody[i]=Rico.getTBody(this.tabs[i==0?0:2]);
741 this.tbody[i].className='ricoLG_bottom';
742 if (Rico.theme.gridcontent) Rico.addClass(this.tbody[i],Rico.theme.gridcontent);
743 this.tbody[i].insertRow(-1);
745 this.frozenTabs.appendChild(this.tabs[0]);
746 this.innerDiv.appendChild(this.tabs[1]);
747 this.scrollTab.appendChild(this.tabs[2]);
748 if (insertloc) insertloc.parentNode.insertBefore(this.outerDiv,insertloc);
750 this.headerColCnt = this.getColumnInfo(hdrSrc);
751 this.loadHdrSrc(hdrSrc);
753 this.createHdr(0,0,this.options.frozenColumns);
754 this.createHdr(1,this.options.frozenColumns,this.options.columnSpecs.length);
755 if (this.options.PanelNamesOnTabHdr && this.options.panels) {
756 this.insertPanelNames(this.thead[0].insertRow(0), 0, this.options.frozenColumns);
757 this.insertPanelNames(this.thead[1].insertRow(0), this.options.frozenColumns, this.options.columnSpecs.length);
760 this.headerColCnt = this.getColumnInfo(this.thead[i].rows);
762 for( var c=0; c < this.headerColCnt; c++ )
763 this.tbody[c<this.options.frozenColumns ? 0 : 1].rows[0].insertCell(-1);
764 if (insertloc) table.parentNode.removeChild(table);
765 Rico.log('createTables end');
769 createDataCells: function(visibleRows) {
770 if (visibleRows < 0) {
771 for (var i=0; i<this.options.minPageRows; i++)
772 this.appendBlankRow();
774 this.autoAppendRows(this.remainingHt());
776 for( var r=0; r < visibleRows; r++ )
777 this.appendBlankRow();
779 var s=this.options.highlightSection;
780 if (s & 1) this.attachHighlightEvents(this.tbody[0]);
781 if (s & 2) this.attachHighlightEvents(this.tbody[1]);
785 * @param colnum column number
786 * @return id string for a filter element
788 filterId: function(colnum) {
789 return 'RicoFilter_'+this.tableId+'_'+colnum;
793 * Create filter elements in heading
794 * Reads this.columns[].filterUI to determine type of filter element for each column (t=text box, s=select list, c=custom)
795 * @param r heading row where filter elements will be placed
797 createFilters: function(r) {
798 for( var c=0; c < this.headerColCnt; c++ ) {
799 var col=this.columns[c];
801 if (typeof fmt.filterUI!='string') continue;
802 var cell=this.hdrCells[r][c].cell;
803 var field,name=this.filterId(c);
\r
804 var divs=cell.getElementsByTagName('div');
805 // copy text alignment from data cell
806 var align=Rico.getStyle(this.cell(0,c),'textAlign');
807 divs[1].style.textAlign=align;
808 switch (fmt.filterUI.charAt(0)) {
811 field=Rico.createFormField(divs[1],'input','text',name,name);
812 var size=fmt.filterUI.match(/\d+/);
813 field.maxLength=fmt.Length || 50;
\r
814 field.size=size ? parseInt(size,10) : 10;
815 divs[1].appendChild(Rico.clearButton(Rico.eventHandle(col,'filterClear')));
816 if (col.filterType==Rico.ColumnConst.USERFILTER && col.filterOp=='LIKE') {
817 var v=col.filterValues[0];
818 if (v.charAt(0)=='*') v=v.substr(1);
819 if (v.slice(-1)=='*') v=v.slice(0,-1);
823 Rico.eventBind(field,'keyup',Rico.eventHandle(col,'filterKeypress'),false);
824 col.filterField=field;
\r
830 field=Rico.createFormField(divs[1],'select',null,name);
\r
831 Rico.addSelectOption(field,this.options.FilterAllToken,Rico.getPhraseById("filterAll"));
\r
832 col.filterField=field;
834 Rico.extend(options, this.buffer.ajaxOptions);
835 var colnum=typeof(fmt.filterCol)=='number' ? fmt.filterCol : c;
836 options.parameters = {id: this.tableId, distinct:colnum};
837 options.parameters[this.actionId]="query";
838 options.onComplete = this.filterValuesUpdateFunc(c);
839 new Rico.ajaxRequest(this.buffer.dataSource, options);
843 if (typeof col._createFilters == 'function')
844 col._createFilters(divs[1], name);
848 this.initFilterImage(r);
851 filterValuesUpdateFunc: function(colnum) {
853 return function (request) { self.filterValuesUpdate(colnum,request); };
857 * update select list filter with values in AJAX response
858 * @returns true on success
860 filterValuesUpdate: function(colnum,request) {
861 var response = request.responseXML.getElementsByTagName("ajax-response");
862 Rico.log("filterValuesUpdate: "+request.status);
863 if (response == null || response.length != 1) return false;
864 response=response[0];
865 var error = response.getElementsByTagName('error');
866 if (error.length > 0) {
867 Rico.log("Data provider returned an error:\n"+Rico.getContentAsString(error[0],this.buffer.isEncoded));
868 alert(Rico.getPhraseById("requestError",Rico.getContentAsString(error[0],this.buffer.isEncoded)));
871 response=response.getElementsByTagName('response')[0];
\r
872 var rowsElement = response.getElementsByTagName('rows')[0];
\r
873 var col=this.columns[parseInt(colnum,10)];
874 var rows = this.buffer.dom2jstable(rowsElement);
\r
876 if (col.filterType==Rico.ColumnConst.USERFILTER && col.filterOp=='EQ') v=col.filterValues[0];
877 Rico.log('filterValuesUpdate: col='+colnum+' rows='+rows.length);
878 switch (col.format.filterUI.charAt(0)) {
881 col.mFilter = document.body.appendChild(document.createElement("div"));
882 col.mFilter.className = 'ricoLG_mFilter'
883 Rico.hide(col.mFilter);
884 var contentDiv = col.mFilter.appendChild(document.createElement("div"));
885 contentDiv.className = 'ricoLG_mFilter_content'
886 var buttonDiv = col.mFilter.appendChild(document.createElement("div"));
887 buttonDiv.className = 'ricoLG_mFilter_button'
888 col.mFilterButton=buttonDiv.appendChild(document.createElement("button"));
889 col.mFilterButton.innerHTML=Rico.getPhraseById("ok");
890 var eventName=Rico.isWebKit ? 'mousedown' : 'click';
891 Rico.eventBind(col.filterField,eventName,Rico.eventHandle(col,'mFilterSelectClick'));
892 Rico.eventBind(col.mFilterButton,'click',Rico.eventHandle(col,'mFilterFinish'));
893 //col.filterField.options[0].text=$('AllLabel').innerHTML;
894 tab = contentDiv.appendChild(document.createElement("table"));
898 //tbody=(tab.tBodies.length==0) ? tab.appendChild(document.createElement("tbody")) : tab.tBodies[0];
899 var baseId=this.filterId(colnum)+'_';
900 this.createMFilterItem(tab,this.options.FilterAllToken,Rico.getPhraseById("filterAll"),baseId+'all',Rico.eventHandle(col,'mFilterAllClick'));
901 var handle=Rico.eventHandle(col,'mFilterOtherClick')
902 for (var i=0; i<rows.length; i++) {
903 if (rows[i].length>0) {
905 this.createMFilterItem(tab,c,c || Rico.getPhraseById("filterBlank"),baseId+i,handle);
908 col.mFilterInputs=contentDiv.getElementsByTagName('input');
909 col.mFilterLabels=contentDiv.getElementsByTagName('label');
910 col.mFilterFocus=col.mFilterInputs.length ? col.mFilterInputs[0] : col.mFilterButton;
915 for (var i=0; i<rows.length; i++) {
916 if (rows[i].length>0) {
918 opt=Rico.addSelectOption(col.filterField,c,c || Rico.getPhraseById("filterBlank"));
919 if (col.filterType==Rico.ColumnConst.USERFILTER && c==v) opt.selected=true;
922 Rico.eventBind(col.filterField,'change',Rico.eventHandle(col,'filterChange'));
928 createMFilterItem: function(table,code,description,id,eventHandle) {
929 var tr=table.insertRow(-1);
931 if (tr.rowIndex % 2 == 1) tr.className='ricoLG_mFilter_oddrow';
932 var td1=tr.insertCell(-1)
933 var td2=tr.insertCell(-1)
934 var field=Rico.createFormField(td1,'input','checkbox',id);
937 var label = td2.appendChild(document.createElement("label"));
939 label.innerHTML=description;
940 Rico.eventBind(field,'click',eventHandle);
943 unplugHighlightEvents: function() {
944 var s=this.options.highlightSection;
945 if (s & 1) this.detachHighlightEvents(this.tbody[0]);
946 if (s & 2) this.detachHighlightEvents(this.tbody[1]);
950 * place panel names on first row of grid header (used by LiveGridForms)
952 insertPanelNames: function(r,start,limit,cellClass) {
953 Rico.log('insertPanelNames: start='+start+' limit='+limit);
954 r.className='ricoLG_hdg';
955 var lastIdx=-1, span, newCell=null, spanIdx=0;
956 for( var c=start; c < limit; c++ ) {
957 if (lastIdx == this.options.columnSpecs[c].panelIdx) {
960 if (newCell) newCell.colSpan=span;
961 newCell = r.insertCell(-1);
962 if (cellClass) newCell.className=cellClass;
964 lastIdx=this.options.columnSpecs[c].panelIdx;
965 newCell.innerHTML=this.options.panels[lastIdx];
968 if (newCell) newCell.colSpan=span;
972 * create grid header for table i (if none was provided)
974 createHdr: function(i,start,limit) {
975 Rico.log('createHdr: i='+i+' start='+start+' limit='+limit);
976 var mainRow = this.thead[i].insertRow(-1);
977 mainRow.id=this.tableId+'_tab'+i+'h_main';
978 mainRow.className='ricoLG_hdg';
979 for( var c=start; c < limit; c++ ) {
980 var newCell = mainRow.insertCell(-1);
981 newCell.innerHTML=this.options.columnSpecs[c].Hdg;
986 * move header cells in original table to grid
988 loadHdrSrc: function(hdrSrc) {
989 var i,h,c,r,newrow,cells;
990 Rico.log('loadHdrSrc start');
991 for (i=0; i<2; i++) {
992 for (r=0; r<hdrSrc.length; r++) {
993 newrow = this.thead[i].insertRow(-1);
994 newrow.className='ricoLG_hdg '+this.tableId+'_hdg'+r;
997 if (hdrSrc.length==1) {
998 cells=hdrSrc[0].cells;
999 for (c=0; cells.length > 0; c++)
1000 this.thead[c<this.options.frozenColumns ? 0 : 1].rows[0].appendChild(cells[0]);
1002 for (r=0; r<hdrSrc.length; r++) {
1003 cells=hdrSrc[r].cells;
1004 for (c=0,h=0; cells.length > 0; c++) {
1005 if (cells[0].className=='ricoFrozen') {
1006 if (r==this.headerRowIdx) this.options.frozenColumns=c+1;
1010 this.thead[h].rows[r].appendChild(cells[0]);
1014 Rico.log('loadHdrSrc end');
1020 sizeDivs: function() {
1021 Rico.log('sizeDivs: '+this.tableId);
1022 //this.cancelMenu();
1024 this.baseSizeDivs();
1025 var firstVisible=this.firstVisible();
1026 if (this.pageSize == 0 || firstVisible < 0) return;
1027 var totRowHt=this.columns[firstVisible].dataColDiv.offsetHeight;
1028 this.rowHeight = Math.round(totRowHt/this.pageSize);
1029 var scrHt=this.dataHt;
1030 if (this.scrTabWi0 == this.scrTabWi) {
1031 // no scrolling columns - horizontal scroll bar not needed
1032 this.innerDiv.style.height=(this.hdrHt+1)+'px';
1033 this.scrollDiv.style.overflowX='hidden';
1035 this.scrollDiv.style.overflowX='scroll';
1036 scrHt+=this.options.scrollBarWidth;
1038 this.scrollDiv.style.height=scrHt+'px';
1039 this.innerDiv.style.width=(this.scrWi)+'px';
1040 this.scrollTab.style.width=(this.scrWi-this.options.scrollBarWidth)+'px';
1041 //this.resizeDiv.style.height=this.frozenTabs.style.height=this.innerDiv.style.height=(this.hdrHt+this.dataHt+1)+'px';
1042 this.resizeDiv.style.height=(this.hdrHt+this.dataHt+1)+'px';
1043 Rico.log('sizeDivs scrHt='+scrHt+' innerHt='+this.innerDiv.style.height+' rowHt='+this.rowHeight+' pageSize='+this.pageSize);
1044 var pad=(this.scrWi-this.scrTabWi < this.options.scrollBarWidth) ? 2 : 0;
1045 this.shadowDiv.style.width=(this.scrTabWi+pad)+'px';
1046 this.outerDiv.style.height=(this.hdrHt+scrHt)+'px';
1047 this.setHorizontalScroll();
1050 setHorizontalScroll: function() {
1051 var newLeft=(-this.scrollDiv.scrollLeft)+'px';
1052 this.tabs[1].style.marginLeft=newLeft;
1053 this.tabs[2].style.marginLeft=newLeft;
1056 remainingHt: function() {
1057 var tabHt=this.outerDiv.offsetHeight;
1058 var winHt=Rico.windowHeight();
1059 var margin=Rico.isIE ? 15 : 10;
1060 // if there is a horizontal scrollbar take it into account
1061 if (!Rico.isIE && window.frameElement && window.frameElement.scrolling=='yes' && this.sizeTo!='parent') margin+=this.options.scrollBarWidth;
1062 switch (this.sizeTo) {
1064 var divTop=Rico.cumulativeOffset(this.outerDiv).top;
1065 Rico.log("remainingHt/window, winHt="+winHt+' tabHt='+tabHt+' gridY='+divTop);
1066 return winHt-divTop-tabHt-margin; // allow for scrollbar and some margin
1068 var offset=this.offsetFromParent(this.outerDiv);
1069 if (Rico.isIE) Rico.hide(this.outerDiv);
1070 var parentHt=this.outerDiv.parentNode.clientHeight;
1071 if (Rico.isIE) Rico.show(this.outerDiv);
1072 Rico.log("remainingHt/parent, parentHt="+parentHt+' offset='+offset+' tabHt='+tabHt);
1073 return parentHt-tabHt-offset-margin;
1076 var bodyHt=Rico.isIE ? document.body.scrollHeight : document.body.offsetHeight;
1077 //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);
1078 var remHt=winHt-bodyHt-margin;
1079 if (!Rico.isWebKit) remHt-=this.options.scrollBarWidth;
1080 Rico.log("remainingHt, winHt="+winHt+' pageHt='+bodyHt+' remHt='+remHt);
1083 Rico.log("remainingHt, winHt="+winHt+' tabHt='+tabHt);
1084 if (this.sizeTo.slice(-1)=='%') winHt*=parseFloat(this.sizeTo)/100.0;
1085 else if (this.sizeTo.slice(-2)=='px') winHt=parseInt(this.sizeTo,10);
1086 return winHt-tabHt-margin; // allow for scrollbar and some margin
1090 offsetFromParent: function(element) {
1092 var elParent=element.parentNode;
1094 //Rico.log("offsetFromParent: "+element.tagName+' id='+element.id+' otop='+element.offsetTop);
1095 valueT += element.offsetTop || 0;
1096 element = element.offsetParent;
1097 if (!element || element==null) break;
1098 var p = Rico.getStyle(element, 'position');
1099 if (element.tagName=='BODY' || element.tagName=='HTML' || p=='absolute') return valueT-elParent.offsetTop;
1100 } while (element != elParent);
1104 adjustPageSize: function() {
1105 var remHt=this.remainingHt();
1106 Rico.log('adjustPageSize remHt='+remHt+' lastRow='+this.lastRowPos);
1107 if (remHt > this.rowHeight)
1108 this.autoAppendRows(remHt);
1109 else if (remHt < 0 || this.sizeTo=='data')
1110 this.autoRemoveRows(-remHt);
1113 setPageSize: function(newRowCount) {
1114 newRowCount=Math.min(newRowCount,this.options.maxPageRows);
1115 newRowCount=Math.max(newRowCount,this.options.minPageRows);
1116 this.sizeTo='fixed';
1117 var oldSize=this.pageSize;
1118 while (this.pageSize > newRowCount) {
1121 while (this.pageSize < newRowCount) {
1122 this.appendBlankRow();
1124 this.finishResize(oldSize);
1127 pluginWindowResize: function() {
1128 Rico.log("pluginWindowResize");
1129 this.resizeWindowHandler=Rico.eventHandle(this,'resizeWindow');
1130 Rico.eventBind(window, "resize", this.resizeWindowHandler, false);
1133 unplugWindowResize: function() {
1134 if (!this.resizeWindowHandler) return;
1135 Rico.eventUnbind(window,"resize", this.resizeWindowHandler, false);
1136 this.resizeWindowHandler=null;
1139 resizeWindow: function() {
1140 Rico.log('resizeWindow '+this.tableId+' lastRow='+this.lastRowPos);
1141 if (this.resizeState=='finish') {
1142 Rico.log('resizeWindow postponed');
1143 this.resizeState='resize';
1146 if (!this.sizeTo || this.sizeTo=='fixed') {
1150 if (this.sizeTo=='parent' && Rico.getStyle(this.outerDiv.parentNode,'display') == 'none') return;
1151 var oldSize=this.pageSize;
1152 this.adjustPageSize();
1153 this.finishResize(oldSize);
1156 finishResize: function(oldSize) {
1157 if (this.pageSize > oldSize && this.buffer.totalRows>0) {
1158 this.isPartialBlank=true;
1159 var adjStart=this.adjustRow(this.lastRowPos);
1160 this.buffer.fetch(adjStart);
1161 } else if (this.pageSize < oldSize) {
1162 if (this.options.onRefreshComplete) this.options.onRefreshComplete(this.contentStartPos,this.contentStartPos+this.pageSize-1); // update bookmark
1164 this.resizeState='finish';
1165 Rico.runLater(20,this,'finishResize2');
1166 Rico.log('Resize '+this.tableId+' complete. old size='+oldSize+' new size='+this.pageSize);
1169 finishResize2: function() {
1171 this.updateHeightDiv();
1172 if (this.resizeState=='resize') {
1173 this.resizeWindow();
1175 this.resizeState='';
1179 topOfLastPage: function() {
1180 return Math.max(this.buffer.totalRows-this.pageSize,0);
1183 updateHeightDiv: function() {
1184 var notdisp=this.topOfLastPage();
1185 var ht = notdisp ? this.scrollDiv.clientHeight + Math.floor(this.rowHeight * (notdisp + 0.4)) : 1;
1186 Rico.log("updateHeightDiv, ht="+ht+' scrollDiv.clientHeight='+this.scrollDiv.clientHeight+' rowsNotDisplayed='+notdisp);
1187 this.shadowDiv.style.height=ht+'px';
1190 autoRemoveRows: function(overage) {
1191 if (!this.rowHeight) return;
1192 var removeCnt=Math.ceil(overage / this.rowHeight);
1193 if (this.sizeTo=='data')
1194 removeCnt=Math.max(removeCnt,this.pageSize-this.buffer.totalRows);
1195 Rico.log("autoRemoveRows overage="+overage+" removeCnt="+removeCnt);
1196 for (var i=0; i<removeCnt; i++)
1200 removeRow: function() {
1201 if (this.pageSize <= this.options.minPageRows) return;
1203 for( var c=0; c < this.headerColCnt; c++ ) {
1204 var cell=this.columns[c].cell(this.pageSize);
1205 this.columns[c].dataColDiv.removeChild(cell);
1209 autoAppendRows: function(overage) {
1210 if (!this.rowHeight) return;
1211 var addCnt=Math.floor(overage / this.rowHeight);
1212 Rico.log("autoAppendRows overage="+overage+" cnt="+addCnt+" rowHt="+this.rowHeight);
1213 for (var i=0; i<addCnt; i++) {
1214 if (this.sizeTo=='data' && this.pageSize>=this.buffer.totalRows) break;
1215 this.appendBlankRow();
1220 * on older systems, this can be fairly slow
1222 appendBlankRow: function() {
1223 if (this.pageSize >= this.options.maxPageRows) return;
1224 Rico.log("appendBlankRow #"+this.pageSize);
1225 var cls=this.defaultRowClass(this.pageSize);
1226 for( var c=0; c < this.headerColCnt; c++ ) {
1227 var newdiv = document.createElement("div");
1228 newdiv.className = 'ricoLG_cell '+cls;
1229 newdiv.id=this.tableId+'_'+this.pageSize+'_'+c;
1230 this.columns[c].dataColDiv.appendChild(newdiv);
1231 if (this.columns[c].format.canDrag && Rico.registerDraggable)
1232 Rico.registerDraggable( new Rico.LiveGridDraggable(this, this.pageSize, c), this.options.dndMgrIdx );
1233 newdiv.innerHTML=' '; // this seems to be required by IE
1234 if (this.columns[c]._create) {
1235 this.columns[c]._create(newdiv,this.pageSize);
1241 defaultRowClass: function(rownum) {
1243 if (rownum % 2==0) {
1244 cls='ricoLG_evenRow';
1245 //if (Rico.theme.primary) cls+=' '+Rico.theme.primary;
1247 cls='ricoLG_oddRow';
1248 //if (Rico.theme.secondary) cls+=' '+Rico.theme.secondary;
1253 handleMenuClick: function(e) {
1254 if (!this.menu) return;
1256 this.unhighlight(); // in case highlighting was invoked externally
1258 var cell=Rico.eventElement(e);
1259 if (cell.className=='ricoLG_highlightDiv') {
1260 idx=this.highlightIdx;
1262 cell=Rico.getParentByTagName(cell,'div','ricoLG_cell');
1264 idx=this.winCellIndex(cell);
1265 if ((this.options.highlightSection & (idx.tabIdx+1))==0) return;
1267 this.highlight(idx);
1268 this.highlightEnabled=false;
1269 if (this.hideScroll) this.scrollDiv.style.overflow="hidden";
1271 if (!this.menu.div) this.menu.createDiv();
1272 this.menu.liveGrid=this;
1273 if (this.menu.buildGridMenu) {
1274 var showMenu=this.menu.buildGridMenu(idx.row, idx.column, idx.tabIdx);
1275 if (!showMenu) return;
1277 if (this.options.highlightElem=='selection' && !this.isSelected(idx.cell)) {
1278 this.selectCell(idx.cell);
1281 this.menu.showmenu(e,function() { self.closeMenu(); });
1285 closeMenu: function() {
1286 if (!this.menuIdx) return;
1287 if (this.hideScroll) this.scrollDiv.style.overflow="";
1288 //this.unhighlight();
1289 this.highlightEnabled=true;
1294 * @return index of cell within the window
1296 winCellIndex: function(cell) {
1297 var l=cell.id.lastIndexOf('_',cell.id.length);
1298 var l2=cell.id.lastIndexOf('_',l-1)+1;
1299 var c=parseInt(cell.id.substr(l+1));
1300 var r=parseInt(cell.id.substr(l2,l));
1301 return {row:r, column:c, tabIdx:this.columns[c].tabIdx, cell:cell};
1305 * @return index of cell within the dataset
1307 datasetIndex: function(cell) {
1308 var idx=this.winCellIndex(cell);
1309 idx.row+=this.buffer.windowPos;
1310 idx.onBlankRow=(idx.row >= this.buffer.endPos());
1314 attachHighlightEvents: function(tBody) {
1315 switch (this.options.highlightElem) {
1317 Rico.eventBind(tBody,"mousedown", this.options.mouseDownHandler, false);
1319 tBody.ondrag = function () { return false; };
1321 tBody.onselectstart = function () { return false; };
1325 Rico.eventBind(tBody,"mouseover", this.options.rowOverHandler, false);
1330 detachHighlightEvents: function(tBody) {
1331 switch (this.options.highlightElem) {
1333 Rico.eventUnbind(tBody,"mousedown", this.options.mouseDownHandler, false);
1334 tBody.ondrag = null;
1335 tBody.onselectstart = null;
1339 Rico.eventUnbind(tBody,"mouseover", this.options.rowOverHandler, false);
1345 * @return array of objects containing row/col indexes (index values are relative to the start of the window)
1347 getVisibleSelection: function() {
1349 if (this.SelectIdxStart && this.SelectIdxEnd) {
1350 var r1=Math.max(Math.min(this.SelectIdxEnd.row,this.SelectIdxStart.row)-this.buffer.startPos,this.buffer.windowStart);
1351 var r2=Math.min(Math.max(this.SelectIdxEnd.row,this.SelectIdxStart.row)-this.buffer.startPos,this.buffer.windowEnd-1);
1352 var c1=Math.min(this.SelectIdxEnd.column,this.SelectIdxStart.column);
1353 var c2=Math.max(this.SelectIdxEnd.column,this.SelectIdxStart.column);
1354 //Rico.log("getVisibleSelection "+r1+','+c1+' to '+r2+','+c2+' ('+this.SelectIdxStart.row+',startPos='+this.buffer.startPos+',windowPos='+this.buffer.windowPos+',windowEnd='+this.buffer.windowEnd+')');
1355 for (var r=r1; r<=r2; r++) {
1356 for (var c=c1; c<=c2; c++)
1357 cellList.push({row:r-this.buffer.windowStart,column:c});
1360 if (this.SelectCtrl) {
1361 for (var i=0; i<this.SelectCtrl.length; i++) {
1362 if (this.SelectCtrl[i].row>=this.buffer.windowStart && this.SelectCtrl[i].row<this.buffer.windowEnd)
1363 cellList.push({row:this.SelectCtrl[i].row-this.buffer.windowStart,column:this.SelectCtrl[i].column});
1369 updateSelectOutline: function() {
1370 if (!this.SelectIdxStart || !this.SelectIdxEnd) return;
1371 var r1=Math.max(Math.min(this.SelectIdxEnd.row,this.SelectIdxStart.row), this.buffer.windowStart);
1372 var r2=Math.min(Math.max(this.SelectIdxEnd.row,this.SelectIdxStart.row), this.buffer.windowEnd-1);
1374 this.HideSelection();
1377 var c1=Math.min(this.SelectIdxEnd.column,this.SelectIdxStart.column);
1378 var c2=Math.max(this.SelectIdxEnd.column,this.SelectIdxStart.column);
1379 var top1=this.columns[c1].cell(r1-this.buffer.windowStart).offsetTop;
1380 var cell2=this.columns[c1].cell(r2-this.buffer.windowStart);
1381 var bottom2=cell2.offsetTop+cell2.offsetHeight;
1382 var left1=this.columns[c1].dataCell.offsetLeft;
1383 var left2=this.columns[c2].dataCell.offsetLeft;
1384 var right2=left2+this.columns[c2].dataCell.offsetWidth;
1385 //window.status='updateSelectOutline: '+r1+' '+r2+' top='+top1+' bot='+bottom2;
1386 this.highlightDiv[0].style.top=this.highlightDiv[3].style.top=this.highlightDiv[1].style.top=(this.hdrHt+top1-1) + 'px';
1387 this.highlightDiv[2].style.top=(this.hdrHt+bottom2-1)+'px';
1388 this.highlightDiv[3].style.left=(left1-2)+'px';
1389 this.highlightDiv[0].style.left=this.highlightDiv[2].style.left=(left1-1)+'px';
1390 this.highlightDiv[1].style.left=(right2-1)+'px';
1391 this.highlightDiv[0].style.width=this.highlightDiv[2].style.width=(right2-left1-1) + 'px';
1392 this.highlightDiv[1].style.height=this.highlightDiv[3].style.height=(bottom2-top1) + 'px';
1393 //this.highlightDiv[0].style.right=this.highlightDiv[2].style.right=this.highlightDiv[1].style.right=()+'px';
1394 //this.highlightDiv[2].style.bottom=this.highlightDiv[3].style.bottom=this.highlightDiv[1].style.bottom=(this.hdrHt+bottom2) + 'px';
1395 for (var i=0; i<4; i++)
1396 this.highlightDiv[i].style.display='';
1399 HideSelection: function() {
1401 if (this.options.highlightMethod!='class') {
1402 for (i=0; i<this.highlightDiv.length; i++)
1403 this.highlightDiv[i].style.display='none';
1405 if (this.options.highlightMethod!='outline') {
1406 var cellList=this.getVisibleSelection();
1407 Rico.log("HideSelection "+cellList.length);
1408 for (i=0; i<cellList.length; i++)
1409 this.unhighlightCell(this.columns[cellList[i].column].cell(cellList[i].row));
1413 ShowSelection: function() {
1414 if (this.options.highlightMethod!='class')
1415 this.updateSelectOutline();
1416 if (this.options.highlightMethod!='outline') {
1417 var cellList=this.getVisibleSelection();
1418 for (var i=0; i<cellList.length; i++)
1419 this.highlightCell(this.columns[cellList[i].column].cell(cellList[i].row));
1423 ClearSelection: function() {
1424 Rico.log("ClearSelection");
1425 this.HideSelection();
1426 this.SelectIdxStart=null;
1427 this.SelectIdxEnd=null;
1431 selectCell: function(cell) {
1432 this.ClearSelection();
1433 this.SelectIdxStart=this.SelectIdxEnd=this.datasetIndex(cell);
1434 this.ShowSelection();
1437 AdjustSelection: function(cell) {
1438 var newIdx=this.datasetIndex(cell);
1439 if (this.SelectIdxStart.tabIdx != newIdx.tabIdx) return;
1440 this.HideSelection();
1441 this.SelectIdxEnd=newIdx;
1442 this.ShowSelection();
1445 RefreshSelection: function() {
1446 var cellList=this.getVisibleSelection();
1447 for (var i=0; i<cellList.length; i++) {
1448 this.columns[cellList[i].column].displayValue(cellList[i].row);
1452 FillSelection: function(newVal,newStyle) {
1453 if (this.SelectIdxStart && this.SelectIdxEnd) {
1454 var r1=Math.min(this.SelectIdxEnd.row,this.SelectIdxStart.row);
1455 var r2=Math.max(this.SelectIdxEnd.row,this.SelectIdxStart.row);
1456 var c1=Math.min(this.SelectIdxEnd.column,this.SelectIdxStart.column);
1457 var c2=Math.max(this.SelectIdxEnd.column,this.SelectIdxStart.column);
1458 for (var r=r1; r<=r2; r++) {
1459 for (var c=c1; c<=c2; c++) {
1460 this.buffer.setValue(r,c,newVal,newStyle);
1464 if (this.SelectCtrl) {
1465 for (var i=0; i<this.SelectCtrl.length; i++) {
1466 this.buffer.setValue(this.SelectCtrl[i].row,this.SelectCtrl[i].column,newVal,newStyle);
1469 this.RefreshSelection();
1473 * Process mouse down event
1474 * @param e event object
1476 selectMouseDown: function(e) {
1477 if (this.highlightEnabled==false) return true;
1479 var cell=Rico.eventElement(e);
1480 if (!Rico.eventLeftClick(e)) return true;
1481 cell=Rico.getParentByTagName(cell,'div','ricoLG_cell');
1482 if (!cell) return true;
1484 var newIdx=this.datasetIndex(cell);
1485 if (newIdx.onBlankRow) return true;
1486 Rico.log("selectMouseDown @"+newIdx.row+','+newIdx.column);
1488 if (!this.SelectIdxStart || this.options.highlightMethod!='class') return true;
1489 if (!this.isSelected(cell)) {
1490 this.highlightCell(cell);
1491 this.SelectCtrl.push(this.datasetIndex(cell));
1493 for (var i=0; i<this.SelectCtrl.length; i++) {
1494 if (this.SelectCtrl[i].row==newIdx.row && this.SelectCtrl[i].column==newIdx.column) {
1495 this.unhighlightCell(cell);
1496 this.SelectCtrl.splice(i,1);
1501 } else if (e.shiftKey) {
1502 if (!this.SelectIdxStart) return true;
1503 this.AdjustSelection(cell);
1505 this.selectCell(cell);
1506 this.pluginSelect();
1511 pluginSelect: function() {
1512 if (this.selectPluggedIn) return;
1513 var tBody=this.tbody[this.SelectIdxStart.tabIdx];
1514 Rico.eventBind(tBody,"mouseover", this.options.mouseOverHandler, false);
1515 Rico.eventBind(this.outerDiv,"mouseup", this.options.mouseUpHandler, false);
1516 this.selectPluggedIn=true;
1519 unplugSelect: function() {
1520 if (!this.selectPluggedIn) return;
1521 var tBody=this.tbody[this.SelectIdxStart.tabIdx];
1522 Rico.eventUnbind(tBody,"mouseover", this.options.mouseOverHandler , false);
1523 Rico.eventUnbind(this.outerDiv,"mouseup", this.options.mouseUpHandler , false);
1524 this.selectPluggedIn=false;
1527 selectMouseUp: function(e) {
1528 this.unplugSelect();
1529 var cell=Rico.eventElement(e);
1530 cell=Rico.getParentByTagName(cell,'div','ricoLG_cell');
1532 if (this.SelectIdxStart && this.SelectIdxEnd)
1533 this.AdjustSelection(cell);
1535 this.ClearSelection();
1538 selectMouseOver: function(e) {
1539 var cell=Rico.eventElement(e);
1540 cell=Rico.getParentByTagName(cell,'div','ricoLG_cell');
1542 this.AdjustSelection(cell);
1546 isSelected: function(cell) {
1547 if (this.options.highlightMethod!='outline') return Rico.hasClass(cell,this.options.highlightClass);
1548 if (!this.SelectIdxStart || !this.SelectIdxEnd) return false;
1549 var r1=Math.max(Math.min(this.SelectIdxEnd.row,this.SelectIdxStart.row), this.buffer.windowStart);
1550 var r2=Math.min(Math.max(this.SelectIdxEnd.row,this.SelectIdxStart.row), this.buffer.windowEnd-1);
1551 if (r1 > r2) return false;
1552 var c1=Math.min(this.SelectIdxEnd.column,this.SelectIdxStart.column);
1553 var c2=Math.max(this.SelectIdxEnd.column,this.SelectIdxStart.column);
1554 var curIdx=this.datasetIndex(cell);
1555 return (r1<=curIdx.row && curIdx.row<=r2 && c1<=curIdx.column && curIdx.column<=c2);
1558 highlightCell: function(cell) {
1559 Rico.addClass(cell,this.options.highlightClass);
1562 unhighlightCell: function(cell) {
1563 if (cell) Rico.removeClass(cell,this.options.highlightClass);
1566 selectRow: function(r) {
1567 for (var c=0; c<this.columns.length; c++)
1568 this.highlightCell(this.columns[c].cell(r));
1571 unselectRow: function(r) {
1572 for (var c=0; c<this.columns.length; c++)
1573 this.unhighlightCell(this.columns[c].cell(r));
1576 rowMouseOver: function(e) {
1577 if (!this.highlightEnabled) return;
1578 var cell=Rico.eventElement(e);
1579 cell=Rico.getParentByTagName(cell,'div','ricoLG_cell');
1581 var newIdx=this.winCellIndex(cell);
1582 if ((this.options.highlightSection & (newIdx.tabIdx+1))==0) return;
1583 this.highlight(newIdx);
1586 highlight: function(newIdx) {
1587 if (this.options.highlightMethod!='outline') this.cursorSetClass(newIdx);
1588 if (this.options.highlightMethod!='class') this.cursorOutline(newIdx);
1589 this.highlightIdx=newIdx;
1592 cursorSetClass: function(newIdx) {
1593 switch (this.options.highlightElem) {
1596 if (this.highlightIdx) this.unhighlightCell(this.highlightIdx.cell);
1597 this.highlightCell(newIdx.cell);
1601 if (this.highlightIdx) this.unselectRow(this.highlightIdx.row);
1602 var s1=this.options.highlightSection & 1;
1603 var s2=this.options.highlightSection & 2;
1604 var c0=s1 ? 0 : this.options.frozenColumns;
1605 var c1=s2 ? this.columns.length : this.options.frozenColumns;
1606 for (var c=c0; c<c1; c++)
1607 this.highlightCell(this.columns[c].cell(newIdx.row));
1613 cursorOutline: function(newIdx) {
1615 switch (this.options.highlightElem) {
1618 div=this.highlightDiv[newIdx.tabIdx];
1619 div.style.left=(this.columns[newIdx.column].dataCell.offsetLeft-1)+'px';
1620 div.style.width=this.columns[newIdx.column].colWidth;
1621 this.highlightDiv[1-newIdx.tabIdx].style.display='none';
1625 div=this.highlightDiv[0];
1626 var s1=this.options.highlightSection & 1;
1627 var s2=this.options.highlightSection & 2;
1628 div.style.left=s1 ? '0px' : this.frozenTabs.style.width;
1629 div.style.width=((s1 ? this.frozenTabs.offsetWidth : 0) + (s2 ? this.innerDiv.offsetWidth : 0) - 4)+'px';
1633 div.style.top=(this.hdrHt+newIdx.row*this.rowHeight-1)+'px';
1634 div.style.height=(this.rowHeight-1)+'px';
1635 div.style.display='';
1638 unhighlight: function() {
1639 switch (this.options.highlightElem) {
1641 //this.highlightIdx=this.menuIdx;
1644 if (this.highlightIdx) this.unhighlightCell(this.highlightIdx.cell);
1645 if (!this.highlightDiv) return;
1646 for (var i=0; i<2; i++)
1647 this.highlightDiv[i].style.display='none';
1650 //this.highlightIdx=this.menuIdx;
1653 if (this.highlightIdx) this.unselectRow(this.highlightIdx.row);
1654 if (this.highlightDiv) this.highlightDiv[0].style.display='none';
1659 resetContents: function() {
1660 Rico.log("resetContents");
1661 this.ClearSelection();
1662 this.buffer.clear();
1664 this.clearBookmark();
1667 setImages: function() {
1668 for (var n=0; n<this.columns.length; n++)
1669 this.columns[n].setImage();
1673 * @return column index, or -1 if there are no sorted columns
1675 findSortedColumn: function() {
1676 for (var n=0; n<this.columns.length; n++) {
1677 if (this.columns[n].isSorted()) return n;
1682 findColumnName: function(name) {
1683 for (var n=0; n<this.columns.length; n++) {
1684 if (this.columns[n].fieldName == name) return n;
1690 * Searches options.columnSpecs colAttr for matching colValue
1691 * @return array of matching column indexes
1693 findColumnsBySpec: function(colAttr, colValue) {
1695 for (var n=0; n<this.options.columnSpecs.length; n++) {
1696 if (this.options.columnSpecs[n][colAttr] == colValue) result.push(n);
1704 setSortUI: function( columnNameOrNum, sortDirection ) {
1705 Rico.log("setSortUI: "+columnNameOrNum+' '+sortDirection);
1706 var colnum=this.findSortedColumn();
1708 sortDirection=this.columns[colnum].getSortDirection();
1710 if (typeof sortDirection!='string') {
1711 sortDirection=Rico.ColumnConst.SORT_ASC;
1713 sortDirection=sortDirection.toUpperCase();
1714 if (sortDirection != Rico.ColumnConst.SORT_DESC) sortDirection=Rico.ColumnConst.SORT_ASC;
1716 switch (typeof columnNameOrNum) {
1718 colnum=this.findColumnName(columnNameOrNum);
1721 colnum=columnNameOrNum;
1725 if (typeof(colnum)!='number' || colnum < 0) return;
1727 this.columns[colnum].setSorted(sortDirection);
1728 this.buffer.sortBuffer(colnum);
1732 * clear sort flag on all columns
1734 clearSort: function() {
1735 for (var x=0;x<this.columns.length;x++)
1736 this.columns[x].setUnsorted();
1740 * clear filters on all columns
1742 clearFilters: function() {
1743 for (var x=0;x<this.columns.length;x++) {
1744 this.columns[x].setUnfiltered(true);
1746 if (this.options.filterHandler) {
1747 this.options.filterHandler();
1752 * returns number of columns with a user filter set
1754 filterCount: function() {
1755 for (var x=0,cnt=0;x<this.columns.length;x++) {
1756 if (this.columns[x].isFiltered()) cnt++;
1761 sortHandler: function() {
1763 this.ClearSelection();
1765 var n=this.findSortedColumn();
1767 Rico.log("sortHandler: sorting column "+n);
1768 this.buffer.sortBuffer(n);
1770 this.scrollDiv.scrollTop = 0;
1771 this.buffer.fetch(0);
1774 filterHandler: function() {
1775 Rico.log("filterHandler");
1777 if (this.buffer.processingRequest) {
1778 this.queueFilter=true;
1781 this.unplugScroll();
1782 this.ClearSelection();
1784 this.clearBookmark();
1786 this.buffer.fetch(-1);
1787 Rico.runLater(10,this,'pluginScroll'); // resetting ht div can cause a scroll event, triggering an extra fetch
1790 clearBookmark: function() {
1791 if (this.bookmark) this.bookmark.innerHTML=" ";
1794 bookmarkHandler: function(firstrow,lastrow) {
1796 if (isNaN(firstrow) || !this.bookmark) return;
1797 var totrows=this.buffer.totalRows;
1798 if (totrows < lastrow) lastrow=totrows;
1800 newhtml = Rico.getPhraseById('bookmarkNoMatch');
1801 } else if (lastrow<0) {
1802 newhtml = Rico.getPhraseById('bookmarkNoRec');
1803 } else if (this.buffer.foundRowCount) {
1804 newhtml = Rico.getPhraseById('bookmarkExact',firstrow,lastrow,totrows);
1806 newhtml = Rico.getPhraseById('bookmarkAbout',firstrow,lastrow,totrows);
1808 this.bookmark.innerHTML = newhtml;
1811 clearRows: function() {
1812 if (this.isBlank==true) return;
1813 for (var c=0; c < this.columns.length; c++)
1814 this.columns[c].clearColumn();
1815 this.isBlank = true;
1818 refreshContents: function(startPos) {
1819 Rico.log("refreshContents1 "+this.tableId+": startPos="+startPos+" lastRow="+this.lastRowPos+" PartBlank="+this.isPartialBlank+" pageSize="+this.pageSize);
1822 this.unhighlight(); // in case highlighting was manually invoked
1823 if (this.queueFilter) {
1824 Rico.log("refreshContents: cancelling refresh because filter has changed");
1825 this.queueFilter=false;
1826 this.filterHandler();
1829 this.highlightEnabled=this.options.highlightSection!='none';
1830 var viewPrecedesBuffer = this.buffer.startPos > startPos;
1831 var contentStartPos = viewPrecedesBuffer ? this.buffer.startPos: startPos;
1832 this.contentStartPos = contentStartPos+1;
1833 var contentEndPos = Math.min(this.buffer.startPos + this.buffer.size, startPos + this.pageSize);
1834 this.buffer.setWindow(contentStartPos, contentEndPos);
1835 Rico.log('refreshContents2 '+this.tableId+': cStartPos='+contentStartPos+' cEndPos='+contentEndPos+' vPrecedesBuf='+viewPrecedesBuffer+' b.startPos='+this.buffer.startPos);
1836 if (startPos == this.lastRowPos && !this.isPartialBlank && !this.isBlank) return;
1837 this.isBlank = false;
1838 var onRefreshComplete = this.options.onRefreshComplete;
1840 if ((startPos + this.pageSize < this.buffer.startPos) ||
1841 (this.buffer.startPos + this.buffer.size < startPos) ||
1842 (this.buffer.size == 0)) {
1844 if (onRefreshComplete) onRefreshComplete(this.contentStartPos,contentEndPos); // update bookmark
1848 Rico.log('refreshContents: contentStartPos='+contentStartPos+' contentEndPos='+contentEndPos+' viewPrecedesBuffer='+viewPrecedesBuffer);
1849 var rowSize = contentEndPos - contentStartPos;
1850 var blankSize = this.pageSize - rowSize;
1851 var blankOffset = viewPrecedesBuffer ? 0: rowSize;
1852 var contentOffset = viewPrecedesBuffer ? blankSize: 0;
1854 for (var r=0; r < rowSize; r++) { //initialize what we have
1855 for (var c=0; c < this.columns.length; c++)
1856 this.columns[c].displayValue(r + contentOffset);
1858 for (var i=0; i < blankSize; i++) // blank out the rest
1859 this.blankRow(i + blankOffset);
1860 if (this.options.highlightElem=='selection') this.ShowSelection();
1861 this.isPartialBlank = blankSize > 0;
1862 this.lastRowPos = startPos;
1863 Rico.log("refreshContents complete, startPos="+startPos);
1864 if (onRefreshComplete) onRefreshComplete(this.contentStartPos,contentEndPos); // update bookmark
1867 scrollToRow: function(rowOffset) {
1868 var p=this.rowToPixel(rowOffset);
1869 Rico.log("scrollToRow, rowOffset="+rowOffset+" pixel="+p);
1870 this.scrollDiv.scrollTop = p; // this causes a scroll event
1871 if ( this.options.onscroll )
1872 this.options.onscroll( this, rowOffset );
1875 scrollUp: function() {
1876 this.moveRelative(-1);
1879 scrollDown: function() {
1880 this.moveRelative(1);
1883 pageUp: function() {
1884 this.moveRelative(-this.pageSize);
1887 pageDown: function() {
1888 this.moveRelative(this.pageSize);
1891 adjustRow: function(rowOffset) {
1892 var notdisp=this.topOfLastPage();
1893 if (notdisp == 0 || !rowOffset) return 0;
1894 return Math.min(notdisp,rowOffset);
1897 rowToPixel: function(rowOffset) {
1898 return this.adjustRow(rowOffset) * this.rowHeight;
1902 * @returns row to display at top of scroll div
1904 pixeltorow: function(p) {
1905 var notdisp=this.topOfLastPage();
1906 if (notdisp == 0) return 0;
1907 var prow=parseInt(p/this.rowHeight,10);
1908 return Math.min(notdisp,prow);
1911 moveRelative: function(relOffset) {
1912 var newoffset=Math.max(this.scrollDiv.scrollTop+relOffset*this.rowHeight,0);
1913 newoffset=Math.min(newoffset,this.scrollDiv.scrollHeight);
1914 //Rico.log("moveRelative, newoffset="+newoffset);
1915 this.scrollDiv.scrollTop=newoffset;
1918 pluginScroll: function() {
1919 if (this.scrollPluggedIn) return;
1920 Rico.log("pluginScroll: wheelEvent="+this.wheelEvent);
1921 Rico.eventBind(this.scrollDiv,"scroll",this.scrollEventFunc, false);
1922 for (var t=0; t<2; t++)
1923 Rico.eventBind(this.tabs[t],this.wheelEvent,this.wheelEventFunc, false);
1924 this.scrollPluggedIn=true;
1927 unplugScroll: function() {
1928 if (!this.scrollPluggedIn) return;
1929 Rico.log("unplugScroll");
1930 Rico.eventUnbind(this.scrollDiv,"scroll", this.scrollEventFunc , false);
1931 for (var t=0; t<2; t++)
1932 Rico.eventUnbind(this.tabs[t],this.wheelEvent,this.wheelEventFunc, false);
1933 this.scrollPluggedIn=false;
1936 handleWheel: function(e) {
1940 delta = e.wheelDelta/120;
1941 else if (Rico.isWebKit)
1942 delta = -e.wheelDelta/12;
1944 delta = -e.wheelDelta/120;
1945 } else if (e.detail) {
1946 delta = e.detail/3; /* Mozilla/Gecko */
1948 if (delta) this.moveRelative(delta);
1953 handleScroll: function(e) {
1954 if ( this.scrollTimeout )
1955 clearTimeout( this.scrollTimeout );
1956 this.setHorizontalScroll();
1957 var scrtop=this.scrollDiv.scrollTop;
1958 var vscrollDiff = this.lastScrollPos-scrtop;
1959 if (vscrollDiff == 0.00) return;
1960 var newrow=this.pixeltorow(scrtop);
1961 if (newrow == this.lastRowPos && !this.isPartialBlank && !this.isBlank) return;
1962 var stamp1 = new Date();
1963 Rico.log("handleScroll, newrow="+newrow+" scrtop="+scrtop);
1964 if (this.options.highlightElem=='selection') this.HideSelection();
1965 this.buffer.fetch(newrow);
1966 if (this.options.onscroll) this.options.onscroll(this, newrow);
1967 this.scrollTimeout = Rico.runLater(1200,this,'scrollIdle');
1968 this.lastScrollPos = this.scrollDiv.scrollTop;
1969 var stamp2 = new Date();
1970 //Rico.log("handleScroll, time="+(stamp2.getTime()-stamp1.getTime()));
1973 scrollIdle: function() {
1974 if ( this.options.onscrollidle )
1975 this.options.onscrollidle();
1981 Rico.LiveGridColumn = function(grid,colIdx,hdrInfo,tabIdx) {
1982 this.initialize(grid,colIdx,hdrInfo,tabIdx);
1985 Rico.LiveGridColumn.prototype =
1986 /** @lends Rico.LiveGridColumn# */
1989 * Implements a LiveGrid column. Also contains static properties used by SimpleGrid columns.
1990 * @extends Rico.TableColumnBase
1993 initialize: function(liveGrid,colIdx,hdrInfo,tabIdx) {
1994 Rico.extend(this, new Rico.TableColumnBase());
1995 this.baseInit(liveGrid,colIdx,hdrInfo,tabIdx);
1996 this.buffer=liveGrid.buffer;
1997 if (typeof(this.format.type)!='string' || this.format.EntryType=='tinyMCE') this.format.type='raw';
1998 if (typeof this.isNullable!='boolean') this.isNullable = /number|date/.test(this.format.type);
1999 this.isText = /raw|text|showTags/.test(this.format.type);
2000 Rico.log(" sortable="+this.sortable+" filterable="+this.filterable+" hideable="+this.hideable+" isNullable="+this.isNullable+' isText='+this.isText);
2001 this.fixHeaders(this.liveGrid.tableId, this.options.hdrIconsFirst);
2002 if (this['format_'+this.format.type]) {
2003 this._format=this['format_'+this.format.type];
2005 if (this.format.control) {
2006 // copy all properties/methods that start with '_'
2007 if (typeof this.format.control=='string') {
2008 this.format.control=eval(this.format.control);
2010 for (var property in this.format.control) {
2011 if (property.charAt(0)=='_') {
2012 Rico.log("Copying control property "+property+ ' to ' + this);
2013 this[property] = this.format.control[property];
2020 * Sorts the column in ascending order
2022 sortAsc: function() {
2023 this.setColumnSort(Rico.ColumnConst.SORT_ASC);
2027 * Sorts the column in descending order
2029 sortDesc: function() {
2030 this.setColumnSort(Rico.ColumnConst.SORT_DESC);
2034 * Sorts the column in the specified direction
2035 * @param direction must be one of Rico.ColumnConst.UNSORTED, .SORT_ASC, or .SORT_DESC
2037 setColumnSort: function(direction) {
2038 this.liveGrid.clearSort();
2039 this.setSorted(direction);
2040 if (this.liveGrid.options.saveColumnInfo.sort)
2041 this.liveGrid.setCookie();
2042 if (this.options.sortHandler)
2043 this.options.sortHandler();
2047 * @returns true if this column is allowed to be sorted
2049 isSortable: function() {
2050 return this.sortable;
2054 * @returns true if this column is currently sorted
2056 isSorted: function() {
2057 return this.currentSort != Rico.ColumnConst.UNSORTED;
2061 * @returns Rico.ColumnConst.UNSORTED, .SORT_ASC, or .SORT_DESC
2063 getSortDirection: function() {
2064 return this.currentSort;
2068 * toggle the sort sequence for this column
2070 toggleSort: function() {
2071 if (this.buffer && this.buffer.totalRows==0) return;
2072 if (this.currentSort == Rico.ColumnConst.SORT_ASC)
2079 * Flags that this column is not sorted
2081 setUnsorted: function() {
2082 this.setSorted(Rico.ColumnConst.UNSORTED);
2086 * Flags that this column is sorted, but doesn't actually carry out the sort
2087 * @param direction must be one of Rico.ColumnConst.UNSORTED, .SORT_ASC, or .SORT_DESC
2089 setSorted: function(direction) {
2090 this.currentSort = direction;
2094 * @returns true if this column is allowed to be filtered
2096 canFilter: function() {
2097 return this.filterable;
2101 * @returns a textual representation of how this column is filtered
2103 getFilterText: function() {
2105 for (var i=0; i<this.filterValues.length; i++) {
2106 var v=this.filterValues[i];
2107 vals.push(v=='' ? Rico.getPhraseById('filterBlank') : v);
2109 switch (this.filterOp) {
2110 case 'EQ': return '= '+vals.join(', ');
2111 case 'NE': return Rico.getPhraseById('filterNot',vals.join(', '));
2112 case 'LE': return '<= '+vals[0];
2113 case 'GE': return '>= '+vals[0];
2114 case 'LIKE': return Rico.getPhraseById('filterLike',vals[0]);
2115 case 'NULL': return Rico.getPhraseById('filterEmpty');
2116 case 'NOTNULL': return Rico.getPhraseById('filterNotEmpty');
2122 * @returns returns the query string representation of the filter
2124 getFilterQueryParm: function() {
2125 if (this.filterType == Rico.ColumnConst.UNFILTERED) return '';
2126 var retval='&f['+this.index+'][op]='+this.filterOp;
2127 retval+='&f['+this.index+'][len]='+this.filterValues.length;
2128 for (var i=0; i<this.filterValues.length; i++) {
2129 retval+='&f['+this.index+']['+i+']='+escape(this.filterValues[i]);
2135 * removes the filter from this column
2137 setUnfiltered: function(skipHandler) {
2138 this.filterType = Rico.ColumnConst.UNFILTERED;
2139 if (this.liveGrid.options.saveColumnInfo.filter)
2140 this.liveGrid.setCookie();
2141 if (this.removeFilterFunc)
2142 this.removeFilterFunc();
2143 if (this.options.filterHandler && !skipHandler)
2144 this.options.filterHandler();
2147 setFilterEQ: function() {
2148 this.setUserFilter('EQ');
2150 setFilterNE: function() {
2151 this.setUserFilter('NE');
2153 addFilterNE: function() {
2154 this.filterValues.push(this.userFilter);
2155 if (this.liveGrid.options.saveColumnInfo.filter)
2156 this.liveGrid.setCookie();
2157 if (this.options.filterHandler)
2158 this.options.filterHandler();
2160 setFilterGE: function() { this.setUserFilter('GE'); },
2161 setFilterLE: function() { this.setUserFilter('LE'); },
2162 setFilterKW: function(keyword) {
2163 if (keyword!='' && keyword!=null) {
2164 this.setFilter('LIKE',keyword,Rico.ColumnConst.USERFILTER);
2166 this.setUnfiltered(false);
2170 setUserFilter: function(relop) {
2171 this.setFilter(relop,this.userFilter,Rico.ColumnConst.USERFILTER);
2174 setSystemFilter: function(relop,filter) {
2175 this.setFilter(relop,filter,Rico.ColumnConst.SYSTEMFILTER);
2178 setFilter: function(relop,filter,type,removeFilterFunc) {
2179 this.filterValues = typeof(filter)=='object' ? filter : [filter];
2180 this.filterType = type;
2181 this.filterOp = relop;
2182 if (type == Rico.ColumnConst.USERFILTER && this.liveGrid.options.saveColumnInfo.filter)
2183 this.liveGrid.setCookie();
2184 this.removeFilterFunc=removeFilterFunc;
2185 if (this.options.filterHandler)
2186 this.options.filterHandler();
2189 isFiltered: function() {
2190 return this.filterType == Rico.ColumnConst.USERFILTER;
2193 filterChange: function(e) {
\r
2194 var selbox=Rico.eventElement(e);
2195 if (selbox.value==this.liveGrid.options.FilterAllToken)
\r
2196 this.setUnfiltered();
\r
2198 this.setFilter('EQ',selbox.value,Rico.ColumnConst.USERFILTER,function() {selbox.selectedIndex=0;});
\r
2201 filterClear: function(e) {
\r
2202 this.filterField.value='';
2203 this.setUnfiltered();
\r
2206 filterKeypress: function(e) {
\r
2207 var txtbox=Rico.eventElement(e);
2208 if (typeof this.lastKeyFilter != 'string') this.lastKeyFilter='';
\r
2209 if (this.lastKeyFilter==txtbox.value) return;
\r
2210 var v=txtbox.value;
\r
2211 Rico.log("filterKeypress: "+this.index+' '+v);
\r
2212 this.lastKeyFilter=v;
2213 if (v=='' || v=='*')
\r
2214 this.setUnfiltered();
\r
2216 this.setFilter('LIKE', v, Rico.ColumnConst.USERFILTER, function() {txtbox.value='';});
2220 mFilterSelectClick: function(e) {
2222 if (this.mFilter.style.display!='none') {
2223 this.mFilterFinish(e);
2224 if (Rico.isIE && Rico.ieVersion <= 6) {
2225 this.filterField.focus();
2227 this.filterField.blur();
2230 var offset=Rico.cumulativeOffset(this.filterField);
2231 this.mFilter.style.top=(offset.top+this.filterField.offsetHeight)+'px';
2232 this.mFilter.style.left=offset.left+'px';
2233 this.mFilter.style.width=Math.min(this.filterField.offsetWidth,parseInt(this.colWidth,10))+'px';
2234 Rico.show(this.mFilter);
2235 this.mFilterFocus.focus();
2239 mFilterFinish: function(e) {
2240 if (!this.mFilterChange) {
2241 Rico.hide(this.mFilter);
2244 if (this.mFilterInputs[0].checked) {
2245 this.mFilterReset();
2246 Rico.hide(this.mFilter);
2247 this.setUnfiltered();
2252 for (var i=1; i<this.mFilterInputs.length; i++) {
2253 if (this.mFilterInputs[i].checked) {
2254 newValues.push(this.mFilterInputs[i].value)
2255 newLabels.push(this.mFilterLabels[i].innerHTML)
2258 if (newValues.length > 0) {
2259 var newText=newLabels.join(', ');
2260 this.filterField.options[0].text=newText;
2261 this.filterField.title=newText;
2262 Rico.hide(this.mFilter);
2263 this.mFilterChange=false;
2265 this.setFilter('EQ',newValues,Rico.ColumnConst.USERFILTER,function() { self.mFilterReset(); });
2267 alert('Please select at least one value');
2271 mFilterReset: function() {
2272 var newText=this.mFilterLabels[0].innerHTML; // all
2273 this.filterField.options[0].text=newText;
2274 this.filterField.title=newText;
2277 mFilterAllClick: function(e) {
2278 var allChecked=this.mFilterInputs[0].checked;
2279 for (var i=1; i<this.mFilterInputs.length; i++) {
2280 this.mFilterInputs[i].checked=allChecked;
2282 this.mFilterChange=true;
2285 mFilterOtherClick: function(e) {
2286 this.mFilterInputs[0].checked=false;
2287 this.mFilterChange=true;
2290 format_text: function(v) {
2291 if (typeof v!='string')
2294 return Rico.stripTags(v);
2297 format_showTags: function(v) {
2298 if (typeof v!='string')
2301 return v.replace(/&/g, '&').replace(/</g,'<').replace(/>/g,'>');
2304 format_number: function(v) {
2305 if (typeof v=='undefined' || v=='' || v==null)
2308 return Rico.formatNumber(v,this.format);
2311 format_datetime: function(v) {
2312 if (typeof v=='undefined' || v=='' || v==null)
2315 var d=Rico.setISO8601(v);
2317 return (this.format.prefix || '')+Rico.formatDate(d,this.format.dateFmt || 'translateDateTime')+(this.format.suffix || '');
2321 // converts GMT/UTC to local time
2322 format_UTCasLocalTime: function(v) {
2323 if (typeof v=='undefined' || v=='' || v==null)
2327 var d=Rico.setISO8601(v,-tz.getTimezoneOffset());
2329 return (this.format.prefix || '')+Rico.formatDate(d,this.format.dateFmt || 'translateDateTime')+(this.format.suffix || '');
2333 format_date: function(v) {
2334 if (typeof v=='undefined' || v==null || v=='')
2337 var d=Rico.setISO8601(v);
2339 return (this.format.prefix || '')+Rico.formatDate(d,this.format.dateFmt || 'translateDate')+(this.format.suffix || '');
2343 fixHeaders: function(prefix, iconsfirst) {
2344 if (this.sortable) {
2345 var handler=Rico.eventHandle(this,'toggleSort');
2346 switch (this.options.headingSort) {
2348 var a=Rico.wrapChildren(this.hdrCellDiv,'ricoSort',undefined,'a');
2349 a.href = "javascript:void(0)";
2350 Rico.eventBind(a,"click", handler);
2353 Rico.eventBind(this.hdrCellDiv,"click", handler);
2357 this.imgFilter = document.createElement('span');
2358 this.imgFilter.style.display='none';
2359 this.imgFilter.className='rico-icon ricoLG_filterCol';
2360 this.imgSort = document.createElement('span');
2361 this.imgSort.style.display='none';
2362 this.imgSort.style.verticalAlign='top';
2364 this.hdrCellDiv.insertBefore(this.imgSort,this.hdrCellDiv.firstChild);
2365 this.hdrCellDiv.insertBefore(this.imgFilter,this.hdrCellDiv.firstChild);
2367 this.hdrCellDiv.appendChild(this.imgFilter);
2368 this.hdrCellDiv.appendChild(this.imgSort);
2370 if (!this.format.filterUI) {
2371 Rico.eventBind(this.imgFilter, 'click', Rico.eventHandle(this,'filterClick'), false);
2375 filterClick: function(e) {
2376 if (this.filterType==Rico.ColumnConst.USERFILTER && this.filterOp=='LIKE') {
2377 this.liveGrid.openKeyword(this.index);
2381 getValue: function(windowRow) {
2382 return this.buffer.getWindowCell(windowRow,this.index);
2385 getBufferAttr: function(windowRow) {
2386 return this.buffer.getWindowAttr(windowRow,this.index);
2389 setValue: function(windowRow,newval) {
2390 this.buffer.setWindowValue(windowRow,this.index,newval);
2393 _format: function(v) {
2397 _display: function(v,gridCell) {
2398 gridCell.innerHTML=this._format(v);
2401 _export: function(v) {
2402 return this._format(v);
2405 exportBuffer: function(bufRow) {
2406 return this._export(this.buffer.getValue(bufRow,this.index));
2409 displayValue: function(windowRow) {
2410 var bufval=this.getValue(windowRow);
2412 this.clearCell(windowRow);
2415 var gridCell=this.cell(windowRow);
2416 this._display(bufval,gridCell,windowRow);
2417 var acceptAttr=this.buffer.options.acceptAttr;
2418 if (acceptAttr.length==0) return;
2419 var bufAttr=this.getBufferAttr(windowRow);
2420 if (bufAttr==null) return;
2421 for (var k=0; k<acceptAttr.length; k++) {
2422 bufAttr=bufAttr['_'+acceptAttr[k]] || '';
2423 switch (acceptAttr[k]) {
2424 case 'style': gridCell.style.cssText=bufAttr; break;
2425 case 'class': gridCell.className=bufAttr; break;
2426 default: gridCell['_'+acceptAttr[k]]=bufAttr; break;