3 var CellComponent =
function (cell){
7 CellComponent.prototype.getValue =
function(){
8 return this._cell.getValue();
11 CellComponent.prototype.getOldValue =
function(){
12 return this._cell.getOldValue();
15 CellComponent.prototype.getElement =
function(){
16 return this._cell.getElement();
19 CellComponent.prototype.getRow =
function(){
20 return this._cell.row.getComponent();
23 CellComponent.prototype.getData =
function(){
24 return this._cell.row.getData();
27 CellComponent.prototype.getField =
function(){
28 return this._cell.column.getField();
31 CellComponent.prototype.getColumn =
function(){
32 return this._cell.column.getComponent();
35 CellComponent.prototype.setValue =
function(value, mutate){
36 if(typeof mutate ==
"undefined"){
40 this._cell.setValue(value, mutate);
43 CellComponent.prototype.restoreOldValue =
function(){
44 this._cell.setValueActual(this._cell.getOldValue());
47 CellComponent.prototype.edit =
function(force){
48 return this._cell.edit(force);
51 CellComponent.prototype.cancelEdit =
function(){
52 this._cell.cancelEdit();
56 CellComponent.prototype.nav =
function(){
57 return this._cell.nav();
60 CellComponent.prototype.checkHeight =
function(){
61 this._cell.checkHeight();
64 CellComponent.prototype.getTable =
function(){
65 return this._cell.table;
68 CellComponent.prototype._getSelf =
function(){
74 var Cell =
function(column, row){
76 this.table = column.table;
94 Cell.prototype.build =
function(){
95 this.generateElement();
99 this._configureCell();
101 this.setValueActual(this.column.getFieldValue(
this.row.data));
104 Cell.prototype.generateElement =
function(){
105 this.element = document.createElement(
'div');
106 this.element.className =
"tabulator-cell";
107 this.element.setAttribute(
"role",
"gridcell");
108 this.element = this.element;
112 Cell.prototype._configureCell =
function(){
114 cellEvents =
self.column.cellEvents,
115 element =
self.element,
116 field = this.column.getField();
119 element.style.textAlign =
self.column.hozAlign;
122 element.setAttribute(
"tabulator-field", field);
126 if(
self.column.definition.cssClass){
127 var classNames =
self.column.definition.cssClass.split(
" ")
128 classNames.forEach(
function(className) {
129 element.classList.add(className)
134 if (this.table.options.tooltipGenerationMode ===
"hover"){
135 element.addEventListener(
"mouseenter",
function(e){
136 self._generateTooltip();
140 self._bindClickEvents(cellEvents);
142 self._bindTouchEvents(cellEvents);
144 self._bindMouseEvents(cellEvents);
146 if(
self.column.modules.edit){
147 self.table.modules.edit.bindEditor(
self);
150 if(
self.column.definition.rowHandle &&
self.table.options.movableRows !==
false &&
self.table.modExists(
"moveRow")){
151 self.table.modules.moveRow.initializeCell(
self);
155 if(!
self.column.visible){
160 Cell.prototype._bindClickEvents =
function(cellEvents){
162 element =
self.element;
165 if (cellEvents.cellClick ||
self.table.options.cellClick){
166 element.addEventListener(
"click",
function(e){
167 var component =
self.getComponent();
169 if(cellEvents.cellClick){
170 cellEvents.cellClick.call(
self.table, e, component);
173 if(
self.table.options.cellClick){
174 self.table.options.cellClick.call(
self.table, e, component);
179 if (cellEvents.cellDblClick ||
this.table.options.cellDblClick){
180 element.addEventListener(
"dblclick",
function(e){
181 var component =
self.getComponent();
183 if(cellEvents.cellDblClick){
184 cellEvents.cellDblClick.call(
self.table, e, component);
187 if(
self.table.options.cellDblClick){
188 self.table.options.cellDblClick.call(
self.table, e, component);
192 element.addEventListener(
"dblclick",
function(e){
196 if (document.selection) {
197 var range = document.body.createTextRange();
198 range.moveToElementText(
self.element);
200 }
else if (window.getSelection) {
201 var range = document.createRange();
202 range.selectNode(
self.element);
203 window.getSelection().removeAllRanges();
204 window.getSelection().addRange(range);
210 if (cellEvents.cellContext ||
this.table.options.cellContext){
211 element.addEventListener(
"contextmenu",
function(e){
212 var component =
self.getComponent();
214 if(cellEvents.cellContext){
215 cellEvents.cellContext.call(
self.table, e, component);
218 if(
self.table.options.cellContext){
219 self.table.options.cellContext.call(
self.table, e, component);
226 Cell.prototype._bindMouseEvents =
function(cellEvents){
228 element =
self.element;
230 if (cellEvents.cellMouseEnter ||
self.table.options.cellMouseEnter){
231 element.addEventListener(
"mouseenter",
function(e){
232 var component =
self.getComponent();
234 if(cellEvents.cellMouseEnter){
235 cellEvents.cellMouseEnter.call(
self.table, e, component);
238 if(
self.table.options.cellMouseEnter){
239 self.table.options.cellMouseEnter.call(
self.table, e, component);
244 if (cellEvents.cellMouseLeave ||
self.table.options.cellMouseLeave){
245 element.addEventListener(
"mouseleave",
function(e){
246 var component =
self.getComponent();
248 if(cellEvents.cellMouseLeave){
249 cellEvents.cellMouseLeave.call(
self.table, e, component);
252 if(
self.table.options.cellMouseLeave){
253 self.table.options.cellMouseLeave.call(
self.table, e, component);
258 if (cellEvents.cellMouseOver ||
self.table.options.cellMouseOver){
259 element.addEventListener(
"mouseover",
function(e){
260 var component =
self.getComponent();
262 if(cellEvents.cellMouseOver){
263 cellEvents.cellMouseOver.call(
self.table, e, component);
266 if(
self.table.options.cellMouseOver){
267 self.table.options.cellMouseOver.call(
self.table, e, component);
272 if (cellEvents.cellMouseOut ||
self.table.options.cellMouseOut){
273 element.addEventListener(
"mouseout",
function(e){
274 var component =
self.getComponent();
276 if(cellEvents.cellMouseOut){
277 cellEvents.cellMouseOut.call(
self.table, e, component);
280 if(
self.table.options.cellMouseOut){
281 self.table.options.cellMouseOut.call(
self.table, e, component);
286 if (cellEvents.cellMouseMove ||
self.table.options.cellMouseMove){
287 element.addEventListener(
"mousemove",
function(e){
288 var component =
self.getComponent();
290 if(cellEvents.cellMouseMove){
291 cellEvents.cellMouseMove.call(
self.table, e, component);
294 if(
self.table.options.cellMouseMove){
295 self.table.options.cellMouseMove.call(
self.table, e, component);
304 Cell.prototype._bindTouchEvents =
function(cellEvents){
306 element =
self.element,
307 dblTap, tapHold, tap;
309 if (cellEvents.cellTap ||
this.table.options.cellTap){
312 element.addEventListener(
"touchstart",
function(e){
316 element.addEventListener(
"touchend",
function(e){
318 var component =
self.getComponent();
320 if(cellEvents.cellTap){
321 cellEvents.cellTap.call(
self.table, e, component);
324 if(
self.table.options.cellTap){
325 self.table.options.cellTap.call(
self.table, e, component);
333 if (cellEvents.cellDblTap ||
this.table.options.cellDblTap){
336 element.addEventListener(
"touchend",
function(e){
339 clearTimeout(dblTap);
342 var component =
self.getComponent();
344 if(cellEvents.cellDblTap){
345 cellEvents.cellDblTap.call(
self.table, e, component);
348 if(
self.table.options.cellDblTap){
349 self.table.options.cellDblTap.call(
self.table, e, component);
353 dblTap = setTimeout(
function(){
354 clearTimeout(dblTap);
362 if (cellEvents.cellTapHold ||
this.table.options.cellTapHold){
365 element.addEventListener(
"touchstart",
function(e){
366 clearTimeout(tapHold);
368 tapHold = setTimeout(
function(){
369 clearTimeout(tapHold);
372 var component =
self.getComponent();
374 if(cellEvents.cellTapHold){
375 cellEvents.cellTapHold.call(
self.table, e, component);
378 if(
self.table.options.cellTapHold){
379 self.table.options.cellTapHold.call(
self.table, e, component);
385 element.addEventListener(
"touchend",
function(e){
386 clearTimeout(tapHold);
394 Cell.prototype._generateContents =
function(){
397 if(this.table.modExists(
"format")){
398 val = this.table.modules.format.formatValue(
this);
400 val = this.element.innerHTML = this.value;
405 if(val instanceof Node){
408 while(this.element.firstChild) this.element.removeChild(this.element.firstChild);
410 this.element.appendChild(val);
412 this.element.innerHTML =
"";
415 console.warn(
"Format Error - Formatter has returned a type of object, the only valid formatter object return is an instance of Node, the formatter returned:", val);
421 this.element.innerHTML =
"";
424 this.element.innerHTML = val;
428 Cell.prototype.cellRendered =
function(){
429 if(this.table.modExists(
"format") && this.table.modules.format.cellRendered){
430 this.table.modules.format.cellRendered(
this);
435 Cell.prototype._generateTooltip =
function(){
436 var tooltip = this.column.tooltip;
439 if(tooltip ===
true){
440 tooltip = this.value;
441 }
else if(typeof(tooltip) ==
"function"){
442 tooltip = tooltip(this.getComponent());
444 if(tooltip ===
false){
449 if(typeof tooltip ===
"undefined"){
453 this.element.setAttribute(
"title", tooltip);
455 this.element.setAttribute(
"title",
"");
461 Cell.prototype.getElement =
function(){
465 Cell.prototype.getValue =
function(){
469 Cell.prototype.getOldValue =
function(){
470 return this.oldValue;
475 Cell.prototype.setValue =
function(value, mutate){
477 var changed = this.setValueProcessData(value, mutate),
481 if(this.table.options.history &&
this.table.modExists(
"history")){
482 this.table.modules.history.action(
"cellEdit",
this, {oldValue:this.oldValue, newValue:this.value});
485 component = this.getComponent();
487 if(this.column.cellEvents.cellEdited){
488 this.column.cellEvents.cellEdited.call(this.table, component);
491 this.table.options.cellEdited.call(this.table, component);
493 this.table.options.dataEdited.call(this.table, this.table.rowManager.getData());
498 Cell.prototype.setValueProcessData =
function(value, mutate){
501 if(this.value != value){
506 if(this.column.modules.mutate){
507 value = this.table.modules.mutator.transformCell(
this, value);
512 this.setValueActual(value);
514 if(changed && this.table.modExists(
"columnCalcs")){
515 if(this.column.definition.topCalc ||
this.column.definition.bottomCalc){
516 if(this.table.options.groupBy &&
this.table.modExists(
"groupRows")){
518 if(this.table.options.columnCalcs ==
"table" ||
this.table.options.columnCalcs ==
"both"){
519 this.table.modules.columnCalcs.recalc(this.table.rowManager.activeRows);
522 if(this.table.options.columnCalcs !=
"table"){
523 this.table.modules.columnCalcs.recalcRowGroup(this.row);
527 this.table.modules.columnCalcs.recalc(this.table.rowManager.activeRows);
535 Cell.prototype.setValueActual =
function(value){
536 this.oldValue = this.value;
540 if(this.table.options.reactiveData &&
this.table.modExists(
"reactiveData")){
541 this.table.modules.reactiveData.block();
544 this.column.setFieldValue(this.row.data, value);
546 if(this.table.options.reactiveData &&
this.table.modExists(
"reactiveData")){
547 this.table.modules.reactiveData.unblock();
550 this._generateContents();
551 this._generateTooltip();
554 if(this.table.options.resizableColumns &&
this.table.modExists(
"resizeColumns")){
555 this.table.modules.resizeColumns.initializeColumn(
"cell", this.column, this.element);
559 if(this.table.modExists(
"frozenColumns")){
560 this.table.modules.frozenColumns.layoutElement(this.element, this.column);
564 Cell.prototype.setWidth =
function(){
565 this.width = this.column.width;
566 this.element.style.width = this.column.widthStyled;
569 Cell.prototype.clearWidth =
function(){
571 this.element.style.width =
"";
574 Cell.prototype.getWidth =
function(){
575 return this.width || this.element.offsetWidth;
578 Cell.prototype.setMinWidth =
function(){
579 this.minWidth = this.column.minWidth;
580 this.element.style.minWidth = this.column.minWidthStyled;
583 Cell.prototype.checkHeight =
function(){
585 this.row.reinitializeHeight();
588 Cell.prototype.clearHeight =
function(){
589 this.element.style.height =
"";
594 Cell.prototype.setHeight =
function(){
595 this.height = this.row.height;
596 this.element.style.height = this.row.heightStyled;
599 Cell.prototype.getHeight =
function(){
600 return this.height || this.element.offsetHeight;
603 Cell.prototype.show =
function(){
604 this.element.style.display =
"";
607 Cell.prototype.hide =
function(){
608 this.element.style.display =
"none";
611 Cell.prototype.edit =
function(force){
612 if(this.table.modExists(
"edit",
true)){
613 return this.table.modules.edit.editCell(
this, force);
617 Cell.prototype.cancelEdit =
function(){
618 if(this.table.modExists(
"edit",
true)){
619 var editing = this.table.modules.edit.getCurrentCell();
621 if(editing && editing._getSelf() ===
this){
622 this.table.modules.edit.cancelEdit();
624 console.warn(
"Cancel Editor Error - This cell is not currently being edited ");
631 Cell.prototype.delete =
function(){
632 if(!this.table.rowManager.redrawBlock){
633 this.element.parentNode.removeChild(this.element);
635 this.element =
false;
636 this.column.deleteCell(
this);
637 this.row.deleteCell(
this);
643 Cell.prototype.nav =
function(){
647 index = this.row.getCellIndex(
this);
651 var nextCell = this.right(),
655 nextRow =
self.table.rowManager.nextDisplayRow(
self.row,
true);
658 nextCell = nextRow.findNextEditableCell(-1);
672 var nextCell = this.left(),
676 prevRow =
self.table.rowManager.prevDisplayRow(
self.row,
true);
679 nextCell = prevRow.findPrevEditableCell(prevRow.cells.length);
695 nextCell =
self.row.findPrevEditableCell(index);
705 nextCell =
self.row.findNextEditableCell(index);
715 var nextRow =
self.table.rowManager.prevDisplayRow(
self.row,
true);
718 nextRow.cells[index].edit();
722 var nextRow =
self.table.rowManager.nextDisplayRow(
self.row,
true);
725 nextRow.cells[index].edit();
733 Cell.prototype.getIndex =
function(){
734 this.row.getCellIndex(
this);
738 Cell.prototype.getComponent =
function(){
739 return new CellComponent(
this);