otsdaq_utilities  v2_05_02_indev
data_tree.min.js
1 /* Tabulator v4.5.3 (c) Oliver Folkerd */
2 var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},DataTree=function(e){this.table=e,this.indent=10,this.field="",this.collapseEl=null,this.expandEl=null,this.branchEl=null,this.elementField=!1,this.startOpen=function(){},this.displayIndex=0};DataTree.prototype.initialize=function(){var e=null,t=this.table.columnManager.getFirstVisibileColumn(),a=this.table.options;switch(this.field=a.dataTreeChildField,this.indent=a.dataTreeChildIndent,this.elementField=a.dataTreeElementColumn||!!t&&t.field,a.dataTreeBranchElement&&(!0===a.dataTreeBranchElement?(this.branchEl=document.createElement("div"),this.branchEl.classList.add("tabulator-data-tree-branch")):"string"==typeof a.dataTreeBranchElement?(e=document.createElement("div"),e.innerHTML=a.dataTreeBranchElement,this.branchEl=e.firstChild):this.branchEl=a.dataTreeBranchElement),a.dataTreeCollapseElement?"string"==typeof a.dataTreeCollapseElement?(e=document.createElement("div"),e.innerHTML=a.dataTreeCollapseElement,this.collapseEl=e.firstChild):this.collapseEl=a.dataTreeCollapseElement:(this.collapseEl=document.createElement("div"),this.collapseEl.classList.add("tabulator-data-tree-control"),this.collapseEl.tabIndex=0,this.collapseEl.innerHTML="<div class='tabulator-data-tree-control-collapse'></div>"),a.dataTreeExpandElement?"string"==typeof a.dataTreeExpandElement?(e=document.createElement("div"),e.innerHTML=a.dataTreeExpandElement,this.expandEl=e.firstChild):this.expandEl=a.dataTreeExpandElement:(this.expandEl=document.createElement("div"),this.expandEl.classList.add("tabulator-data-tree-control"),this.expandEl.tabIndex=0,this.expandEl.innerHTML="<div class='tabulator-data-tree-control-expand'></div>"),_typeof(a.dataTreeStartExpanded)){case"boolean":this.startOpen=function(e,t){return a.dataTreeStartExpanded};break;case"function":this.startOpen=a.dataTreeStartExpanded;break;default:this.startOpen=function(e,t){return a.dataTreeStartExpanded[t]}}},DataTree.prototype.initializeRow=function(e){var t=e.getData()[this.field],a=Array.isArray(t),n=a||!a&&"object"===(void 0===t?"undefined":_typeof(t))&&null!==t;e.modules.dataTree={index:0,open:!!n&&this.startOpen(e.getComponent(),0),controlEl:!1,branchEl:!1,parent:!1,children:n}},DataTree.prototype.layoutRow=function(e){var t=this.elementField?e.getCell(this.elementField):e.getCells()[0],a=t.getElement(),n=e.modules.dataTree;n.branchEl&&n.branchEl.parentNode.removeChild(n.branchEl),this.generateControlElement(e,a),n.index&&(this.branchEl?(n.branchEl=this.branchEl.cloneNode(!0),a.insertBefore(n.branchEl,a.firstChild),n.branchEl.style.marginLeft=(n.branchEl.offsetWidth+n.branchEl.style.marginRight)*(n.index-1)+n.index*this.indent+"px"):a.style.paddingLeft=parseInt(window.getComputedStyle(a,null).getPropertyValue("padding-left"))+n.index*this.indent+"px")},DataTree.prototype.generateControlElement=function(e,t){var a=this,n=e.modules.dataTree,t=t||e.getCells()[0].getElement(),r=n.controlEl;!1!==n.children&&(n.open?(n.controlEl=this.collapseEl.cloneNode(!0),n.controlEl.addEventListener("click",function(t){t.stopPropagation(),a.collapseRow(e)})):(n.controlEl=this.expandEl.cloneNode(!0),n.controlEl.addEventListener("click",function(t){t.stopPropagation(),a.expandRow(e)})),n.controlEl.addEventListener("mousedown",function(e){e.stopPropagation()}),r&&r.parentNode===t?r.parentNode.replaceChild(n.controlEl,r):t.insertBefore(n.controlEl,t.firstChild))},DataTree.prototype.setDisplayIndex=function(e){this.displayIndex=e},DataTree.prototype.getDisplayIndex=function(){return this.displayIndex},DataTree.prototype.getRows=function(e){var t=this,a=[];return e.forEach(function(e,n){var r,l;a.push(e),e instanceof Row&&(r=e.modules.dataTree.children,r.index||!1===r.children||(l=t.getChildren(e),l.forEach(function(e){a.push(e)})))}),a},DataTree.prototype.getChildren=function(e){var t=this,a=e.modules.dataTree,n=[],r=[];return!1!==a.children&&a.open&&(Array.isArray(a.children)||(a.children=this.generateChildren(e)),n=this.table.modExists("filter")?this.table.modules.filter.filter(a.children):a.children,this.table.modExists("sort")&&this.table.modules.sort.sort(n),n.forEach(function(e){r.push(e),t.getChildren(e).forEach(function(e){r.push(e)})})),r},DataTree.prototype.generateChildren=function(e){var t=this,a=[],n=e.getData()[this.field];return Array.isArray(n)||(n=[n]),n.forEach(function(n){var r=new Row(n||{},t.table.rowManager);r.modules.dataTree.index=e.modules.dataTree.index+1,r.modules.dataTree.parent=e,r.modules.dataTree.children&&(r.modules.dataTree.open=t.startOpen(r.getComponent(),r.modules.dataTree.index)),a.push(r)}),a},DataTree.prototype.expandRow=function(e,t){var a=e.modules.dataTree;!1!==a.children&&(a.open=!0,e.reinitialize(),this.table.rowManager.refreshActiveData("tree",!1,!0),this.table.options.dataTreeRowExpanded(e.getComponent(),e.modules.dataTree.index))},DataTree.prototype.collapseRow=function(e){var t=e.modules.dataTree;!1!==t.children&&(t.open=!1,e.reinitialize(),this.table.rowManager.refreshActiveData("tree",!1,!0),this.table.options.dataTreeRowCollapsed(e.getComponent(),e.modules.dataTree.index))},DataTree.prototype.toggleRow=function(e){var t=e.modules.dataTree;!1!==t.children&&(t.open?this.collapseRow(e):this.expandRow(e))},DataTree.prototype.getTreeParent=function(e){return!!e.modules.dataTree.parent&&e.modules.dataTree.parent.getComponent()},DataTree.prototype.getTreeChildren=function(e){var t=e.modules.dataTree,a=[];return t.children&&(Array.isArray(t.children)||(t.children=this.generateChildren(e)),t.children.forEach(function(e){e instanceof Row&&a.push(e.getComponent())})),a},DataTree.prototype.checkForRestyle=function(e){e.row.cells.indexOf(e)||!1!==e.row.modules.dataTree.children&&e.row.reinitialize()},DataTree.prototype.getChildField=function(){return this.field},DataTree.prototype.redrawNeeded=function(e){return!!this.field&&void 0!==e[this.field]||!!this.elementField&&void 0!==e[this.elementField]},Tabulator.prototype.registerModule("dataTree",DataTree);