otsdaq_utilities  v2_05_02_indev
group_rows.min.js
1 /* Tabulator v4.5.3 (c) Oliver Folkerd */
2 var GroupComponent=function(t){this._group=t,this.type="GroupComponent"};GroupComponent.prototype.getKey=function(){return this._group.key},GroupComponent.prototype.getField=function(){return this._group.field},GroupComponent.prototype.getElement=function(){return this._group.element},GroupComponent.prototype.getRows=function(){return this._group.getRows(!0)},GroupComponent.prototype.getSubGroups=function(){return this._group.getSubGroups(!0)},GroupComponent.prototype.getParentGroup=function(){return!!this._group.parent&&this._group.parent.getComponent()},GroupComponent.prototype.getVisibility=function(){return this._group.visible},GroupComponent.prototype.show=function(){this._group.show()},GroupComponent.prototype.hide=function(){this._group.hide()},GroupComponent.prototype.toggle=function(){this._group.toggleVisibility()},GroupComponent.prototype._getSelf=function(){return this._group},GroupComponent.prototype.getTable=function(){return this._group.groupManager.table};var Group=function(t,o,e,r,i,s,n){this.groupManager=t,this.parent=o,this.key=r,this.level=e,this.field=i,this.hasSubGroups=e<t.groupIDLookups.length-1,this.addRow=this.hasSubGroups?this._addRowToGroup:this._addRow,this.type="group",this.old=n,this.rows=[],this.groups=[],this.groupList=[],this.generator=s,this.elementContents=!1,this.height=0,this.outerHeight=0,this.initialized=!1,this.calcs={},this.initialized=!1,this.modules={},this.arrowElement=!1,this.visible=n?n.visible:void 0!==t.startOpen[e]?t.startOpen[e]:t.startOpen[0],this.createElements(),this.addBindings(),this.createValueGroups()};Group.prototype.wipe=function(){this.groupList.length?this.groupList.forEach(function(t){t.wipe()}):(this.element=!1,this.arrowElement=!1,this.elementContents=!1)},Group.prototype.createElements=function(){var t=document.createElement("div");t.classList.add("tabulator-arrow"),this.element=document.createElement("div"),this.element.classList.add("tabulator-row"),this.element.classList.add("tabulator-group"),this.element.classList.add("tabulator-group-level-"+this.level),this.element.setAttribute("role","rowgroup"),this.arrowElement=document.createElement("div"),this.arrowElement.classList.add("tabulator-group-toggle"),this.arrowElement.appendChild(t),!1!==this.groupManager.table.options.movableRows&&this.groupManager.table.modExists("moveRow")&&this.groupManager.table.modules.moveRow.initializeGroupHeader(this)},Group.prototype.createValueGroups=function(){var t=this,o=this.level+1;this.groupManager.allowedValues&&this.groupManager.allowedValues[o]&&this.groupManager.allowedValues[o].forEach(function(e){t._createGroup(e,o)})},Group.prototype.addBindings=function(){var t,o,e,r,i=this;i.groupManager.table.options.groupClick&&i.element.addEventListener("click",function(t){i.groupManager.table.options.groupClick.call(i.groupManager.table,t,i.getComponent())}),i.groupManager.table.options.groupDblClick&&i.element.addEventListener("dblclick",function(t){i.groupManager.table.options.groupDblClick.call(i.groupManager.table,t,i.getComponent())}),i.groupManager.table.options.groupContext&&i.element.addEventListener("contextmenu",function(t){i.groupManager.table.options.groupContext.call(i.groupManager.table,t,i.getComponent())}),i.groupManager.table.options.groupTap&&(e=!1,i.element.addEventListener("touchstart",function(t){e=!0},{passive:!0}),i.element.addEventListener("touchend",function(t){e&&i.groupManager.table.options.groupTap(t,i.getComponent()),e=!1})),i.groupManager.table.options.groupDblTap&&(t=null,i.element.addEventListener("touchend",function(o){t?(clearTimeout(t),t=null,i.groupManager.table.options.groupDblTap(o,i.getComponent())):t=setTimeout(function(){clearTimeout(t),t=null},300)})),i.groupManager.table.options.groupTapHold&&(o=null,i.element.addEventListener("touchstart",function(t){clearTimeout(o),o=setTimeout(function(){clearTimeout(o),o=null,e=!1,i.groupManager.table.options.groupTapHold(t,i.getComponent())},1e3)},{passive:!0}),i.element.addEventListener("touchend",function(t){clearTimeout(o),o=null})),i.groupManager.table.options.groupToggleElement&&(r="arrow"==i.groupManager.table.options.groupToggleElement?i.arrowElement:i.element,r.addEventListener("click",function(t){t.stopPropagation(),t.stopImmediatePropagation(),i.toggleVisibility()}))},Group.prototype._createGroup=function(t,o){var e=o+"_"+t,r=new Group(this.groupManager,this,o,t,this.groupManager.groupIDLookups[o].field,this.groupManager.headerGenerator[o]||this.groupManager.headerGenerator[0],!!this.old&&this.old.groups[e]);this.groups[e]=r,this.groupList.push(r)},Group.prototype._addRowToGroup=function(t){var o=this.level+1;if(this.hasSubGroups){var e=this.groupManager.groupIDLookups[o].func(t.getData()),r=o+"_"+e;this.groupManager.allowedValues&&this.groupManager.allowedValues[o]?this.groups[r]&&this.groups[r].addRow(t):(this.groups[r]||this._createGroup(e,o),this.groups[r].addRow(t))}},Group.prototype._addRow=function(t){this.rows.push(t),t.modules.group=this},Group.prototype.insertRow=function(t,o,e){var r=this.conformRowData({});t.updateData(r);var i=this.rows.indexOf(o);i>-1?e?this.rows.splice(i+1,0,t):this.rows.splice(i,0,t):e?this.rows.push(t):this.rows.unshift(t),t.modules.group=this,this.generateGroupHeaderContents(),this.groupManager.table.modExists("columnCalcs")&&"table"!=this.groupManager.table.options.columnCalcs&&this.groupManager.table.modules.columnCalcs.recalcGroup(this),this.groupManager.updateGroupRows(!0)},Group.prototype.scrollHeader=function(t){this.arrowElement.style.marginLeft=t,this.groupList.forEach(function(o){o.scrollHeader(t)})},Group.prototype.getRowIndex=function(t){},Group.prototype.conformRowData=function(t){return this.field?t[this.field]=this.key:console.warn("Data Conforming Error - Cannot conform row data to match new group as groupBy is a function"),this.parent&&(t=this.parent.conformRowData(t)),t},Group.prototype.removeRow=function(t){var o=this.rows.indexOf(t),e=t.getElement();o>-1&&this.rows.splice(o,1),this.groupManager.table.options.groupValues||this.rows.length?(e.parentNode&&e.parentNode.removeChild(e),this.generateGroupHeaderContents(),this.groupManager.table.modExists("columnCalcs")&&"table"!=this.groupManager.table.options.columnCalcs&&this.groupManager.table.modules.columnCalcs.recalcGroup(this)):(this.parent?this.parent.removeGroup(this):this.groupManager.removeGroup(this),this.groupManager.updateGroupRows(!0))},Group.prototype.removeGroup=function(t){var o,e=t.level+"_"+t.key;this.groups[e]&&(delete this.groups[e],o=this.groupList.indexOf(t),o>-1&&this.groupList.splice(o,1),this.groupList.length||(this.parent?this.parent.removeGroup(this):this.groupManager.removeGroup(this)))},Group.prototype.getHeadersAndRows=function(t){var o=[];return o.push(this),this._visSet(),this.visible?this.groupList.length?this.groupList.forEach(function(e){o=o.concat(e.getHeadersAndRows(t))}):(!t&&"table"!=this.groupManager.table.options.columnCalcs&&this.groupManager.table.modExists("columnCalcs")&&this.groupManager.table.modules.columnCalcs.hasTopCalcs()&&(this.calcs.top&&(this.calcs.top.detachElement(),this.calcs.top.deleteCells()),this.calcs.top=this.groupManager.table.modules.columnCalcs.generateTopRow(this.rows),o.push(this.calcs.top)),o=o.concat(this.rows),!t&&"table"!=this.groupManager.table.options.columnCalcs&&this.groupManager.table.modExists("columnCalcs")&&this.groupManager.table.modules.columnCalcs.hasBottomCalcs()&&(this.calcs.bottom&&(this.calcs.bottom.detachElement(),this.calcs.bottom.deleteCells()),this.calcs.bottom=this.groupManager.table.modules.columnCalcs.generateBottomRow(this.rows),o.push(this.calcs.bottom))):this.groupList.length||"table"==this.groupManager.table.options.columnCalcs||this.groupManager.table.modExists("columnCalcs")&&(!t&&this.groupManager.table.modules.columnCalcs.hasTopCalcs()&&(this.calcs.top&&(this.calcs.top.detachElement(),this.calcs.top.deleteCells()),this.groupManager.table.options.groupClosedShowCalcs&&(this.calcs.top=this.groupManager.table.modules.columnCalcs.generateTopRow(this.rows),o.push(this.calcs.top))),!t&&this.groupManager.table.modules.columnCalcs.hasBottomCalcs()&&(this.calcs.bottom&&(this.calcs.bottom.detachElement(),this.calcs.bottom.deleteCells()),this.groupManager.table.options.groupClosedShowCalcs&&(this.calcs.bottom=this.groupManager.table.modules.columnCalcs.generateBottomRow(this.rows),o.push(this.calcs.bottom)))),o},Group.prototype.getData=function(t,o){var e=[];return this._visSet(),(!t||t&&this.visible)&&this.rows.forEach(function(t){e.push(t.getData(o||"data"))}),e},Group.prototype.getRowCount=function(){var t=0;return this.groupList.length?this.groupList.forEach(function(o){t+=o.getRowCount()}):t=this.rows.length,t},Group.prototype.toggleVisibility=function(){this.visible?this.hide():this.show()},Group.prototype.hide=function(){this.visible=!1,"classic"!=this.groupManager.table.rowManager.getRenderMode()||this.groupManager.table.options.pagination?this.groupManager.updateGroupRows(!0):(this.element.classList.remove("tabulator-group-visible"),this.groupList.length?this.groupList.forEach(function(t){t.getHeadersAndRows().forEach(function(t){t.detachElement()})}):this.rows.forEach(function(t){var o=t.getElement();o.parentNode.removeChild(o)}),this.groupManager.table.rowManager.setDisplayRows(this.groupManager.updateGroupRows(),this.groupManager.getDisplayIndex()),this.groupManager.table.rowManager.checkClassicModeGroupHeaderWidth()),this.groupManager.table.options.groupVisibilityChanged.call(this.table,this.getComponent(),!1)},Group.prototype.show=function(){var t=this;if(t.visible=!0,"classic"!=this.groupManager.table.rowManager.getRenderMode()||this.groupManager.table.options.pagination)this.groupManager.updateGroupRows(!0);else{this.element.classList.add("tabulator-group-visible");var o=t.getElement();this.groupList.length?this.groupList.forEach(function(t){t.getHeadersAndRows().forEach(function(t){var e=t.getElement();o.parentNode.insertBefore(e,o.nextSibling),t.initialize(),o=e})}):t.rows.forEach(function(t){var e=t.getElement();o.parentNode.insertBefore(e,o.nextSibling),t.initialize(),o=e}),this.groupManager.table.rowManager.setDisplayRows(this.groupManager.updateGroupRows(),this.groupManager.getDisplayIndex()),this.groupManager.table.rowManager.checkClassicModeGroupHeaderWidth()}this.groupManager.table.options.groupVisibilityChanged.call(this.table,this.getComponent(),!0)},Group.prototype._visSet=function(){var t=[];"function"==typeof this.visible&&(this.rows.forEach(function(o){t.push(o.getData())}),this.visible=this.visible(this.key,this.getRowCount(),t,this.getComponent()))},Group.prototype.getRowGroup=function(t){var o=!1;return this.groupList.length?this.groupList.forEach(function(e){var r=e.getRowGroup(t);r&&(o=r)}):this.rows.find(function(o){return o===t})&&(o=this),o},Group.prototype.getSubGroups=function(t){var o=[];return this.groupList.forEach(function(e){o.push(t?e.getComponent():e)}),o},Group.prototype.getRows=function(t){var o=[];return this.rows.forEach(function(e){o.push(t?e.getComponent():e)}),o},Group.prototype.generateGroupHeaderContents=function(){var t=[];for(this.rows.forEach(function(o){t.push(o.getData())}),this.elementContents=this.generator(this.key,this.getRowCount(),t,this.getComponent());this.element.firstChild;)this.element.removeChild(this.element.firstChild);"string"==typeof this.elementContents?this.element.innerHTML=this.elementContents:this.element.appendChild(this.elementContents),this.element.insertBefore(this.arrowElement,this.element.firstChild)},Group.prototype.getElement=function(){this.addBindingsd=!1,this._visSet(),this.visible?this.element.classList.add("tabulator-group-visible"):this.element.classList.remove("tabulator-group-visible");for(var t=0;t<this.element.childNodes.length;++t)this.element.childNodes[t].parentNode.removeChild(this.element.childNodes[t]);return this.generateGroupHeaderContents(),this.element},Group.prototype.detachElement=function(){this.element&&this.element.parentNode&&this.element.parentNode.removeChild(this.element)},Group.prototype.normalizeHeight=function(){this.setHeight(this.element.clientHeight)},Group.prototype.initialize=function(t){this.initialized&&!t||(this.normalizeHeight(),this.initialized=!0)},Group.prototype.reinitialize=function(){this.initialized=!1,this.height=0,Tabulator.prototype.helpers.elVisible(this.element)&&this.initialize(!0)},Group.prototype.setHeight=function(t){this.height!=t&&(this.height=t,this.outerHeight=this.element.offsetHeight)},Group.prototype.getHeight=function(){return this.outerHeight},Group.prototype.getGroup=function(){return this},Group.prototype.reinitializeHeight=function(){},Group.prototype.calcHeight=function(){},Group.prototype.setCellHeight=function(){},Group.prototype.clearCellHeight=function(){},Group.prototype.getComponent=function(){return new GroupComponent(this)};var GroupRows=function(t){this.table=t,this.groupIDLookups=!1,this.startOpen=[function(){return!1}],this.headerGenerator=[function(){return""}],this.groupList=[],this.allowedValues=!1,this.groups={},this.displayIndex=0};GroupRows.prototype.initialize=function(){var t=this,o=t.table.options.groupBy,e=t.table.options.groupStartOpen,r=t.table.options.groupHeader;if(this.allowedValues=t.table.options.groupValues,Array.isArray(o)&&Array.isArray(r)&&o.length>r.length&&console.warn("Error creating group headers, groupHeader array is shorter than groupBy array"),t.headerGenerator=[function(){return""}],this.startOpen=[function(){return!1}],t.table.modules.localize.bind("groups|item",function(o,e){t.headerGenerator[0]=function(t,r,i){return(void 0===t?"":t)+"<span>("+r+" "+(1===r?o:e.groups.items)+")</span>"}}),this.groupIDLookups=[],Array.isArray(o)||o)this.table.modExists("columnCalcs")&&"table"!=this.table.options.columnCalcs&&"both"!=this.table.options.columnCalcs&&this.table.modules.columnCalcs.removeCalcs();else if(this.table.modExists("columnCalcs")&&"group"!=this.table.options.columnCalcs){var i=this.table.columnManager.getRealColumns();i.forEach(function(o){o.definition.topCalc&&t.table.modules.columnCalcs.initializeTopRow(),o.definition.bottomCalc&&t.table.modules.columnCalcs.initializeBottomRow()})}Array.isArray(o)||(o=[o]),o.forEach(function(o,e){var r,i;"function"==typeof o?r=o:(i=t.table.columnManager.getColumnByField(o),r=i?function(t){return i.getFieldValue(t)}:function(t){return t[o]}),t.groupIDLookups.push({field:"function"!=typeof o&&o,func:r,values:!!t.allowedValues&&t.allowedValues[e]})}),e&&(Array.isArray(e)||(e=[e]),e.forEach(function(t){t="function"==typeof t?t:function(){return!0}}),t.startOpen=e),r&&(t.headerGenerator=Array.isArray(r)?r:[r]),this.initialized=!0},GroupRows.prototype.setDisplayIndex=function(t){this.displayIndex=t},GroupRows.prototype.getDisplayIndex=function(){return this.displayIndex},GroupRows.prototype.getRows=function(t){return this.groupIDLookups.length?(this.table.options.dataGrouping.call(this.table),this.generateGroups(t),this.table.options.dataGrouped&&this.table.options.dataGrouped.call(this.table,this.getGroups(!0)),this.updateGroupRows()):t.slice(0)},GroupRows.prototype.getGroups=function(t){var o=[];return this.groupList.forEach(function(e){o.push(t?e.getComponent():e)}),o},GroupRows.prototype.wipe=function(){this.groupList.forEach(function(t){t.wipe()})},GroupRows.prototype.pullGroupListData=function(t){var o=this,e=[];return t.forEach(function(t){var r={};r.level=0,r.rowCount=0,r.headerContent="";var i=[];t.hasSubGroups?(i=o.pullGroupListData(t.groupList),r.level=t.level,r.rowCount=i.length-t.groupList.length,r.headerContent=t.generator(t.key,r.rowCount,t.rows,t),e.push(r),e=e.concat(i)):(r.level=t.level,r.headerContent=t.generator(t.key,t.rows.length,t.rows,t),r.rowCount=t.getRows().length,e.push(r),t.getRows().forEach(function(t){e.push(t.getData("data"))}))}),e},GroupRows.prototype.getGroupedData=function(){return this.pullGroupListData(this.groupList)},GroupRows.prototype.getRowGroup=function(t){var o=!1;return this.groupList.forEach(function(e){var r=e.getRowGroup(t);r&&(o=r)}),o},GroupRows.prototype.countGroups=function(){return this.groupList.length},GroupRows.prototype.generateGroups=function(t){var o=this,e=o.groups;o.groups={},o.groupList=[],this.allowedValues&&this.allowedValues[0]?(this.allowedValues[0].forEach(function(t){o.createGroup(t,0,e)}),t.forEach(function(t){o.assignRowToExistingGroup(t,e)})):t.forEach(function(t){o.assignRowToGroup(t,e)})},GroupRows.prototype.createGroup=function(t,o,e){var r,i=o+"_"+t;e=e||[],r=new Group(this,!1,o,t,this.groupIDLookups[0].field,this.headerGenerator[0],e[i]),this.groups[i]=r,this.groupList.push(r)},GroupRows.prototype.assignRowToExistingGroup=function(t,o){var e=this.groupIDLookups[0].func(t.getData()),r="0_"+e;this.groups[r]&&this.groups[r].addRow(t)},GroupRows.prototype.assignRowToGroup=function(t,o){var e=this.groupIDLookups[0].func(t.getData()),r=!this.groups["0_"+e];return r&&this.createGroup(e,0,o),this.groups["0_"+e].addRow(t),!r},GroupRows.prototype.updateGroupRows=function(t){var o=this,e=[];if(o.groupList.forEach(function(t){e=e.concat(t.getHeadersAndRows())}),t){var r=o.table.rowManager.setDisplayRows(e,this.getDisplayIndex());!0!==r&&this.setDisplayIndex(r),o.table.rowManager.refreshActiveData("group",!0,!0)}return e},GroupRows.prototype.scrollHeaders=function(t){t+="px",this.groupList.forEach(function(o){o.scrollHeader(t)})},GroupRows.prototype.removeGroup=function(t){var o,e=t.level+"_"+t.key;this.groups[e]&&(delete this.groups[e],(o=this.groupList.indexOf(t))>-1&&this.groupList.splice(o,1))},Tabulator.prototype.registerModule("groupRows",GroupRows);