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 acceptStyle : false // copy style from original/ajax data?
48 Rico.extend(this.options, options || {});
50 this.loadRowsFromTable(dataTable,this.options.fixedHdrRows);
51 dataTable.parentNode.removeChild(dataTable); // delete the data once it has been loaded
57 registerGrid: function(liveGrid) {
58 this.liveGrid = liveGrid;
61 setTotalRows: function( newTotalRows ) {
62 if (typeof(newTotalRows)!='number') newTotalRows=this.size;
63 if (this.totalRows == newTotalRows) return;
64 this.totalRows = newTotalRows;
65 if (!this.liveGrid) return;
66 Rico.log("setTotalRows, newTotalRows="+newTotalRows);
67 switch (this.liveGrid.sizeTo) {
69 this.liveGrid.resizeWindow();
72 this.liveGrid.setPageSize(newTotalRows);
75 this.liveGrid.updateHeightDiv();
80 loadRowsFromTable: function(tableElement,firstRow) {
82 var trs = tableElement.getElementsByTagName("tr");
83 for ( var i=firstRow || 0; i < trs.length; i++ ) {
85 var cells = trs[i].getElementsByTagName("td");
86 for ( var j=0; j < cells.length ; j++ )
87 row[j]=cells[j].innerHTML;
90 this.loadRows(newRows);
93 loadRowsFromArray: function(array2D) {
94 for ( var i=0; i < array2D.length; i++ ) {
95 for ( var j=0; j < array2D[i].length ; j++ ) {
96 array2D[i][j]=array2D[i][j].toString();
99 this.loadRows(array2D);
102 loadRows: function(jstable) {
103 this.baseRows = jstable;
105 this.size = this.baseRows.length;
108 dom2jstable: function(rowsElement) {
109 Rico.log('dom2jstable: encoded='+this.options.isEncoded);
111 var trs = rowsElement.getElementsByTagName("tr");
112 for ( var i=0; i < trs.length; i++ ) {
114 var cells = trs[i].getElementsByTagName("td");
115 for ( var j=0; j < cells.length ; j++ )
116 row[j]=Rico.getContentAsString(cells[j],this.options.isEncoded);
122 _blankRow: function() {
124 for (var i=0; i<this.liveGrid.columns.length; i++) {
130 deleteRows: function(rowIndex,cnt) {
131 this.baseRows.splice(rowIndex,typeof(cnt)=='number' ? cnt : 1);
132 this.liveGrid.isPartialBlank=true;
133 this.size=this.baseRows.length;
136 insertRow: function(beforeRowIndex) {
137 var r=this._blankRow();
138 this.baseRows.splice(beforeRowIndex,0,r);
139 this.size=this.baseRows.length;
140 this.liveGrid.isPartialBlank=true;
141 if (this.startPos < 0) this.startPos=0;
145 appendRows: function(cnt) {
147 for (var i=0; i<cnt; i++) {
148 var r=this._blankRow();
149 this.baseRows.push(r);
152 this.size=this.baseRows.length;
153 this.liveGrid.isPartialBlank=true;
154 if (this.startPos < 0) this.startPos=0;
158 sortFunc: function(coltype) {
161 case 'number': return function(a,b) { return self._sortNumeric(a,b); };
162 case 'control':return function(a,b) { return self._sortControl(a,b); };
163 default: return function(a,b) { return self._sortAlpha(a,b); };
167 sortBuffer: function(colnum) {
168 if (!this.baseRows) {
169 this.delayedSortCol=colnum;
172 this.liveGrid.showMsg(Rico.getPhraseById("sorting"));
173 this.sortColumn=colnum;
174 var col=this.liveGrid.columns[colnum];
175 this.getValFunc=col._sortfunc;
176 this.baseRows.sort(this.sortFunc(col.format.type));
177 if (col.getSortDirection()=='DESC') this.baseRows.reverse();
180 _sortAlpha: function(a,b) {
181 var aa = this.sortColumn<a.length ? Rico.getInnerText(a[this.sortColumn]) : '';
182 var bb = this.sortColumn<b.length ? Rico.getInnerText(b[this.sortColumn]) : '';
183 if (aa==bb) return 0;
184 if (aa<bb) return -1;
188 _sortNumeric: function(a,b) {
189 var aa = this.sortColumn<a.length ? this.nan2zero(Rico.getInnerText(a[this.sortColumn])) : 0;
190 var bb = this.sortColumn<b.length ? this.nan2zero(Rico.getInnerText(b[this.sortColumn])) : 0;
194 nan2zero: function(n) {
195 if (typeof(n)=='string') n=parseFloat(n);
196 return isNaN(n) || typeof(n)=='undefined' ? 0 : n;
199 _sortControl: 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 (this.getValFunc) {
203 aa=this.getValFunc(aa);
204 bb=this.getValFunc(bb);
206 if (aa==bb) return 0;
207 if (aa<bb) return -1;
219 isInRange: function(position) {
220 var lastRow=Math.min(this.totalRows, position + this.liveGrid.pageSize);
221 return (position >= this.startPos) && (lastRow <= this.endPos()); // && (this.size != 0);
225 return this.startPos + this.rows.length;
228 fetch: function(offset) {
229 Rico.log('fetch '+this.liveGrid.tableId+': offset='+offset);
232 this.rcvdRowCount = true;
233 this.foundRowCount = true;
234 if (offset < 0) offset=0;
235 this.liveGrid.refreshContents(offset);
240 * @return a 2D array of buffer data representing the rows that are currently visible on the grid
242 visibleRows: function() {
243 return this.rows.slice(this.windowStart,this.windowEnd);
246 setWindow: function(startrow, endrow) {
247 this.windowStart = startrow - this.startPos; // position in the buffer of first visible row
248 Rico.log('setWindow '+this.liveGrid.tableId+': '+startrow+', '+endrow+', newstart='+this.windowStart);
249 this.windowEnd = Math.min(endrow,this.size); // position in the buffer of last visible row containing data+1
250 this.windowPos = startrow; // position in the dataset of first visible row
254 * @return true if bufRow is currently visible in the grid
256 isVisible: function(bufRow) {
257 return bufRow < this.rows.length && bufRow >= this.windowStart && bufRow < this.windowEnd;
261 * takes a window row index and returns the corresponding buffer row index
263 bufferRow: function(windowRow) {
264 return this.windowStart+windowRow;
268 * @return buffer cell at the specified visible row/col index
270 getWindowCell: function(windowRow,col) {
271 var bufrow=this.bufferRow(windowRow);
272 return this.isVisible(bufrow) && col < this.rows[bufrow].length ? this.rows[bufrow][col] : null;
275 getWindowStyle: function(windowRow,col) {
276 var bufrow=this.bufferRow(windowRow);
277 return this.attr && this.isVisible(bufrow) && this.attr[bufrow] && col < this.attr[bufrow].length ? this.attr[bufrow][col] : '';
280 getWindowValue: function(windowRow,col) {
281 return this.getWindowCell(windowRow,col);
284 setWindowValue: function(windowRow,col,newval) {
285 var bufrow=this.bufferRow(windowRow);
286 if (bufrow >= this.windowEnd) return false;
287 return this.setValue(bufrow,col,newval);
290 getCell: function(bufRow,col) {
291 return bufRow < this.size ? this.rows[bufRow][col] : null;
294 getValue: function(bufRow,col) {
295 return this.getCell(bufRow,col);
298 setValue: function(bufRow,col,newval,newstyle) {
299 if (bufRow>=this.size) return false;
300 if (!this.rows[bufRow][col]) this.rows[bufRow][col]={};
301 this.rows[bufRow][col]=newval;
302 if (typeof newstyle=='string') this.rows[bufRow][col]._style=newstyle;
303 this.rows[bufRow][col].modified=true;
307 getRows: function(start, count) {
308 var begPos = start - this.startPos;
309 var endPos = Math.min(begPos + count,this.size);
311 for ( var i=begPos; i < endPos; i++ ) {
312 results.push(this.rows[i]);
317 applyFilters: function() {
318 var newRows=[],re=[];
319 var r,c,n,i,showRow,filtercnt;
320 var cols=this.liveGrid.columns;
321 for (n=0,filtercnt=0; n<cols.length; n++) {
323 if (c.filterType == Rico.ColumnConst.UNFILTERED) continue;
325 if (c.filterOp=='LIKE') re[n]=new RegExp(c.filterValues[0],'i');
327 Rico.log('applyFilters: # of filters='+filtercnt);
329 this.rows = this.baseRows;
331 for (r=0; r<this.baseRows.length; r++) {
333 for (n=0; n<cols.length && showRow; n++) {
335 if (c.filterType == Rico.ColumnConst.UNFILTERED) continue;
336 switch (c.filterOp) {
338 showRow=re[n].test(this.baseRows[r][n]);
341 showRow=this.baseRows[r][n]==c.filterValues[0];
344 for (i=0; i<c.filterValues.length && showRow; i++)
345 showRow=this.baseRows[r][n]!=c.filterValues[i];
348 if (c.format.type=='number')
349 showRow=this.nan2zero(this.baseRows[r][n])<=this.nan2zero(c.filterValues[0]);
351 showRow=this.baseRows[r][n]<=c.filterValues[0];
354 if (c.format.type=='number')
355 showRow=this.nan2zero(this.baseRows[r][n])>=this.nan2zero(c.filterValues[0]);
357 showRow=this.baseRows[r][n]>=c.filterValues[0];
360 showRow=this.baseRows[r][n]=='';
363 showRow=this.baseRows[r][n]!='';
367 if (showRow) newRows.push(this.baseRows[r]);
371 this.rowcntContent = this.size = this.rows.length;
374 printAll: function() {
375 this.liveGrid.showMsg(Rico.getPhraseById('exportInProgress'));
376 Rico.runLater(10,this,'_printAll'); // allow message to paint
380 * Support function for printAll()
382 _printAll: function() {
383 this.liveGrid.exportStart();
384 this.exportBuffer(this.getRows(0,this.totalRows));
385 this.liveGrid.exportFinish();
389 * Copies visible rows to a new window as a simple html table.
391 printVisible: function() {
392 this.liveGrid.showMsg(Rico.getPhraseById('exportInProgress'));
393 Rico.runLater(10,this,'_printVisible'); // allow message to paint
396 _printVisible: function() {
397 this.liveGrid.exportStart();
398 this.exportBuffer(this.visibleRows());
399 this.liveGrid.exportFinish();
403 * Send all rows to print/export window
405 exportBuffer: function(rows,startPos) {
406 var r,c,v,col,exportText;
407 Rico.log("exportBuffer: "+rows.length+" rows");
408 var exportStyles=this.liveGrid.getExportStyles(this.liveGrid.tbody[0]);
410 var totalcnt=startPos || 0;
411 var cols=this.liveGrid.columns;
412 for (c=0; c<cols.length; c++) {
413 if (cols[c].visible) tdstyle[c]=this.liveGrid.exportStyle(cols[c].cell(0),exportStyles); // assumes row 0 style applies to all rows
415 for(r=0; r < rows.length; r++) {
417 for (c=0; c<cols.length; c++) {
418 if (!cols[c].visible) continue;
420 col.expStyle=tdstyle[c];
421 v=col._export(rows[r][c],rows[r]);
422 if (v=='') v=' ';
423 exportText+="<td style='"+col.expStyle+"'>"+v+"</td>";
425 this.liveGrid.exportRows.push(exportText);
427 if (totalcnt % 10 == 0) window.status=Rico.getPhraseById('exportStatus',totalcnt);
434 // Rico.LiveGrid -----------------------------------------------------
436 Rico.LiveGrid = function(tableId, buffer, options) {
437 this.initialize(tableId, buffer, options);
441 * @lends Rico.LiveGrid#
442 * @property tableId id string for this grid
443 * @property options the options object passed to the constructor extended with defaults
444 * @property buffer the buffer object containing the data for this grid
445 * @property columns array of {@link Rico.LiveGridColumn} objects
447 Rico.LiveGrid.prototype = {
449 * @class Buffered LiveGrid component
450 * @extends Rico.GridCommon
453 initialize: function( tableId, buffer, options ) {
454 Rico.extend(this, Rico.GridCommon);
455 Rico.extend(this, Rico.LiveGridMethods);
457 this.tableId = tableId;
458 this.buffer = buffer;
459 this.actionId='_action_'+tableId;
460 Rico.setDebugArea(tableId+"_debugmsgs"); // if used, this should be a textarea
462 Rico.extend(this.options, {
463 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)
465 offset : 0, // first row to be displayed
466 prefetchBuffer : true, // load table on page load?
469 canSortDefault : true, // can be overridden in the column specs
470 canFilterDefault : buffer.options.canFilter, // can be overridden in the column specs
471 canHideDefault : true, // can be overridden in the column specs
473 // highlight & selection parameters
474 highlightElem : 'none',// what gets highlighted/selected (cursorRow, cursorCell, menuRow, menuCell, selection, or none)
475 highlightSection : 3, // which section gets highlighted (frozen=1, scrolling=2, all=3, none=0)
476 highlightMethod : 'class', // outline, class, both (outline is less CPU intensive on the client)
477 highlightClass : Rico.theme.gridHighlightClass || 'ricoLG_selection',
479 // export/print parameters
480 maxPrint : 5000, // max # of rows that can be printed/exported, 0=disable print/export feature
482 // heading parameters
483 headingSort : 'link', // link: make headings a link that will sort column, hover: make headings a hoverset, none: events on headings are disabled
484 hdrIconsFirst : true // true: put sort & filter icons before header text, false: after
487 // sortCol: initial sort column
490 this.options.sortHandler = function() { self.sortHandler(); };
491 this.options.filterHandler = function() { self.filterHandler(); };
492 this.options.onRefreshComplete = function(firstrow,lastrow) { self.bookmarkHandler(firstrow,lastrow); };
493 this.options.rowOverHandler = Rico.eventHandle(this,'rowMouseOver');
494 this.options.mouseDownHandler = Rico.eventHandle(this,'selectMouseDown');
495 this.options.mouseOverHandler = Rico.eventHandle(this,'selectMouseOver');
496 this.options.mouseUpHandler = Rico.eventHandle(this,'selectMouseUp');
497 Rico.extend(this.options, options || {});
499 switch (typeof this.options.visibleRows) {
501 this.sizeTo=this.options.visibleRows;
502 switch (this.options.visibleRows) {
503 case 'data': this.options.visibleRows=-2; break;
504 case 'body': this.options.visibleRows=-3; break;
505 case 'parent': this.options.visibleRows=-4; break;
506 case 'datamax':this.options.visibleRows=-5; break;
507 default: this.options.visibleRows=-1; break;
511 switch (this.options.visibleRows) {
512 case -1: this.sizeTo='window'; break;
513 case -2: this.sizeTo='data'; break;
514 case -3: this.sizeTo='body'; break;
515 case -4: this.sizeTo='parent'; break;
516 case -5: this.sizeTo='datamax'; break;
517 default: this.sizeTo='fixed'; break;
522 this.options.visibleRows=-3;
525 this.highlightEnabled=this.options.highlightSection>0;
528 if (this.headerColCnt==0) {
529 alert('ERROR: no columns found in "'+this.tableId+'"');
532 this.createColumnArray('LiveGridColumn');
533 if (this.options.headingSort=='hover')
534 this.createHoverSet();
536 this.bookmark=document.getElementById(this.tableId+"_bookmark");
539 if (this.buffer.options.canFilter && this.options.AutoFilter)
540 filterUIrow=this.addHeadingRow('ricoLG_FilterRow');
541 this.createDataCells(this.options.visibleRows);
542 if (this.pageSize == 0) return;
543 this.buffer.registerGrid(this);
544 if (this.buffer.setBufferSize) this.buffer.setBufferSize(this.pageSize);
545 this.scrollTimeout = null;
546 this.lastScrollPos = 0;
547 this.attachMenuEvents();
549 this.setSortUI( this.options.sortCol, this.options.sortDir );
551 if (this.listInvisible().length==this.columns.length)
552 this.columns[0].showColumn();
554 this.scrollDiv.style.display="";
555 if (this.buffer.totalRows>0)
556 this.updateHeightDiv();
557 if (this.options.prefetchBuffer) {
558 if (this.bookmark) this.bookmark.innerHTML = Rico.getPhraseById('bookmarkLoading');
559 if (this.options.canFilterDefault && this.options.getQueryParms)
560 this.checkForFilterParms();
561 this.scrollToRow(this.options.offset);
562 this.buffer.fetch(this.options.offset);
564 if (filterUIrow >= 0)
565 this.createFilters(filterUIrow);
566 this.scrollEventFunc=Rico.eventHandle(this,'handleScroll');
567 this.wheelEventFunc=Rico.eventHandle(this,'handleWheel');
568 this.wheelEvent=(Rico.isIE || Rico.isOpera || Rico.isWebKit) ? 'mousewheel' : 'DOMMouseScroll';
569 if (this.options.offset && this.options.offset < this.buffer.totalRows)
570 Rico.runLater(50,this,'scrollToRow',this.options.offset); // Safari requires a delay
572 this.setHorizontalScroll();
573 Rico.log("setHorizontalScroll done");
574 if (this.options.windowResize)
575 Rico.runLater(100,this,'pluginWindowResize');
576 Rico.log("initialize complete for "+this.tableId);
577 //alert('clientLeft='+this.scrollDiv.clientLeft);
578 if (this.direction=='rtl' && (!Rico.isWebKit || this.scrollDiv.clientLeft > 0)) {
579 this.scrollTab.style.right='0px';
581 this.scrollTab.style.left='0px';
582 Rico.setStyle(this.tabs[1], {'float': 'left'});
588 Rico.LiveGridMethods = {
589 /** @lends Rico.LiveGrid# */
591 createHoverSet: function() {
593 for( var c=0; c < this.headerColCnt; c++ ) {
594 if (this.columns[c].sortable) {
\r
595 hdrs.push(this.columns[c].hdrCellDiv);
598 this.hoverSet = new Rico.HoverSet(hdrs);
601 checkForFilterParms: function() {
602 var s=window.location.search;
603 if (s.charAt(0)=='?') s=s.substring(1);
604 var pairs = s.split('&');
605 for (var i=0; i<pairs.length; i++) {
606 if (pairs[i].match(/^f\[\d+\]/)) {
607 this.buffer.options.requestParameters.push(pairs[i]);
613 * Refreshes a detail grid from a master grid
614 * @returns row index on master table on success, -1 otherwise
616 drillDown: function(e,masterColNum,detailColNum) {
617 var cell=Rico.eventElement(e || window.event);
618 cell=Rico.getParentByTagName(cell,'div','ricoLG_cell');
619 if (!cell) return -1;
620 var idx=this.winCellIndex(cell);
621 if (idx.row >= this.buffer.totalRows) return -1
623 this.menuIdx=idx; // ensures selection gets cleared when menu is displayed
625 var drillValue=this.buffer.getWindowCell(idx.row,masterColNum);
626 for (var i=3; i<arguments.length; i++)
627 arguments[i].setDetailFilter(detailColNum,drillValue);
632 * set filter on a detail grid that is in a master-detail relationship
634 setDetailFilter: function(colNumber,filterValue) {
635 var c=this.columns[colNumber];
636 c.format.ColData=filterValue;
637 c.setSystemFilter('EQ',filterValue);
641 * Create one table for frozen columns and one for scrolling columns.
642 * Also create div's to contain them.
643 * @returns true on success
645 createTables: function() {
646 var insertloc,hdrSrc,i;
647 var table = document.getElementById(this.tableId) || document.getElementById(this.tableId+'_outerDiv');
648 if (!table) return false;
649 if (table.tagName.toLowerCase()=='table') {
650 var theads=table.getElementsByTagName("thead");
651 if (theads.length == 1) {
652 Rico.log("createTables: using thead section, id="+this.tableId);
653 if (this.options.ColGroupsOnTabHdr && this.options.ColGroups) {
654 var r=theads[0].insertRow(0);
655 this.insertPanelNames(r, 0, this.options.frozenColumns, 'ricoFrozen');
656 this.insertPanelNames(r, this.options.frozenColumns, this.options.columnSpecs.length);
658 hdrSrc=theads[0].rows;
660 Rico.log("createTables: using tbody section, id="+this.tableId);
661 hdrSrc=new Array(table.rows[0]);
664 } else if (this.options.columnSpecs.length > 0) {
665 if (!table.id.match(/_outerDiv$/)) insertloc=table;
666 Rico.log("createTables: inserting at "+table.tagName+", id="+this.tableId);
668 alert("ERROR!\n\nUnable to initialize '"+this.tableId+"'\n\nLiveGrid terminated");
673 this.scrollContainer = this.createDiv("scrollContainer",this.structTabLR);
674 this.scrollContainer.appendChild(this.scrollDiv); // move scrollDiv
675 this.scrollTab = this.createDiv("scrollTab",this.scrollContainer);
676 this.shadowDiv = this.createDiv("shadow",this.scrollDiv);
677 this.shadowDiv.style.direction='ltr'; // avoid FF bug
678 this.scrollDiv.style.display="none";
679 this.scrollDiv.scrollTop=0;
680 if (this.options.highlightMethod!='class') {
681 this.highlightDiv=[];
682 switch (this.options.highlightElem) {
685 this.highlightDiv[0] = this.createDiv("highlight",this.outerDiv);
686 this.highlightDiv[0].style.display="none";
690 for (i=0; i<2; i++) {
691 this.highlightDiv[i] = this.createDiv("highlight",i==0 ? this.frozenTabs : this.scrollTab);
692 this.highlightDiv[i].style.display="none";
693 this.highlightDiv[i].id+=i;
697 // create one div for each side of the rectangle
698 var parentDiv=this.options.highlightSection==1 ? this.frozenTabs : this.scrollTab;
699 for (i=0; i<4; i++) {
700 this.highlightDiv[i] = this.createDiv("highlight",parentDiv);
701 this.highlightDiv[i].style.display="none";
702 this.highlightDiv[i].style.overflow="hidden";
703 this.highlightDiv[i].id+=i;
704 this.highlightDiv[i].style[i % 2==0 ? 'height' : 'width']="0px";
711 for (i=0; i<3; i++) {
712 this.tabs[i] = document.createElement("table");
713 this.tabs[i].className = (i < 2) ? 'ricoLG_table' : 'ricoLG_scrollTab';
714 this.tabs[i].border=0;
715 this.tabs[i].cellPadding=0;
716 this.tabs[i].cellSpacing=0;
717 this.tabs[i].id = this.tableId+"_tab"+i;
720 for (i=0; i<2; i++) {
721 this.thead[i]=this.tabs[i].createTHead();
722 //Rico.addClass(this.tabs[i],'ricoLG_top');
723 this.thead[i].className='ricoLG_top';
724 if (Rico.theme.gridheader) Rico.addClass(this.thead[i],Rico.theme.gridheader);
727 for (i=0; i<2; i++) {
728 this.tbody[i]=Rico.getTBody(this.tabs[i==0?0:2]);
729 this.tbody[i].className='ricoLG_bottom';
730 if (Rico.theme.gridcontent) Rico.addClass(this.tbody[i],Rico.theme.gridcontent);
731 this.tbody[i].insertRow(-1);
733 this.frozenTabs.appendChild(this.tabs[0]);
734 this.innerDiv.appendChild(this.tabs[1]);
735 this.scrollTab.appendChild(this.tabs[2]);
736 if (insertloc) insertloc.parentNode.insertBefore(this.outerDiv,insertloc);
738 this.headerColCnt = this.getColumnInfo(hdrSrc);
739 this.loadHdrSrc(hdrSrc);
741 this.createHdr(0,0,this.options.frozenColumns);
742 this.createHdr(1,this.options.frozenColumns,this.options.columnSpecs.length);
743 if (this.options.ColGroupsOnTabHdr && this.options.ColGroups) {
744 this.insertPanelNames(this.thead[0].insertRow(0), 0, this.options.frozenColumns);
745 this.insertPanelNames(this.thead[1].insertRow(0), this.options.frozenColumns, this.options.columnSpecs.length);
748 this.headerColCnt = this.getColumnInfo(this.thead[i].rows);
750 for( var c=0; c < this.headerColCnt; c++ )
751 this.tbody[c<this.options.frozenColumns ? 0 : 1].rows[0].insertCell(-1);
752 if (insertloc) table.parentNode.removeChild(table);
753 Rico.log('createTables end');
757 createDataCells: function(visibleRows) {
758 if (visibleRows < 0) {
759 for (var i=0; i<this.options.minPageRows; i++)
760 this.appendBlankRow();
762 this.autoAppendRows(this.remainingHt());
764 for( var r=0; r < visibleRows; r++ )
765 this.appendBlankRow();
767 var s=this.options.highlightSection;
768 if (s & 1) this.attachHighlightEvents(this.tbody[0]);
769 if (s & 2) this.attachHighlightEvents(this.tbody[1]);
773 * @param colnum column number
774 * @return id string for a filter element
776 filterId: function(colnum) {
777 return 'RicoFilter_'+this.tableId+'_'+colnum;
781 * Create filter elements in heading
782 * Reads this.columns[].filterUI to determine type of filter element for each column (t=text box, s=select list, c=custom)
783 * @param r heading row where filter elements will be placed
785 createFilters: function(r) {
786 for( var c=0; c < this.headerColCnt; c++ ) {
787 var col=this.columns[c];
789 if (typeof fmt.filterUI!='string') continue;
790 var cell=this.hdrCells[r][c].cell;
791 var field,name=this.filterId(c);
\r
792 var divs=cell.getElementsByTagName('div');
793 // copy text alignment from data cell
794 var align=Rico.getStyle(this.cell(0,c),'textAlign');
795 divs[1].style.textAlign=align;
796 switch (fmt.filterUI.charAt(0)) {
799 field=Rico.createFormField(divs[1],'input',Rico.inputtypes.search ? 'search' : 'text',name,name);
800 var size=fmt.filterUI.match(/\d+/);
801 field.maxLength=fmt.Length || 50;
\r
802 field.size=size ? parseInt(size,10) : 10;
803 if (field.type != 'search') divs[1].appendChild(Rico.clearButton(Rico.eventHandle(col,'filterClear')));
804 if (col.filterType==Rico.ColumnConst.USERFILTER && col.filterOp=='LIKE') {
805 var v=col.filterValues[0];
806 if (v.charAt(0)=='*') v=v.substr(1);
807 if (v.slice(-1)=='*') v=v.slice(0,-1);
811 Rico.eventBind(field,'keyup',Rico.eventHandle(col,'filterKeypress'),false);
812 col.filterField=field;
\r
818 field=Rico.createFormField(divs[1],'select',null,name);
\r
819 Rico.addSelectOption(field,this.options.FilterAllToken,Rico.getPhraseById("filterAll"));
\r
820 col.filterField=field;
822 Rico.extend(options, this.buffer.ajaxOptions);
823 var colnum=typeof(fmt.filterCol)=='number' ? fmt.filterCol : c;
824 options.parameters = {id: this.tableId, distinct:colnum};
825 options.parameters[this.actionId]="query";
826 options.onComplete = this.filterValuesUpdateFunc(c);
827 new Rico.ajaxRequest(this.buffer.dataSource, options);
831 if (typeof col._createFilters == 'function')
832 col._createFilters(divs[1], name);
836 this.initFilterImage(r);
839 filterValuesUpdateFunc: function(colnum) {
841 return function (request) { self.filterValuesUpdate(colnum,request); };
845 * update select list filter with values in AJAX response
846 * @returns true on success
848 filterValuesUpdate: function(colnum,request) {
849 var response = request.responseXML.getElementsByTagName("ajax-response");
850 Rico.log("filterValuesUpdate: "+request.status);
851 if (response == null || response.length != 1) return false;
852 response=response[0];
853 var error = response.getElementsByTagName('error');
854 if (error.length > 0) {
855 Rico.log("Data provider returned an error:\n"+Rico.getContentAsString(error[0],this.buffer.isEncoded));
856 alert(Rico.getPhraseById("requestError",Rico.getContentAsString(error[0],this.buffer.isEncoded)));
859 response=response.getElementsByTagName('response')[0];
\r
860 var rowsElement = response.getElementsByTagName('rows')[0];
\r
861 var col=this.columns[parseInt(colnum,10)];
862 var rows = this.buffer.dom2jstable(rowsElement);
\r
864 if (col.filterType==Rico.ColumnConst.USERFILTER && col.filterOp=='EQ') v=col.filterValues[0];
865 Rico.log('filterValuesUpdate: col='+colnum+' rows='+rows.length);
866 switch (col.format.filterUI.charAt(0)) {
869 col.mFilter = document.body.appendChild(document.createElement("div"));
870 col.mFilter.className = 'ricoLG_mFilter'
871 Rico.hide(col.mFilter);
872 var contentDiv = col.mFilter.appendChild(document.createElement("div"));
873 contentDiv.className = 'ricoLG_mFilter_content'
874 var buttonDiv = col.mFilter.appendChild(document.createElement("div"));
875 buttonDiv.className = 'ricoLG_mFilter_button'
876 col.mFilterButton=buttonDiv.appendChild(document.createElement("button"));
877 col.mFilterButton.innerHTML=Rico.getPhraseById("ok");
878 var eventName=Rico.isWebKit ? 'mousedown' : 'click';
879 Rico.eventBind(col.filterField,eventName,Rico.eventHandle(col,'mFilterSelectClick'));
880 Rico.eventBind(col.mFilterButton,'click',Rico.eventHandle(col,'mFilterFinish'));
881 //col.filterField.options[0].text=$('AllLabel').innerHTML;
882 tab = contentDiv.appendChild(document.createElement("table"));
886 //tbody=(tab.tBodies.length==0) ? tab.appendChild(document.createElement("tbody")) : tab.tBodies[0];
887 var baseId=this.filterId(colnum)+'_';
888 this.createMFilterItem(tab,this.options.FilterAllToken,Rico.getPhraseById("filterAll"),baseId+'all',Rico.eventHandle(col,'mFilterAllClick'));
889 var handle=Rico.eventHandle(col,'mFilterOtherClick')
890 for (var i=0; i<rows.length; i++) {
891 if (rows[i].length>0) {
893 this.createMFilterItem(tab,c,c || Rico.getPhraseById("filterBlank"),baseId+i,handle);
896 col.mFilterInputs=contentDiv.getElementsByTagName('input');
897 col.mFilterLabels=contentDiv.getElementsByTagName('label');
898 col.mFilterFocus=col.mFilterInputs.length ? col.mFilterInputs[0] : col.mFilterButton;
903 for (var i=0; i<rows.length; i++) {
904 if (rows[i].length>0) {
906 opt=Rico.addSelectOption(col.filterField,c,c || Rico.getPhraseById("filterBlank"));
907 if (col.filterType==Rico.ColumnConst.USERFILTER && c==v) opt.selected=true;
910 Rico.eventBind(col.filterField,'change',Rico.eventHandle(col,'filterChange'));
916 createMFilterItem: function(table,code,description,id,eventHandle) {
917 var tr=table.insertRow(-1);
919 if (tr.rowIndex % 2 == 1) tr.className='ricoLG_mFilter_oddrow';
920 var td1=tr.insertCell(-1)
921 var td2=tr.insertCell(-1)
922 var field=Rico.createFormField(td1,'input','checkbox',id);
925 var label = td2.appendChild(document.createElement("label"));
927 label.innerHTML=description;
928 Rico.eventBind(field,'click',eventHandle);
931 unplugHighlightEvents: function() {
932 var s=this.options.highlightSection;
933 if (s & 1) this.detachHighlightEvents(this.tbody[0]);
934 if (s & 2) this.detachHighlightEvents(this.tbody[1]);
938 * place panel names on first row of grid header (used by LiveGridForms)
940 insertPanelNames: function(r,start,limit,cellClass) {
941 Rico.log('insertPanelNames: start='+start+' limit='+limit);
942 r.className='ricoLG_hdg';
943 var lastIdx=-1, span, newCell=null, spanIdx=0;
944 for( var c=start; c < limit; c++ ) {
945 if (lastIdx == this.options.columnSpecs[c].ColGroupIdx) {
948 if (newCell) newCell.colSpan=span;
949 newCell = r.insertCell(-1);
950 if (cellClass) newCell.className=cellClass;
952 lastIdx=this.options.columnSpecs[c].ColGroupIdx;
953 newCell.innerHTML=this.options.ColGroups[lastIdx];
956 if (newCell) newCell.colSpan=span;
960 * create grid header for table i (if none was provided)
962 createHdr: function(i,start,limit) {
963 Rico.log('createHdr: i='+i+' start='+start+' limit='+limit);
964 var mainRow = this.thead[i].insertRow(-1);
965 mainRow.id=this.tableId+'_tab'+i+'h_main';
966 mainRow.className='ricoLG_hdg';
967 for( var c=start; c < limit; c++ ) {
968 var newCell = mainRow.insertCell(-1);
969 newCell.innerHTML=this.options.columnSpecs[c].Hdg;
974 * move header cells in original table to grid
976 loadHdrSrc: function(hdrSrc) {
977 var i,h,c,r,newrow,cells;
978 Rico.log('loadHdrSrc start');
979 for (i=0; i<2; i++) {
980 for (r=0; r<hdrSrc.length; r++) {
981 newrow = this.thead[i].insertRow(-1);
982 newrow.className='ricoLG_hdg '+this.tableId+'_hdg'+r;
985 if (hdrSrc.length==1) {
986 cells=hdrSrc[0].cells;
987 for (c=0; cells.length > 0; c++)
988 this.thead[c<this.options.frozenColumns ? 0 : 1].rows[0].appendChild(cells[0]);
990 for (r=0; r<hdrSrc.length; r++) {
991 cells=hdrSrc[r].cells;
992 for (c=0,h=0; cells.length > 0; c++) {
993 if (Rico.hasClass(cells[0],'ricoFrozen')) {
994 if (r==this.headerRowIdx) this.options.frozenColumns=c+1;
998 this.thead[h].rows[r].appendChild(cells[0]);
1002 Rico.log('loadHdrSrc end');
1008 sizeDivs: function() {
1009 Rico.log('sizeDivs: '+this.tableId);
1010 //this.cancelMenu();
1012 this.baseSizeDivs();
1013 var firstVisible=this.firstVisible();
1014 if (this.pageSize == 0 || firstVisible < 0) return;
1015 var totRowHt=this.columns[firstVisible].dataColDiv.offsetHeight;
1016 this.rowHeight = Math.round(totRowHt/this.pageSize);
1017 var scrHt=this.dataHt;
1018 if (this.scrTabWi0 == this.scrTabWi) {
1019 // no scrolling columns - horizontal scroll bar not needed
1020 this.innerDiv.style.height=(this.hdrHt+1)+'px';
1021 this.scrollDiv.style.overflowX='hidden';
1023 this.scrollDiv.style.overflowX='scroll';
1024 scrHt+=this.options.scrollBarWidth;
1026 this.scrollDiv.style.height=scrHt+'px';
1027 this.innerDiv.style.width=(this.scrWi)+'px';
1028 this.scrollTab.style.width=(this.scrWi-this.options.scrollBarWidth)+'px';
1029 //this.resizeDiv.style.height=this.frozenTabs.style.height=this.innerDiv.style.height=(this.hdrHt+this.dataHt+1)+'px';
1030 this.resizeDiv.style.height=(this.hdrHt+this.dataHt+1)+'px';
1031 Rico.log('sizeDivs scrHt='+scrHt+' innerHt='+this.innerDiv.style.height+' rowHt='+this.rowHeight+' pageSize='+this.pageSize);
1032 var pad=(this.scrWi-this.scrTabWi < this.options.scrollBarWidth) ? 2 : 0;
1033 this.shadowDiv.style.width=(this.scrTabWi+pad)+'px';
1034 this.outerDiv.style.height=(this.hdrHt+scrHt)+'px';
1035 this.setHorizontalScroll();
1038 setHorizontalScroll: function() {
1039 var newLeft=(-this.scrollDiv.scrollLeft)+'px';
1040 this.tabs[1].style.marginLeft=newLeft;
1041 this.tabs[2].style.marginLeft=newLeft;
1044 remainingHt: function() {
1045 var tabHt=this.outerDiv.offsetHeight;
1046 var winHt=Rico.windowHeight();
1047 var margin=Rico.isIE ? 15 : 10;
1048 // if there is a horizontal scrollbar take it into account
1049 if (!Rico.isIE && window.frameElement && window.frameElement.scrolling=='yes' && this.sizeTo!='parent') margin+=this.options.scrollBarWidth;
1050 switch (this.sizeTo) {
1052 var divTop=Rico.cumulativeOffset(this.outerDiv).top;
1053 Rico.log("remainingHt/window, winHt="+winHt+' tabHt='+tabHt+' gridY='+divTop);
1054 return winHt-divTop-tabHt-margin; // allow for scrollbar and some margin
1056 var offset=this.offsetFromParent(this.outerDiv);
1057 if (Rico.isIE) Rico.hide(this.outerDiv);
1058 var parentHt=this.outerDiv.parentNode.clientHeight;
1059 if (Rico.isIE) Rico.show(this.outerDiv);
1060 Rico.log("remainingHt/parent, parentHt="+parentHt+' offset='+offset+' tabHt='+tabHt);
1061 return parentHt-tabHt-offset-margin;
1064 var bodyHt=Rico.isIE ? document.body.scrollHeight : document.body.offsetHeight;
1065 //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);
1066 var remHt=winHt-bodyHt-margin;
1067 if (!Rico.isWebKit) remHt-=this.options.scrollBarWidth;
1068 Rico.log("remainingHt, winHt="+winHt+' pageHt='+bodyHt+' remHt='+remHt);
1071 Rico.log("remainingHt, winHt="+winHt+' tabHt='+tabHt);
1072 if (this.sizeTo.slice(-1)=='%') winHt*=parseFloat(this.sizeTo)/100.0;
1073 else if (this.sizeTo.slice(-2)=='px') winHt=parseInt(this.sizeTo,10);
1074 return winHt-tabHt-margin; // allow for scrollbar and some margin
1078 offsetFromParent: function(element) {
1080 var elParent=element.parentNode;
1082 //Rico.log("offsetFromParent: "+element.tagName+' id='+element.id+' otop='+element.offsetTop);
1083 valueT += element.offsetTop || 0;
1084 element = element.offsetParent;
1085 if (!element || element==null) break;
1086 var p = Rico.getStyle(element, 'position');
1087 if (element.tagName=='BODY' || element.tagName=='HTML' || p=='absolute') return valueT-elParent.offsetTop;
1088 } while (element != elParent);
1092 adjustPageSize: function() {
1093 var remHt=this.remainingHt();
1094 Rico.log('adjustPageSize remHt='+remHt+' lastRow='+this.lastRowPos);
1095 if (remHt > this.rowHeight)
1096 this.autoAppendRows(remHt);
1097 else if (remHt < 0 || this.sizeTo=='data')
1098 this.autoRemoveRows(-remHt);
1101 setPageSize: function(newRowCount) {
1102 newRowCount=Math.min(newRowCount,this.options.maxPageRows);
1103 newRowCount=Math.max(newRowCount,this.options.minPageRows);
1104 this.sizeTo='fixed';
1105 var oldSize=this.pageSize;
1106 while (this.pageSize > newRowCount) {
1109 while (this.pageSize < newRowCount) {
1110 this.appendBlankRow();
1112 this.finishResize(oldSize);
1115 pluginWindowResize: function() {
1116 Rico.log("pluginWindowResize");
1117 this.resizeWindowHandler=Rico.eventHandle(this,'resizeWindow');
1118 Rico.eventBind(window, "resize", this.resizeWindowHandler, false);
1121 unplugWindowResize: function() {
1122 if (!this.resizeWindowHandler) return;
1123 Rico.eventUnbind(window,"resize", this.resizeWindowHandler, false);
1124 this.resizeWindowHandler=null;
1127 resizeWindow: function() {
1128 Rico.log('resizeWindow '+this.tableId+' lastRow='+this.lastRowPos);
1129 if (this.resizeState=='finish') {
1130 Rico.log('resizeWindow postponed');
1131 this.resizeState='resize';
1134 if (!this.sizeTo || this.sizeTo=='fixed') {
1138 if (this.sizeTo=='parent' && Rico.getStyle(this.outerDiv.parentNode,'display') == 'none') return;
1139 var oldSize=this.pageSize;
1140 this.adjustPageSize();
1141 this.finishResize(oldSize);
1144 finishResize: function(oldSize) {
1145 if (this.pageSize > oldSize && this.buffer.totalRows>0) {
1146 this.isPartialBlank=true;
1147 var adjStart=this.adjustRow(this.lastRowPos);
1148 this.buffer.fetch(adjStart);
1149 } else if (this.pageSize < oldSize) {
1150 if (this.options.onRefreshComplete) this.options.onRefreshComplete(this.contentStartPos,this.contentStartPos+this.pageSize-1); // update bookmark
1152 this.resizeState='finish';
1153 Rico.runLater(20,this,'finishResize2');
1154 Rico.log('Resize '+this.tableId+' complete. old size='+oldSize+' new size='+this.pageSize);
1157 finishResize2: function() {
1159 this.updateHeightDiv();
1160 if (this.resizeState=='resize') {
1161 this.resizeWindow();
1163 this.resizeState='';
1167 topOfLastPage: function() {
1168 return Math.max(this.buffer.totalRows-this.pageSize,0);
1171 updateHeightDiv: function() {
1172 var notdisp=this.topOfLastPage();
1173 var ht = notdisp ? this.scrollDiv.clientHeight + Math.floor(this.rowHeight * (notdisp + 0.4)) : 1;
1174 Rico.log("updateHeightDiv, ht="+ht+' scrollDiv.clientHeight='+this.scrollDiv.clientHeight+' rowsNotDisplayed='+notdisp);
1175 this.shadowDiv.style.height=ht+'px';
1178 autoRemoveRows: function(overage) {
1179 if (!this.rowHeight) return;
1180 var removeCnt=Math.ceil(overage / this.rowHeight);
1181 if (this.sizeTo=='data')
1182 removeCnt=Math.max(removeCnt,this.pageSize-this.buffer.totalRows);
1183 Rico.log("autoRemoveRows overage="+overage+" removeCnt="+removeCnt);
1184 for (var i=0; i<removeCnt; i++)
1188 removeRow: function() {
1189 if (this.pageSize <= this.options.minPageRows) return;
1191 for( var c=0; c < this.headerColCnt; c++ ) {
1192 var cell=this.columns[c].cell(this.pageSize);
1193 this.columns[c].dataColDiv.removeChild(cell);
1197 autoAppendRows: function(overage) {
1198 if (!this.rowHeight) return;
1199 var addCnt=Math.floor(overage / this.rowHeight);
1200 Rico.log("autoAppendRows overage="+overage+" cnt="+addCnt+" rowHt="+this.rowHeight);
1201 for (var i=0; i<addCnt; i++) {
1202 if (this.sizeTo=='data' && this.pageSize>=this.buffer.totalRows) break;
1203 this.appendBlankRow();
1208 * on older systems, this can be fairly slow
1210 appendBlankRow: function() {
1211 if (this.pageSize >= this.options.maxPageRows) return;
1212 Rico.log("appendBlankRow #"+this.pageSize);
1213 var cls=this.defaultRowClass(this.pageSize);
1214 for( var c=0; c < this.headerColCnt; c++ ) {
1215 var newdiv = document.createElement("div");
1216 newdiv.className = 'ricoLG_cell '+cls;
1217 newdiv.id=this.tableId+'_'+this.pageSize+'_'+c;
1218 this.columns[c].dataColDiv.appendChild(newdiv);
1219 if (this.columns[c].format.canDrag && Rico.registerDraggable)
1220 Rico.registerDraggable( new Rico.LiveGridDraggable(this, this.pageSize, c), this.options.dndMgrIdx );
1221 newdiv.innerHTML=' '; // this seems to be required by IE
1222 if (this.columns[c]._create) {
1223 this.columns[c]._create(newdiv,this.pageSize);
1229 defaultRowClass: function(rownum) {
1231 if (rownum % 2==0) {
1232 cls='ricoLG_evenRow';
1233 //if (Rico.theme.primary) cls+=' '+Rico.theme.primary;
1235 cls='ricoLG_oddRow';
1236 //if (Rico.theme.secondary) cls+=' '+Rico.theme.secondary;
1241 handleMenuClick: function(e) {
1242 if (!this.menu) return;
1244 this.unhighlight(); // in case highlighting was invoked externally
1246 var cell=Rico.eventElement(e);
1247 if (cell.className=='ricoLG_highlightDiv') {
1248 idx=this.highlightIdx;
1250 cell=Rico.getParentByTagName(cell,'div','ricoLG_cell');
1252 idx=this.winCellIndex(cell);
1253 if ((this.options.highlightSection & (idx.tabIdx+1))==0) return;
1255 this.highlight(idx);
1256 this.highlightEnabled=false;
1257 if (this.hideScroll) this.scrollDiv.style.overflow="hidden";
1259 if (!this.menu.div) this.menu.createDiv();
1260 this.menu.liveGrid=this;
1261 if (this.menu.buildGridMenu) {
1262 var showMenu=this.menu.buildGridMenu(idx.row, idx.column, idx.tabIdx);
1263 if (!showMenu) return;
1265 if (this.options.highlightElem=='selection' && !this.isSelected(idx.cell)) {
1266 this.selectCell(idx.cell);
1269 this.menu.showmenu(e,function() { self.closeMenu(); });
1273 closeMenu: function() {
1274 if (!this.menuIdx) return;
1275 if (this.hideScroll) this.scrollDiv.style.overflow="";
1276 //this.unhighlight();
1277 this.highlightEnabled=true;
1282 * @return index of cell within the window
1284 winCellIndex: function(cell) {
1285 var l=cell.id.lastIndexOf('_',cell.id.length);
1286 var l2=cell.id.lastIndexOf('_',l-1)+1;
1287 var c=parseInt(cell.id.substr(l+1));
1288 var r=parseInt(cell.id.substr(l2,l));
1289 return {row:r, column:c, tabIdx:this.columns[c].tabIdx, cell:cell};
1293 * @return index of cell within the dataset
1295 datasetIndex: function(cell) {
1296 var idx=this.winCellIndex(cell);
1297 idx.row+=this.buffer.windowPos;
1298 idx.onBlankRow=(idx.row >= this.buffer.endPos());
1302 attachHighlightEvents: function(tBody) {
1303 switch (this.options.highlightElem) {
1305 Rico.eventBind(tBody,"mousedown", this.options.mouseDownHandler, false);
1307 tBody.ondrag = function () { return false; };
1309 tBody.onselectstart = function () { return false; };
1313 Rico.eventBind(tBody,"mouseover", this.options.rowOverHandler, false);
1318 detachHighlightEvents: function(tBody) {
1319 switch (this.options.highlightElem) {
1321 Rico.eventUnbind(tBody,"mousedown", this.options.mouseDownHandler, false);
1322 tBody.ondrag = null;
1323 tBody.onselectstart = null;
1327 Rico.eventUnbind(tBody,"mouseover", this.options.rowOverHandler, false);
1333 * @return array of objects containing row/col indexes (index values are relative to the start of the window)
1335 getVisibleSelection: function() {
1337 if (this.SelectIdxStart && this.SelectIdxEnd) {
1338 var r1=Math.max(Math.min(this.SelectIdxEnd.row,this.SelectIdxStart.row)-this.buffer.startPos,this.buffer.windowStart);
1339 var r2=Math.min(Math.max(this.SelectIdxEnd.row,this.SelectIdxStart.row)-this.buffer.startPos,this.buffer.windowEnd-1);
1340 var c1=Math.min(this.SelectIdxEnd.column,this.SelectIdxStart.column);
1341 var c2=Math.max(this.SelectIdxEnd.column,this.SelectIdxStart.column);
1342 //Rico.log("getVisibleSelection "+r1+','+c1+' to '+r2+','+c2+' ('+this.SelectIdxStart.row+',startPos='+this.buffer.startPos+',windowPos='+this.buffer.windowPos+',windowEnd='+this.buffer.windowEnd+')');
1343 for (var r=r1; r<=r2; r++) {
1344 for (var c=c1; c<=c2; c++)
1345 cellList.push({row:r-this.buffer.windowStart,column:c});
1348 if (this.SelectCtrl) {
1349 for (var i=0; i<this.SelectCtrl.length; i++) {
1350 if (this.SelectCtrl[i].row>=this.buffer.windowStart && this.SelectCtrl[i].row<this.buffer.windowEnd)
1351 cellList.push({row:this.SelectCtrl[i].row-this.buffer.windowStart,column:this.SelectCtrl[i].column});
1357 updateSelectOutline: function() {
1358 if (!this.SelectIdxStart || !this.SelectIdxEnd) return;
1359 var r1=Math.max(Math.min(this.SelectIdxEnd.row,this.SelectIdxStart.row), this.buffer.windowStart);
1360 var r2=Math.min(Math.max(this.SelectIdxEnd.row,this.SelectIdxStart.row), this.buffer.windowEnd-1);
1362 this.HideSelection();
1365 var c1=Math.min(this.SelectIdxEnd.column,this.SelectIdxStart.column);
1366 var c2=Math.max(this.SelectIdxEnd.column,this.SelectIdxStart.column);
1367 var top1=this.columns[c1].cell(r1-this.buffer.windowStart).offsetTop;
1368 var cell2=this.columns[c1].cell(r2-this.buffer.windowStart);
1369 var bottom2=cell2.offsetTop+cell2.offsetHeight;
1370 var left1=this.columns[c1].dataCell.offsetLeft;
1371 var left2=this.columns[c2].dataCell.offsetLeft;
1372 var right2=left2+this.columns[c2].dataCell.offsetWidth;
1373 //window.status='updateSelectOutline: '+r1+' '+r2+' top='+top1+' bot='+bottom2;
1374 this.highlightDiv[0].style.top=this.highlightDiv[3].style.top=this.highlightDiv[1].style.top=(this.hdrHt+top1-1) + 'px';
1375 this.highlightDiv[2].style.top=(this.hdrHt+bottom2-1)+'px';
1376 this.highlightDiv[3].style.left=(left1-2)+'px';
1377 this.highlightDiv[0].style.left=this.highlightDiv[2].style.left=(left1-1)+'px';
1378 this.highlightDiv[1].style.left=(right2-1)+'px';
1379 this.highlightDiv[0].style.width=this.highlightDiv[2].style.width=(right2-left1-1) + 'px';
1380 this.highlightDiv[1].style.height=this.highlightDiv[3].style.height=(bottom2-top1) + 'px';
1381 //this.highlightDiv[0].style.right=this.highlightDiv[2].style.right=this.highlightDiv[1].style.right=()+'px';
1382 //this.highlightDiv[2].style.bottom=this.highlightDiv[3].style.bottom=this.highlightDiv[1].style.bottom=(this.hdrHt+bottom2) + 'px';
1383 for (var i=0; i<4; i++)
1384 this.highlightDiv[i].style.display='';
1387 HideSelection: function() {
1389 if (this.options.highlightMethod!='class') {
1390 for (i=0; i<this.highlightDiv.length; i++)
1391 this.highlightDiv[i].style.display='none';
1393 if (this.options.highlightMethod!='outline') {
1394 var cellList=this.getVisibleSelection();
1395 Rico.log("HideSelection "+cellList.length);
1396 for (i=0; i<cellList.length; i++)
1397 this.unhighlightCell(this.columns[cellList[i].column].cell(cellList[i].row));
1401 ShowSelection: function() {
1402 if (this.options.highlightMethod!='class')
1403 this.updateSelectOutline();
1404 if (this.options.highlightMethod!='outline') {
1405 var cellList=this.getVisibleSelection();
1406 for (var i=0; i<cellList.length; i++)
1407 this.highlightCell(this.columns[cellList[i].column].cell(cellList[i].row));
1411 ClearSelection: function() {
1412 Rico.log("ClearSelection");
1413 this.HideSelection();
1414 this.SelectIdxStart=null;
1415 this.SelectIdxEnd=null;
1419 selectCell: function(cell) {
1420 this.ClearSelection();
1421 this.SelectIdxStart=this.SelectIdxEnd=this.datasetIndex(cell);
1422 this.ShowSelection();
1425 AdjustSelection: function(cell) {
1426 var newIdx=this.datasetIndex(cell);
1427 if (this.SelectIdxStart.tabIdx != newIdx.tabIdx) return;
1428 this.HideSelection();
1429 this.SelectIdxEnd=newIdx;
1430 this.ShowSelection();
1433 RefreshSelection: function() {
1434 var cellList=this.getVisibleSelection();
1435 for (var i=0; i<cellList.length; i++) {
1436 this.columns[cellList[i].column].displayValue(cellList[i].row);
1440 FillSelection: function(newVal,newStyle) {
1441 if (this.SelectIdxStart && this.SelectIdxEnd) {
1442 var r1=Math.min(this.SelectIdxEnd.row,this.SelectIdxStart.row);
1443 var r2=Math.max(this.SelectIdxEnd.row,this.SelectIdxStart.row);
1444 var c1=Math.min(this.SelectIdxEnd.column,this.SelectIdxStart.column);
1445 var c2=Math.max(this.SelectIdxEnd.column,this.SelectIdxStart.column);
1446 for (var r=r1; r<=r2; r++) {
1447 for (var c=c1; c<=c2; c++) {
1448 this.buffer.setValue(r,c,newVal,newStyle);
1452 if (this.SelectCtrl) {
1453 for (var i=0; i<this.SelectCtrl.length; i++) {
1454 this.buffer.setValue(this.SelectCtrl[i].row,this.SelectCtrl[i].column,newVal,newStyle);
1457 this.RefreshSelection();
1461 * Process mouse down event
1462 * @param e event object
1464 selectMouseDown: function(e) {
1465 if (this.highlightEnabled==false) return true;
1467 var cell=Rico.eventElement(e);
1468 if (!Rico.eventLeftClick(e)) return true;
1469 cell=Rico.getParentByTagName(cell,'div','ricoLG_cell');
1470 if (!cell) return true;
1472 var newIdx=this.datasetIndex(cell);
1473 if (newIdx.onBlankRow) return true;
1474 Rico.log("selectMouseDown @"+newIdx.row+','+newIdx.column);
1476 if (!this.SelectIdxStart || this.options.highlightMethod!='class') return true;
1477 if (!this.isSelected(cell)) {
1478 this.highlightCell(cell);
1479 this.SelectCtrl.push(this.datasetIndex(cell));
1481 for (var i=0; i<this.SelectCtrl.length; i++) {
1482 if (this.SelectCtrl[i].row==newIdx.row && this.SelectCtrl[i].column==newIdx.column) {
1483 this.unhighlightCell(cell);
1484 this.SelectCtrl.splice(i,1);
1489 } else if (e.shiftKey) {
1490 if (!this.SelectIdxStart) return true;
1491 this.AdjustSelection(cell);
1493 this.selectCell(cell);
1494 this.pluginSelect();
1499 pluginSelect: function() {
1500 if (this.selectPluggedIn) return;
1501 var tBody=this.tbody[this.SelectIdxStart.tabIdx];
1502 Rico.eventBind(tBody,"mouseover", this.options.mouseOverHandler, false);
1503 Rico.eventBind(this.outerDiv,"mouseup", this.options.mouseUpHandler, false);
1504 this.selectPluggedIn=true;
1507 unplugSelect: function() {
1508 if (!this.selectPluggedIn) return;
1509 var tBody=this.tbody[this.SelectIdxStart.tabIdx];
1510 Rico.eventUnbind(tBody,"mouseover", this.options.mouseOverHandler , false);
1511 Rico.eventUnbind(this.outerDiv,"mouseup", this.options.mouseUpHandler , false);
1512 this.selectPluggedIn=false;
1515 selectMouseUp: function(e) {
1516 this.unplugSelect();
1517 var cell=Rico.eventElement(e);
1518 cell=Rico.getParentByTagName(cell,'div','ricoLG_cell');
1520 if (this.SelectIdxStart && this.SelectIdxEnd)
1521 this.AdjustSelection(cell);
1523 this.ClearSelection();
1526 selectMouseOver: function(e) {
1527 var cell=Rico.eventElement(e);
1528 cell=Rico.getParentByTagName(cell,'div','ricoLG_cell');
1530 this.AdjustSelection(cell);
1534 isSelected: function(cell) {
1535 if (this.options.highlightMethod!='outline') return Rico.hasClass(cell,this.options.highlightClass);
1536 if (!this.SelectIdxStart || !this.SelectIdxEnd) return false;
1537 var r1=Math.max(Math.min(this.SelectIdxEnd.row,this.SelectIdxStart.row), this.buffer.windowStart);
1538 var r2=Math.min(Math.max(this.SelectIdxEnd.row,this.SelectIdxStart.row), this.buffer.windowEnd-1);
1539 if (r1 > r2) return false;
1540 var c1=Math.min(this.SelectIdxEnd.column,this.SelectIdxStart.column);
1541 var c2=Math.max(this.SelectIdxEnd.column,this.SelectIdxStart.column);
1542 var curIdx=this.datasetIndex(cell);
1543 return (r1<=curIdx.row && curIdx.row<=r2 && c1<=curIdx.column && curIdx.column<=c2);
1546 highlightCell: function(cell) {
1547 Rico.addClass(cell,this.options.highlightClass);
1550 unhighlightCell: function(cell) {
1551 if (cell) Rico.removeClass(cell,this.options.highlightClass);
1554 selectRow: function(r) {
1555 for (var c=0; c<this.columns.length; c++)
1556 this.highlightCell(this.columns[c].cell(r));
1559 unselectRow: function(r) {
1560 for (var c=0; c<this.columns.length; c++)
1561 this.unhighlightCell(this.columns[c].cell(r));
1564 rowMouseOver: function(e) {
1565 if (!this.highlightEnabled) return;
1566 var cell=Rico.eventElement(e);
1567 cell=Rico.getParentByTagName(cell,'div','ricoLG_cell');
1569 var newIdx=this.winCellIndex(cell);
1570 if ((this.options.highlightSection & (newIdx.tabIdx+1))==0) return;
1571 this.highlight(newIdx);
1574 highlight: function(newIdx) {
1575 if (this.options.highlightMethod!='outline') this.cursorSetClass(newIdx);
1576 if (this.options.highlightMethod!='class') this.cursorOutline(newIdx);
1577 this.highlightIdx=newIdx;
1580 cursorSetClass: function(newIdx) {
1581 switch (this.options.highlightElem) {
1584 if (this.highlightIdx) this.unhighlightCell(this.highlightIdx.cell);
1585 this.highlightCell(newIdx.cell);
1589 if (this.highlightIdx) this.unselectRow(this.highlightIdx.row);
1590 var s1=this.options.highlightSection & 1;
1591 var s2=this.options.highlightSection & 2;
1592 var c0=s1 ? 0 : this.options.frozenColumns;
1593 var c1=s2 ? this.columns.length : this.options.frozenColumns;
1594 for (var c=c0; c<c1; c++)
1595 this.highlightCell(this.columns[c].cell(newIdx.row));
1601 cursorOutline: function(newIdx) {
1603 switch (this.options.highlightElem) {
1606 div=this.highlightDiv[newIdx.tabIdx];
1607 div.style.left=(this.columns[newIdx.column].dataCell.offsetLeft-1)+'px';
1608 div.style.width=this.columns[newIdx.column].colWidth;
1609 this.highlightDiv[1-newIdx.tabIdx].style.display='none';
1613 div=this.highlightDiv[0];
1614 var s1=this.options.highlightSection & 1;
1615 var s2=this.options.highlightSection & 2;
1616 div.style.left=s1 ? '0px' : this.frozenTabs.style.width;
1617 div.style.width=((s1 ? this.frozenTabs.offsetWidth : 0) + (s2 ? this.innerDiv.offsetWidth : 0) - 4)+'px';
1621 div.style.top=(this.hdrHt+newIdx.row*this.rowHeight-1)+'px';
1622 div.style.height=(this.rowHeight-1)+'px';
1623 div.style.display='';
1626 unhighlight: function() {
1627 switch (this.options.highlightElem) {
1629 //this.highlightIdx=this.menuIdx;
1632 if (this.highlightIdx) this.unhighlightCell(this.highlightIdx.cell);
1633 if (!this.highlightDiv) return;
1634 for (var i=0; i<2; i++)
1635 this.highlightDiv[i].style.display='none';
1638 //this.highlightIdx=this.menuIdx;
1641 if (this.highlightIdx) this.unselectRow(this.highlightIdx.row);
1642 if (this.highlightDiv) this.highlightDiv[0].style.display='none';
1647 resetContents: function() {
1648 Rico.log("resetContents");
1649 this.ClearSelection();
1650 this.buffer.clear();
1652 this.clearBookmark();
1655 setImages: function() {
1656 for (var n=0; n<this.columns.length; n++)
1657 this.columns[n].setImage();
1661 * @return column index, or -1 if there are no sorted columns
1663 findSortedColumn: function() {
1664 for (var n=0; n<this.columns.length; n++) {
1665 if (this.columns[n].isSorted()) return n;
1671 * Searches options.columnSpecs colAttr for matching colValue
1672 * @return array of matching column indexes
1674 findColumnsBySpec: function(colAttr, colValue) {
1676 for (var n=0; n<this.options.columnSpecs.length; n++) {
1677 if (this.options.columnSpecs[n][colAttr] == colValue) result.push(n);
1685 setSortUI: function( columnIdOrNum, sortDirection ) {
1686 Rico.log("setSortUI: "+columnIdOrNum+' '+sortDirection);
1687 var colnum=this.findSortedColumn();
1689 sortDirection=this.columns[colnum].getSortDirection();
1691 if (typeof sortDirection!='string') {
1692 sortDirection=Rico.ColumnConst.SORT_ASC;
1694 sortDirection=sortDirection.toUpperCase();
1695 if (sortDirection != Rico.ColumnConst.SORT_DESC) sortDirection=Rico.ColumnConst.SORT_ASC;
1697 switch (typeof columnIdOrNum) {
1699 colnum=this.findColumnsBySpec('id',columnIdOrNum);
1702 colnum=columnIdOrNum;
1706 if (typeof(colnum)!='number' || colnum < 0) return;
1708 this.columns[colnum].setSorted(sortDirection);
1709 this.buffer.sortBuffer(colnum);
1713 * clear sort flag on all columns
1715 clearSort: function() {
1716 for (var x=0;x<this.columns.length;x++)
1717 this.columns[x].setUnsorted();
1721 * clear filters on all columns
1723 clearFilters: function() {
1724 for (var x=0;x<this.columns.length;x++) {
1725 this.columns[x].setUnfiltered(true);
1727 if (this.options.filterHandler) {
1728 this.options.filterHandler();
1733 * returns number of columns with a user filter set
1735 filterCount: function() {
1736 for (var x=0,cnt=0;x<this.columns.length;x++) {
1737 if (this.columns[x].isFiltered()) cnt++;
1742 sortHandler: function() {
1744 this.ClearSelection();
1746 var n=this.findSortedColumn();
1748 Rico.log("sortHandler: sorting column "+n);
1749 this.buffer.sortBuffer(n);
1751 this.scrollDiv.scrollTop = 0;
1752 this.buffer.fetch(0);
1755 filterHandler: function() {
1756 Rico.log("filterHandler");
1758 if (this.buffer.processingRequest) {
1759 this.queueFilter=true;
1762 this.unplugScroll();
1763 this.ClearSelection();
1765 this.clearBookmark();
1767 this.buffer.fetch(-1);
1768 Rico.runLater(10,this,'pluginScroll'); // resetting ht div can cause a scroll event, triggering an extra fetch
1771 clearBookmark: function() {
1772 if (this.bookmark) this.bookmark.innerHTML=" ";
1775 bookmarkHandler: function(firstrow,lastrow) {
1777 if (isNaN(firstrow) || !this.bookmark) return;
1778 var totrows=this.buffer.totalRows;
1779 if (totrows < lastrow) lastrow=totrows;
1781 newhtml = Rico.getPhraseById('bookmarkNoMatch');
1782 } else if (lastrow<0) {
1783 newhtml = Rico.getPhraseById('bookmarkNoRec');
1784 } else if (this.buffer.foundRowCount) {
1785 newhtml = Rico.getPhraseById('bookmarkExact',firstrow,lastrow,totrows);
1787 newhtml = Rico.getPhraseById('bookmarkAbout',firstrow,lastrow,totrows);
1789 this.bookmark.innerHTML = newhtml;
1792 clearRows: function() {
1793 if (this.isBlank==true) return;
1794 for (var c=0; c < this.columns.length; c++)
1795 this.columns[c].clearColumn();
1796 this.isBlank = true;
1799 refreshContents: function(startPos) {
1800 Rico.log("refreshContents1 "+this.tableId+": startPos="+startPos+" lastRow="+this.lastRowPos+" PartBlank="+this.isPartialBlank+" pageSize="+this.pageSize);
1803 this.unhighlight(); // in case highlighting was manually invoked
1804 if (this.queueFilter) {
1805 Rico.log("refreshContents: cancelling refresh because filter has changed");
1806 this.queueFilter=false;
1807 this.filterHandler();
1810 this.highlightEnabled=this.options.highlightSection!='none';
1811 var viewPrecedesBuffer = this.buffer.startPos > startPos;
1812 var contentStartPos = viewPrecedesBuffer ? this.buffer.startPos: startPos;
1813 this.contentStartPos = contentStartPos+1;
1814 var contentEndPos = Math.min(this.buffer.startPos + this.buffer.size, startPos + this.pageSize);
1815 this.buffer.setWindow(contentStartPos, contentEndPos);
1816 Rico.log('refreshContents2 '+this.tableId+': cStartPos='+contentStartPos+' cEndPos='+contentEndPos+' vPrecedesBuf='+viewPrecedesBuffer+' b.startPos='+this.buffer.startPos);
1817 if (startPos == this.lastRowPos && !this.isPartialBlank && !this.isBlank) return;
1818 this.isBlank = false;
1819 var onRefreshComplete = this.options.onRefreshComplete;
1821 if ((startPos + this.pageSize < this.buffer.startPos) ||
1822 (this.buffer.startPos + this.buffer.size < startPos) ||
1823 (this.buffer.size == 0)) {
1825 if (onRefreshComplete) onRefreshComplete(this.contentStartPos,contentEndPos); // update bookmark
1829 Rico.log('refreshContents: contentStartPos='+contentStartPos+' contentEndPos='+contentEndPos+' viewPrecedesBuffer='+viewPrecedesBuffer);
1830 var rowSize = contentEndPos - contentStartPos;
1831 var blankSize = this.pageSize - rowSize;
1832 var blankOffset = viewPrecedesBuffer ? 0: rowSize;
1833 var contentOffset = viewPrecedesBuffer ? blankSize: 0;
1835 for (var r=0; r < rowSize; r++) { //initialize what we have
1836 for (var c=0; c < this.columns.length; c++)
1837 this.columns[c].displayValue(r + contentOffset);
1839 for (var i=0; i < blankSize; i++) // blank out the rest
1840 this.blankRow(i + blankOffset);
1841 if (this.options.highlightElem=='selection') this.ShowSelection();
1842 this.isPartialBlank = blankSize > 0;
1843 this.lastRowPos = startPos;
1844 Rico.log("refreshContents complete, startPos="+startPos);
1845 if (onRefreshComplete) onRefreshComplete(this.contentStartPos,contentEndPos); // update bookmark
1848 scrollToRow: function(rowOffset) {
1849 var p=this.rowToPixel(rowOffset);
1850 Rico.log("scrollToRow, rowOffset="+rowOffset+" pixel="+p);
1851 this.scrollDiv.scrollTop = p; // this causes a scroll event
1852 if ( this.options.onscroll )
1853 this.options.onscroll( this, rowOffset );
1856 scrollUp: function() {
1857 this.moveRelative(-1);
1860 scrollDown: function() {
1861 this.moveRelative(1);
1864 pageUp: function() {
1865 this.moveRelative(-this.pageSize);
1868 pageDown: function() {
1869 this.moveRelative(this.pageSize);
1872 adjustRow: function(rowOffset) {
1873 var notdisp=this.topOfLastPage();
1874 if (notdisp == 0 || !rowOffset) return 0;
1875 return Math.min(notdisp,rowOffset);
1878 rowToPixel: function(rowOffset) {
1879 return this.adjustRow(rowOffset) * this.rowHeight;
1883 * @returns row to display at top of scroll div
1885 pixeltorow: function(p) {
1886 var notdisp=this.topOfLastPage();
1887 if (notdisp == 0) return 0;
1888 var prow=parseInt(p/this.rowHeight,10);
1889 return Math.min(notdisp,prow);
1892 moveRelative: function(relOffset) {
1893 var newoffset=Math.max(this.scrollDiv.scrollTop+relOffset*this.rowHeight,0);
1894 newoffset=Math.min(newoffset,this.scrollDiv.scrollHeight);
1895 //Rico.log("moveRelative, newoffset="+newoffset);
1896 this.scrollDiv.scrollTop=newoffset;
1899 pluginScroll: function() {
1900 if (this.scrollPluggedIn) return;
1901 Rico.log("pluginScroll: wheelEvent="+this.wheelEvent);
1902 Rico.eventBind(this.scrollDiv,"scroll",this.scrollEventFunc, false);
1903 for (var t=0; t<2; t++)
1904 Rico.eventBind(this.tabs[t],this.wheelEvent,this.wheelEventFunc, false);
1905 this.scrollPluggedIn=true;
1908 unplugScroll: function() {
1909 if (!this.scrollPluggedIn) return;
1910 Rico.log("unplugScroll");
1911 Rico.eventUnbind(this.scrollDiv,"scroll", this.scrollEventFunc , false);
1912 for (var t=0; t<2; t++)
1913 Rico.eventUnbind(this.tabs[t],this.wheelEvent,this.wheelEventFunc, false);
1914 this.scrollPluggedIn=false;
1917 handleWheel: function(e) {
1921 delta = e.wheelDelta/120;
1922 else if (Rico.isWebKit)
1923 delta = -e.wheelDelta/12;
1925 delta = -e.wheelDelta/120;
1926 } else if (e.detail) {
1927 delta = e.detail/3; /* Mozilla/Gecko */
1929 if (delta) this.moveRelative(delta);
1934 handleScroll: function(e) {
1935 if ( this.scrollTimeout )
1936 clearTimeout( this.scrollTimeout );
1937 this.setHorizontalScroll();
1938 var scrtop=this.scrollDiv.scrollTop;
1939 var vscrollDiff = this.lastScrollPos-scrtop;
1940 if (vscrollDiff == 0.00) return;
1941 var newrow=this.pixeltorow(scrtop);
1942 if (newrow == this.lastRowPos && !this.isPartialBlank && !this.isBlank) return;
1943 var stamp1 = new Date();
1944 Rico.log("handleScroll, newrow="+newrow+" scrtop="+scrtop);
1945 if (this.options.highlightElem=='selection') this.HideSelection();
1946 this.buffer.fetch(newrow);
1947 if (this.options.onscroll) this.options.onscroll(this, newrow);
1948 this.scrollTimeout = Rico.runLater(1200,this,'scrollIdle');
1949 this.lastScrollPos = this.scrollDiv.scrollTop;
1950 var stamp2 = new Date();
1951 //Rico.log("handleScroll, time="+(stamp2.getTime()-stamp1.getTime()));
1954 scrollIdle: function() {
1955 if ( this.options.onscrollidle )
1956 this.options.onscrollidle();
1962 Rico.LiveGridColumn = function(grid,colIdx,hdrInfo,tabIdx) {
1963 this.initialize(grid,colIdx,hdrInfo,tabIdx);
1966 Rico.LiveGridColumn.prototype =
1967 /** @lends Rico.LiveGridColumn# */
1970 * Implements a LiveGrid column. Also contains static properties used by SimpleGrid columns.
1971 * @extends Rico.TableColumnBase
1974 initialize: function(liveGrid,colIdx,hdrInfo,tabIdx) {
1975 Rico.extend(this, new Rico.TableColumnBase());
1976 this.baseInit(liveGrid,colIdx,hdrInfo,tabIdx);
1977 this.buffer=liveGrid.buffer;
1978 if (typeof(this.format.type)!='string' || this.format.EntryType=='tinyMCE') this.format.type='html';
1979 if (typeof this.isNullable!='boolean') this.isNullable = /number|date/.test(this.format.type);
1980 this.isText = /html|text/.test(this.format.type);
1981 Rico.log(" sortable="+this.sortable+" filterable="+this.filterable+" hideable="+this.hideable+" isNullable="+this.isNullable+' isText='+this.isText);
1982 this.fixHeaders(this.liveGrid.tableId, this.options.hdrIconsFirst);
1983 if (this['format_'+this.format.type]) {
1984 this._format=this['format_'+this.format.type];
1986 if (this.format.control) {
1987 // copy all properties/methods that start with '_'
1988 if (typeof this.format.control=='string') {
1989 this.format.control=eval(this.format.control);
1991 for (var property in this.format.control) {
1992 if (property.charAt(0)=='_') {
1993 Rico.log("Copying control property "+property+ ' to ' + this);
1994 this[property] = this.format.control[property];
2001 * Sorts the column in ascending order
2003 sortAsc: function() {
2004 this.setColumnSort(Rico.ColumnConst.SORT_ASC);
2008 * Sorts the column in descending order
2010 sortDesc: function() {
2011 this.setColumnSort(Rico.ColumnConst.SORT_DESC);
2015 * Sorts the column in the specified direction
2016 * @param direction must be one of Rico.ColumnConst.UNSORTED, .SORT_ASC, or .SORT_DESC
2018 setColumnSort: function(direction) {
2019 this.liveGrid.clearSort();
2020 this.setSorted(direction);
2021 if (this.liveGrid.options.saveColumnInfo.sort)
2022 this.liveGrid.setCookie();
2023 if (this.options.sortHandler)
2024 this.options.sortHandler();
2028 * @returns true if this column is allowed to be sorted
2030 isSortable: function() {
2031 return this.sortable;
2035 * @returns true if this column is currently sorted
2037 isSorted: function() {
2038 return this.currentSort != Rico.ColumnConst.UNSORTED;
2042 * @returns Rico.ColumnConst.UNSORTED, .SORT_ASC, or .SORT_DESC
2044 getSortDirection: function() {
2045 return this.currentSort;
2049 * toggle the sort sequence for this column
2051 toggleSort: function() {
2052 if (this.buffer && this.buffer.totalRows==0) return;
2053 if (this.currentSort == Rico.ColumnConst.SORT_ASC)
2060 * Flags that this column is not sorted
2062 setUnsorted: function() {
2063 this.setSorted(Rico.ColumnConst.UNSORTED);
2067 * Flags that this column is sorted, but doesn't actually carry out the sort
2068 * @param direction must be one of Rico.ColumnConst.UNSORTED, .SORT_ASC, or .SORT_DESC
2070 setSorted: function(direction) {
2071 this.currentSort = direction;
2075 * @returns true if this column is allowed to be filtered
2077 canFilter: function() {
2078 return this.filterable;
2082 * @returns a textual representation of how this column is filtered
2084 getFilterText: function() {
2086 for (var i=0; i<this.filterValues.length; i++) {
2087 var v=this.filterValues[i];
2088 vals.push(v=='' ? Rico.getPhraseById('filterBlank') : v);
2090 switch (this.filterOp) {
2091 case 'EQ': return '= '+vals.join(', ');
2092 case 'NE': return Rico.getPhraseById('filterNot',vals.join(', '));
2093 case 'LE': return '<= '+vals[0];
2094 case 'GE': return '>= '+vals[0];
2095 case 'LIKE': return Rico.getPhraseById('filterLike',vals[0]);
2096 case 'NULL': return Rico.getPhraseById('filterEmpty');
2097 case 'NOTNULL': return Rico.getPhraseById('filterNotEmpty');
2103 * @returns returns the query string representation of the filter
2105 getFilterQueryParm: function() {
2106 if (this.filterType == Rico.ColumnConst.UNFILTERED) return '';
2107 var retval='&f['+this.index+'][op]='+this.filterOp;
2108 retval+='&f['+this.index+'][len]='+this.filterValues.length;
2109 for (var i=0; i<this.filterValues.length; i++) {
2110 retval+='&f['+this.index+']['+i+']='+escape(this.filterValues[i]);
2116 * removes the filter from this column
2118 setUnfiltered: function(skipHandler) {
2119 this.filterType = Rico.ColumnConst.UNFILTERED;
2120 if (this.liveGrid.options.saveColumnInfo.filter)
2121 this.liveGrid.setCookie();
2122 if (this.removeFilterFunc)
2123 this.removeFilterFunc();
2124 if (this.options.filterHandler && !skipHandler)
2125 this.options.filterHandler();
2128 setFilterEQ: function() {
2129 this.setUserFilter('EQ');
2131 setFilterNE: function() {
2132 this.setUserFilter('NE');
2134 addFilterNE: function() {
2135 this.filterValues.push(this.userFilter);
2136 if (this.liveGrid.options.saveColumnInfo.filter)
2137 this.liveGrid.setCookie();
2138 if (this.options.filterHandler)
2139 this.options.filterHandler();
2141 setFilterGE: function() { this.setUserFilter('GE'); },
2142 setFilterLE: function() { this.setUserFilter('LE'); },
2143 setFilterKW: function(keyword) {
2144 if (keyword!='' && keyword!=null) {
2145 this.setFilter('LIKE',keyword,Rico.ColumnConst.USERFILTER);
2147 this.setUnfiltered(false);
2151 setUserFilter: function(relop) {
2152 this.setFilter(relop,this.userFilter,Rico.ColumnConst.USERFILTER);
2155 setSystemFilter: function(relop,filter) {
2156 this.setFilter(relop,filter,Rico.ColumnConst.SYSTEMFILTER);
2159 setFilter: function(relop,filter,type,removeFilterFunc) {
2160 this.filterValues = typeof(filter)=='object' ? filter : [filter];
2161 this.filterType = type;
2162 this.filterOp = relop;
2163 if (type == Rico.ColumnConst.USERFILTER && this.liveGrid.options.saveColumnInfo.filter)
2164 this.liveGrid.setCookie();
2165 this.removeFilterFunc=removeFilterFunc;
2166 if (this.options.filterHandler)
2167 this.options.filterHandler();
2170 isFiltered: function() {
2171 return this.filterType == Rico.ColumnConst.USERFILTER;
2174 filterChange: function(e) {
\r
2175 var selbox=Rico.eventElement(e);
2176 if (selbox.value==this.liveGrid.options.FilterAllToken)
\r
2177 this.setUnfiltered();
\r
2179 this.setFilter('EQ',selbox.value,Rico.ColumnConst.USERFILTER,function() {selbox.selectedIndex=0;});
\r
2182 filterClear: function(e) {
\r
2183 this.filterField.value='';
2184 this.setUnfiltered();
\r
2187 filterKeypress: function(e) {
\r
2188 var txtbox=Rico.eventElement(e);
2189 if (typeof this.lastKeyFilter != 'string') this.lastKeyFilter='';
\r
2190 if (this.lastKeyFilter==txtbox.value) return;
\r
2191 var v=txtbox.value;
\r
2192 Rico.log("filterKeypress: "+this.index+' '+v);
\r
2193 this.lastKeyFilter=v;
2194 if (v=='' || v=='*')
\r
2195 this.setUnfiltered();
\r
2197 this.setFilter('LIKE', v, Rico.ColumnConst.USERFILTER, function() {txtbox.value='';});
2201 mFilterSelectClick: function(e) {
2203 if (this.mFilter.style.display!='none') {
2204 this.mFilterFinish(e);
2205 if (Rico.isIE && Rico.ieVersion <= 6) {
2206 this.filterField.focus();
2208 this.filterField.blur();
2211 var offset=Rico.cumulativeOffset(this.filterField);
2212 this.mFilter.style.top=(offset.top+this.filterField.offsetHeight)+'px';
2213 this.mFilter.style.left=offset.left+'px';
2214 this.mFilter.style.width=Math.min(this.filterField.offsetWidth,parseInt(this.colWidth,10))+'px';
2215 Rico.show(this.mFilter);
2216 this.mFilterFocus.focus();
2220 mFilterFinish: function(e) {
2221 if (!this.mFilterChange) {
2222 Rico.hide(this.mFilter);
2225 if (this.mFilterInputs[0].checked) {
2226 this.mFilterReset();
2227 Rico.hide(this.mFilter);
2228 this.setUnfiltered();
2233 for (var i=1; i<this.mFilterInputs.length; i++) {
2234 if (this.mFilterInputs[i].checked) {
2235 newValues.push(this.mFilterInputs[i].value)
2236 newLabels.push(this.mFilterLabels[i].innerHTML)
2239 if (newValues.length > 0) {
2240 var newText=newLabels.join(', ');
2241 this.filterField.options[0].text=newText;
2242 this.filterField.title=newText;
2243 Rico.hide(this.mFilter);
2244 this.mFilterChange=false;
2246 this.setFilter('EQ',newValues,Rico.ColumnConst.USERFILTER,function() { self.mFilterReset(); });
2248 alert('Please select at least one value');
2252 mFilterReset: function() {
2253 var newText=this.mFilterLabels[0].innerHTML; // all
2254 this.filterField.options[0].text=newText;
2255 this.filterField.title=newText;
2258 mFilterAllClick: function(e) {
2259 var allChecked=this.mFilterInputs[0].checked;
2260 for (var i=1; i<this.mFilterInputs.length; i++) {
2261 this.mFilterInputs[i].checked=allChecked;
2263 this.mFilterChange=true;
2266 mFilterOtherClick: function(e) {
2267 this.mFilterInputs[0].checked=false;
2268 this.mFilterChange=true;
2271 format_text: function(v) {
2272 if (typeof v!='string')
2275 return v.replace(/&/g, '&').replace(/</g,'<').replace(/>/g,'>');
2278 format_number: function(v) {
2279 if (typeof v=='undefined' || v=='' || v==null)
2282 return Rico.formatNumber(v,this.format);
2285 format_datetime: function(v) {
2286 if (typeof v=='undefined' || v=='' || v==null)
2289 var d=Rico.setISO8601(v);
2291 return (this.format.prefix || '')+Rico.formatDate(d,this.format.dateFmt || 'translateDateTime')+(this.format.suffix || '');
2295 // converts GMT/UTC to local time
2296 format_utcaslocaltime: function(v) {
2297 if (typeof v=='undefined' || v=='' || v==null)
2301 var d=Rico.setISO8601(v,-tz.getTimezoneOffset());
2303 return (this.format.prefix || '')+Rico.formatDate(d,this.format.dateFmt || 'translateDateTime')+(this.format.suffix || '');
2307 format_date: function(v) {
2308 if (typeof v=='undefined' || v==null || v=='')
2311 var d=Rico.setISO8601(v);
2313 return (this.format.prefix || '')+Rico.formatDate(d,this.format.dateFmt || 'translateDate')+(this.format.suffix || '');
2317 fixHeaders: function(prefix, iconsfirst) {
2318 if (this.sortable) {
2319 var handler=Rico.eventHandle(this,'toggleSort');
2320 switch (this.options.headingSort) {
2322 var a=Rico.wrapChildren(this.hdrCellDiv,'ricoSort',undefined,'a');
2323 a.href = "javascript:void(0)";
2324 Rico.eventBind(a,"click", handler);
2327 Rico.eventBind(this.hdrCellDiv,"click", handler);
2331 this.imgFilter = document.createElement('span');
2332 this.imgFilter.style.display='none';
2333 this.imgFilter.className='rico-icon ricoLG_filterCol';
2334 this.imgSort = document.createElement('span');
2335 this.imgSort.style.display='none';
2336 this.imgSort.style.verticalAlign='top';
2338 this.hdrCellDiv.insertBefore(this.imgSort,this.hdrCellDiv.firstChild);
2339 this.hdrCellDiv.insertBefore(this.imgFilter,this.hdrCellDiv.firstChild);
2341 this.hdrCellDiv.appendChild(this.imgFilter);
2342 this.hdrCellDiv.appendChild(this.imgSort);
2344 if (!this.format.filterUI) {
2345 Rico.eventBind(this.imgFilter, 'click', Rico.eventHandle(this,'filterClick'), false);
2349 filterClick: function(e) {
2350 if (this.filterType==Rico.ColumnConst.USERFILTER && this.filterOp=='LIKE') {
2351 this.liveGrid.openKeyword(this.index);
2355 getValue: function(windowRow) {
2356 return this.buffer.getWindowCell(windowRow,this.index);
2359 getBufferStyle: function(windowRow) {
2360 return this.buffer.getWindowStyle(windowRow,this.index);
2363 setValue: function(windowRow,newval) {
2364 this.buffer.setWindowValue(windowRow,this.index,newval);
2367 _format: function(v) {
2371 _display: function(v,gridCell) {
2372 gridCell.innerHTML=this._format(v);
2375 _export: function(v) {
2376 return this._format(v);
2379 exportBuffer: function(bufRow) {
2380 return this._export(this.buffer.getValue(bufRow,this.index));
2383 displayValue: function(windowRow) {
2384 var bufval=this.getValue(windowRow);
2386 this.clearCell(windowRow);
2389 var gridCell=this.cell(windowRow);
2390 this._display(bufval,gridCell,windowRow);
2391 if (this.buffer.options.acceptStyle) {
2392 gridCell.style.cssText=this.getBufferStyle(windowRow);