3 var RowComponent =
function (row){
7 RowComponent.prototype.getData =
function(transform){
8 return this._row.getData(transform);
11 RowComponent.prototype.getElement =
function(){
12 return this._row.getElement();
15 RowComponent.prototype.getCells =
function(){
18 this._row.getCells().forEach(
function(cell){
19 cells.push(cell.getComponent());
25 RowComponent.prototype.getCell =
function(column){
26 var cell = this._row.getCell(column);
27 return cell ? cell.getComponent() :
false;
30 RowComponent.prototype.getIndex =
function(){
31 return this._row.getData(
"data")[this._row.table.options.index];
34 RowComponent.prototype.getPosition =
function(active){
35 return this._row.table.rowManager.getRowPosition(this._row, active);
38 RowComponent.prototype.delete =
function(){
39 return this._row.delete();
42 RowComponent.prototype.scrollTo =
function(){
43 return this._row.table.rowManager.scrollToRow(this._row);
46 RowComponent.prototype.pageTo =
function(){
47 if(this._row.table.modExists(
"page",
true)){
48 return this._row.table.modules.page.setPageToRow(this._row);
52 RowComponent.prototype.move =
function(to, after){
53 this._row.moveToRow(to, after);
56 RowComponent.prototype.update =
function(data){
57 return this._row.updateData(data);
60 RowComponent.prototype.normalizeHeight =
function(){
61 this._row.normalizeHeight(
true);
64 RowComponent.prototype.select =
function(){
65 this._row.table.modules.selectRow.selectRows(this._row);
68 RowComponent.prototype.deselect =
function(){
69 this._row.table.modules.selectRow.deselectRows(this._row);
72 RowComponent.prototype.toggleSelect =
function(){
73 this._row.table.modules.selectRow.toggleRow(this._row);
76 RowComponent.prototype.isSelected =
function(){
77 return this._row.table.modules.selectRow.isRowSelected(this._row);
80 RowComponent.prototype._getSelf =
function(){
84 RowComponent.prototype.freeze =
function(){
85 if(this._row.table.modExists(
"frozenRows",
true)){
86 this._row.table.modules.frozenRows.freezeRow(this._row);
90 RowComponent.prototype.unfreeze =
function(){
91 if(this._row.table.modExists(
"frozenRows",
true)){
92 this._row.table.modules.frozenRows.unfreezeRow(this._row);
96 RowComponent.prototype.treeCollapse =
function(){
97 if(this._row.table.modExists(
"dataTree",
true)){
98 this._row.table.modules.dataTree.collapseRow(this._row);
102 RowComponent.prototype.treeExpand =
function(){
103 if(this._row.table.modExists(
"dataTree",
true)){
104 this._row.table.modules.dataTree.expandRow(this._row);
108 RowComponent.prototype.treeToggle =
function(){
109 if(this._row.table.modExists(
"dataTree",
true)){
110 this._row.table.modules.dataTree.toggleRow(this._row);
114 RowComponent.prototype.getTreeParent =
function(){
115 if(this._row.table.modExists(
"dataTree",
true)){
116 return this._row.table.modules.dataTree.getTreeParent(this._row);
122 RowComponent.prototype.getTreeChildren =
function(){
123 if(this._row.table.modExists(
"dataTree",
true)){
124 return this._row.table.modules.dataTree.getTreeChildren(this._row);
130 RowComponent.prototype.reformat =
function(){
131 return this._row.reinitialize();
134 RowComponent.prototype.getGroup =
function(){
135 return this._row.getGroup().getComponent();
138 RowComponent.prototype.getTable =
function(){
139 return this._row.table;
142 RowComponent.prototype.getNextRow =
function(){
143 var row = this._row.nextRow();
144 return row ? row.getComponent() : row;
147 RowComponent.prototype.getPrevRow =
function(){
148 var row = this._row.prevRow();
149 return row ? row.getComponent() : row;
153 var Row =
function(data, parent, type =
"row"){
154 this.table = parent.table;
155 this.parent = parent;
158 this.element = this.createElement();
162 this.heightStyled =
"";
163 this.manualHeight =
false;
164 this.outerHeight = 0;
165 this.initialized =
false;
166 this.heightInitialized =
false;
169 this.generateElement();
172 Row.prototype.createElement =
function (){
173 var el = document.createElement(
"div");
175 el.classList.add(
"tabulator-row");
176 el.setAttribute(
"role",
"row");
181 Row.prototype.getElement =
function(){
185 Row.prototype.detachElement =
function(){
186 if (this.element && this.element.parentNode){
187 this.element.parentNode.removeChild(this.element);
191 Row.prototype.generateElement =
function(){
193 dblTap, tapHold, tap;
196 if(
self.table.options.selectable !==
false &&
self.table.modExists(
"selectRow")){
197 self.table.modules.selectRow.initializeRow(
this);
201 if(
self.table.options.movableRows !==
false &&
self.table.modExists(
"moveRow")){
202 self.table.modules.moveRow.initializeRow(
this);
206 if(
self.table.options.dataTree !==
false &&
self.table.modExists(
"dataTree")){
207 self.table.modules.dataTree.initializeRow(
this);
211 if(
self.table.options.responsiveLayout ===
"collapse" &&
self.table.modExists(
"responsiveLayout")){
212 self.table.modules.responsiveLayout.initializeRow(
this);
216 if (
self.table.options.rowClick){
217 self.element.addEventListener(
"click",
function(e){
218 self.table.options.rowClick(e,
self.getComponent());
222 if (
self.table.options.rowDblClick){
223 self.element.addEventListener(
"dblclick",
function(e){
224 self.table.options.rowDblClick(e,
self.getComponent());
228 if (
self.table.options.rowContext){
229 self.element.addEventListener(
"contextmenu",
function(e){
230 self.table.options.rowContext(e,
self.getComponent());
236 if (
self.table.options.rowMouseEnter){
237 self.element.addEventListener(
"mouseenter",
function(e){
238 self.table.options.rowMouseEnter(e,
self.getComponent());
242 if (
self.table.options.rowMouseLeave){
243 self.element.addEventListener(
"mouseleave",
function(e){
244 self.table.options.rowMouseLeave(e,
self.getComponent());
248 if (
self.table.options.rowMouseOver){
249 self.element.addEventListener(
"mouseover",
function(e){
250 self.table.options.rowMouseOver(e,
self.getComponent());
254 if (
self.table.options.rowMouseOut){
255 self.element.addEventListener(
"mouseout",
function(e){
256 self.table.options.rowMouseOut(e,
self.getComponent());
260 if (
self.table.options.rowMouseMove){
261 self.element.addEventListener(
"mousemove",
function(e){
262 self.table.options.rowMouseMove(e,
self.getComponent());
267 if (
self.table.options.rowTap){
271 self.element.addEventListener(
"touchstart",
function(e){
275 self.element.addEventListener(
"touchend",
function(e){
277 self.table.options.rowTap(e,
self.getComponent());
284 if (
self.table.options.rowDblTap){
288 self.element.addEventListener(
"touchend",
function(e){
291 clearTimeout(dblTap);
294 self.table.options.rowDblTap(e,
self.getComponent());
297 dblTap = setTimeout(
function(){
298 clearTimeout(dblTap);
307 if (
self.table.options.rowTapHold){
311 self.element.addEventListener(
"touchstart",
function(e){
312 clearTimeout(tapHold);
314 tapHold = setTimeout(
function(){
315 clearTimeout(tapHold);
318 self.table.options.rowTapHold(e,
self.getComponent());
323 self.element.addEventListener(
"touchend",
function(e){
324 clearTimeout(tapHold);
330 Row.prototype.generateCells =
function(){
331 this.cells = this.table.columnManager.generateCells(
this);
335 Row.prototype.initialize =
function(force){
338 if(!
self.initialized || force){
342 while(
self.element.firstChild)
self.element.removeChild(
self.element.firstChild);
345 if(this.table.modExists(
"frozenColumns")){
346 this.table.modules.frozenColumns.layoutRow(
this);
349 this.generateCells();
351 self.cells.forEach(
function(cell){
352 self.element.appendChild(cell.getElement());
357 self.normalizeHeight();
361 if(
self.table.options.dataTree &&
self.table.modExists(
"dataTree")){
362 self.table.modules.dataTree.layoutRow(
this);
366 if(
self.table.options.responsiveLayout ===
"collapse" &&
self.table.modExists(
"responsiveLayout")){
367 self.table.modules.responsiveLayout.layoutRow(
this);
370 if(
self.table.options.rowFormatter){
371 self.table.options.rowFormatter(
self.getComponent());
375 if(
self.table.options.resizableRows &&
self.table.modExists(
"resizeRows")){
376 self.table.modules.resizeRows.initializeRow(
self);
379 self.initialized =
true;
383 Row.prototype.reinitializeHeight =
function(){
384 this.heightInitialized =
false;
386 if(this.element.offsetParent !== null){
387 this.normalizeHeight(
true);
392 Row.prototype.reinitialize =
function(){
393 this.initialized =
false;
394 this.heightInitialized =
false;
396 if(!this.manualHeight){
398 this.heightStyled =
"";
401 if(this.element.offsetParent !== null){
402 this.initialize(
true);
407 Row.prototype.calcHeight =
function(force){
410 minHeight = this.table.options.resizableRows ? this.element.clientHeight : 0;
412 this.cells.forEach(
function(cell){
413 var height = cell.getHeight();
414 if(height > maxHeight){
420 this.height = Math.max(maxHeight, minHeight);
422 this.height = this.manualHeight ? this.height : Math.max(maxHeight, minHeight);
425 this.heightStyled = this.height ? this.height +
"px" :
"";
426 this.outerHeight = this.element.offsetHeight;
430 Row.prototype.setCellHeight =
function(){
431 this.cells.forEach(
function(cell){
435 this.heightInitialized =
true;
438 Row.prototype.clearCellHeight =
function(){
439 this.cells.forEach(
function(cell){
445 Row.prototype.normalizeHeight =
function(force){
448 this.clearCellHeight();
451 this.calcHeight(force);
453 this.setCellHeight();
463 Row.prototype.setHeight =
function(height, force){
464 if(this.height != height || force){
466 this.manualHeight =
true;
468 this.height = height;
469 this.heightStyled = height ? height +
"px" :
"";
471 this.setCellHeight();
474 this.outerHeight = this.element.offsetHeight;
479 Row.prototype.getHeight =
function(){
480 return this.outerHeight;
484 Row.prototype.getWidth =
function(){
485 return this.element.offsetWidth;
491 Row.prototype.deleteCell =
function(cell){
492 var index = this.cells.indexOf(cell);
495 this.cells.splice(index, 1);
501 Row.prototype.setData =
function(data){
502 if(this.table.modExists(
"mutator")){
503 data = this.table.modules.mutator.transformRow(data,
"data", data);
508 if(this.table.options.reactiveData &&
this.table.modExists(
"reactiveData",
true)){
509 this.table.modules.reactiveData.watchRow(
this);
514 Row.prototype.updateData =
function(data){
515 var visible = Tabulator.prototype.helpers.elVisible(this.element),
518 return new Promise((resolve, reject) => {
520 if(typeof data ===
"string"){
521 data = JSON.parse(data);
524 if(this.table.options.reactiveData &&
this.table.modExists(
"reactiveData",
true)){
525 this.table.modules.reactiveData.block();
529 if(this.table.modExists(
"mutator")){
531 tempData = Object.assign(tempData, this.data);
532 tempData = Object.assign(tempData, data);
534 data = this.table.modules.mutator.transformRow(tempData,
"data", data);
538 for (var attrname in data) {
539 this.data[attrname] = data[attrname];
542 if(this.table.options.reactiveData &&
this.table.modExists(
"reactiveData",
true)){
543 this.table.modules.reactiveData.unblock();
547 for (var attrname in data) {
549 let columns = this.table.columnManager.getColumnsByFieldRoot(attrname);
551 columns.forEach((column) => {
552 let cell = this.getCell(column.getField());
555 let value = column.getFieldValue(data);
556 if(cell.getValue() != value){
557 cell.setValueProcessData(value);
569 this.normalizeHeight();
571 if(this.table.options.rowFormatter){
572 this.table.options.rowFormatter(this.getComponent());
575 this.initialized =
false;
577 this.heightStyled =
"";
580 if(this.table.options.dataTree !==
false &&
this.table.modExists(
"dataTree") && this.table.modules.dataTree.redrawNeeded(data)){
581 this.table.modules.dataTree.initializeRow(
this);
582 this.table.modules.dataTree.layoutRow(
this);
583 this.table.rowManager.refreshActiveData(
"tree",
false,
true);
588 this.table.options.rowUpdated.call(this.table, this.getComponent());
594 Row.prototype.getData =
function(transform){
598 if(
self.table.modExists(
"accessor")){
599 return self.table.modules.accessor.transformRow(
self.data, transform);
607 Row.prototype.getCell =
function(column){
610 column = this.table.columnManager.findColumn(column);
612 match = this.cells.find(
function(cell){
613 return cell.column === column;
619 Row.prototype.getCellIndex =
function(findCell){
620 return this.cells.findIndex(
function(cell){
621 return cell === findCell;
626 Row.prototype.findNextEditableCell =
function(index){
627 var nextCell =
false;
629 if(index < this.cells.length-1){
630 for(var i = index+1; i < this.cells.length; i++){
631 let cell = this.cells[i];
633 if(cell.column.modules.edit && Tabulator.prototype.helpers.elVisible(cell.getElement())){
634 let allowEdit =
true;
636 if(typeof cell.column.modules.edit.check ==
"function"){
637 allowEdit = cell.column.modules.edit.check(cell.getComponent());
651 Row.prototype.findPrevEditableCell =
function(index){
652 var prevCell =
false;
655 for(var i = index-1; i >= 0; i--){
656 let cell = this.cells[i],
659 if(cell.column.modules.edit && Tabulator.prototype.helpers.elVisible(cell.getElement())){
660 if(typeof cell.column.modules.edit.check ==
"function"){
661 allowEdit = cell.column.modules.edit.check(cell.getComponent());
675 Row.prototype.getCells =
function(){
679 Row.prototype.nextRow =
function(){
680 var row = this.table.rowManager.nextDisplayRow(
this,
true);
684 Row.prototype.prevRow =
function(){
685 var row = this.table.rowManager.prevDisplayRow(
this,
true);
689 Row.prototype.moveToRow =
function(to, before){
690 var toRow = this.table.rowManager.findRow(to);
693 this.table.rowManager.moveRowActual(
this, toRow, !before);
694 this.table.rowManager.refreshActiveData(
"display",
false,
true);
696 console.warn(
"Move Error - No matching row found:", to);
703 Row.prototype.delete =
function(){
704 return new Promise((resolve, reject) => {
707 if(this.table.options.history &&
this.table.modExists(
"history")){
709 if(this.table.options.groupBy &&
this.table.modExists(
"groupRows")){
710 rows = this.getGroup().rows
711 index = rows.indexOf(
this);
714 index = rows[index-1];
717 index = this.table.rowManager.getRowIndex(
this);
720 index = this.table.rowManager.rows[index-1];
724 this.table.modules.history.action(
"rowDelete",
this, {data:this.getData(), pos:!index, index:index});
735 Row.prototype.deleteActual =
function(blockRedraw){
736 var index = this.table.rowManager.getRowIndex(
this);
739 if(this.table.modExists(
"selectRow")){
740 this.table.modules.selectRow._deselectRow(
this,
true);
748 if(this.table.options.reactiveData &&
this.table.modExists(
"reactiveData",
true)){
753 if(this.modules.group){
754 this.modules.group.removeRow(
this);
757 this.table.rowManager.deleteRow(
this, blockRedraw);
761 this.initialized =
false;
762 this.heightInitialized =
false;
765 if(this.table.modExists(
"columnCalcs")){
766 if(this.table.options.groupBy &&
this.table.modExists(
"groupRows")){
767 this.table.modules.columnCalcs.recalcRowGroup(
this);
769 this.table.modules.columnCalcs.recalc(this.table.rowManager.activeRows);
774 Row.prototype.deleteCells =
function(){
775 var cellCount = this.cells.length;
777 for(let i = 0; i < cellCount; i++){
778 this.cells[0].delete();
782 Row.prototype.wipe =
function(){
785 while(this.element.firstChild) this.element.removeChild(this.element.firstChild);
787 this.element =
false;
790 if(this.element.parentNode){
791 this.element.parentNode.removeChild(this.element);
796 Row.prototype.getGroup =
function(){
797 return this.modules.group ||
false;
802 Row.prototype.getComponent =
function(){
803 return new RowComponent(
this);