if ($MWGUI != null) { $MWGUI.NewTable = function(ElementContainer,OptionsReceived) { let Options; if(OptionsReceived) { Options = OptionsReceived; } else { Options = {}; Options.EnableScrollPagination = false; Options.ScrollPaginationFunction = null; } var Table = document.createElement("div"); Table.style.overflow="hidden"; Table.className = "column-direction relative-full-height relative-full-width"; Table.ColumnList=new Array(); Table.RowList = new Array(); var ToolbarContainer = document.createElement("div"); ToolbarContainer.className ="relative-full-width resgui-1row align-items-center"; ToolbarContainer.style.display = "none"; Table.Toolbar = ToolbarContainer; Table.appendChild(ToolbarContainer); Table.ShowToolbar = function() { Table.Toolbar.style.display ="flex"; TableContent.style.minHeight = "calc(100% - var(--resgui-2row))"; } Table.HideToolbar = function() { Table.Toolbar.style.display ="none"; TableContent.style.minHeight = "calc(100% - var(--resgui-1row))"; } var HeaderRow = document.createElement("div"); HeaderRow.className = "row-direction resgui-1row decor-solid-border-bottom-group-header-color" HeaderRow.style.backgroundColor ="var(--table-header-column-background)"; HeaderRow.style.minWidth ="100%"; Table.appendChild(HeaderRow); var HeaderFixedContainer = document.createElement("div"); HeaderFixedContainer.className="relative-full-height"; HeaderRow.appendChild(HeaderFixedContainer); var HeaderContainer = document.createElement("div"); HeaderContainer.className="relative-full-height"; HeaderContainer.style.overflow ="hidden"; HeaderRow.appendChild(HeaderContainer); var TableContent = document.createElement("div"); TableContent.style.minHeight = "calc(100% - var(--resgui-1row))"; Table.appendChild(TableContent); var FixedColumns = document.createElement("div"); FixedColumns.style.height="calc(100% - 17px)"; FixedColumns.style.overflow="hidden"; TableContent.appendChild(FixedColumns); var Columns = document.createElement("div"); Columns.className ="relative-full-height"; Columns.style.overflow = "scroll"; Columns.lastScrollTop = 0; Columns.addEventListener("scroll", function(event){ var st = window.pageYOffset || Columns.scrollTop; if (st > this.lastScrollTop){ FixedColumns.scrollTop = Columns.scrollTop; //HeaderContainer.scrollLeft = Columns.scrollLeft; if(Options.EnableScrollPagination) if(Options.ScrollPaginationFunction != null) { if (Columns.offsetHeight + Columns.scrollTop >= Columns.scrollHeight) { Options.ScrollPaginationFunction(event); } } } else { // upscroll code } this.lastScrollTop = st <= 0 ? 0 : st; HeaderContainer.scrollLeft = Columns.scrollLeft; }); TableContent.appendChild(Columns); Table.AddFixedColumn = function(Label, columnSize) { if (columnSize == null) columnSize = 5; if (columnSize == undefined) columnSize = 5; var Header = document.createElement("div"); HeaderFixedContainer.appendChild(Header); Header.className = " relative-full-height align-items-center decor-solid-border-right-group-header-color"; Header.Label = Label; var Column = document.createElement("div"); Column.Fixed = true; Column.className = " relative-full-height column-direction " FixedColumns.appendChild(Column); var RefCol = new Object(); RefCol.Header = Header; RefCol.Column = Column; RefCol.Cells = new Array(); Header.Column = RefCol; Column.Column = RefCol; Table.ColumnList.push(RefCol); for(var i in Table.RowList) { var Cell = document.createElement("div"); Cell.className="relative-full-width resgui-three-quarter-row decor-solid-border-bottom-group-header-color decor-solid-border-right-group-header-color"; Table.RowList[i].Cells.push(Cell); Cell.Row = Table.RowList[i]; Column.appendChild(Cell); RefCol.Cells.push(Cell); Cell.Column = RefCol; } Table.ColumnSetWidth(RefCol, columnSize); return RefCol; } Table.ColumnSetWidth= function(RefCol, columnSize) { var resguiValue = "resgui-5column"; switch(columnSize) { case 1: {resguiValue = " resgui-1column "; break; } case 2: {resguiValue = " resgui-2column "; break; } case 3: {resguiValue = " resgui-3column "; break; } case 4: {resguiValue = " resgui-4column "; break; } case 6: {resguiValue = " resgui-6column "; break; } case 7: {resguiValue = " resgui-7column "; break; } case 8: {resguiValue = " resgui-8column "; break; } case 9: {resguiValue = " resgui-9column "; break; } case 10: {resguiValue = " resgui-10column "; break; } case 11: {resguiValue = " resgui-11column "; break; } case 12: {resguiValue = " resgui-12column "; break; } case 13: {resguiValue = " resgui-13column "; break; } case 14: {resguiValue = " resgui-14column "; break; } case 15: {resguiValue = " resgui-15column "; break; } case 16: {resguiValue = " resgui-16column "; break; } case 17: {resguiValue = " resgui-17column "; break; } case 18: {resguiValue = " resgui-18column "; break; } case 19: {resguiValue = " resgui-19column "; break; } case 20: {resguiValue = " resgui-20column "; break; } default: {resguiValue = " resgui-5column "; break;} } if (RefCol.columnSize != null) { switch(RefCol.columnSize) { case 1: {RefCol.Header.className = RefCol.Header.className.replace(" resgui-1column ",""); RefCol.Column.className = RefCol.Column.className.replace(" resgui-1column ",""); break; } case 2: {RefCol.Header.className = RefCol.Header.className.replace(" resgui-2column ",""); RefCol.Column.className = RefCol.Column.className.replace(" resgui-2column ",""); break; } case 3: {RefCol.Header.className = RefCol.Header.className.replace(" resgui-3column ",""); RefCol.Column.className = RefCol.Column.className.replace(" resgui-3column ",""); break; } case 4: {RefCol.Header.className = RefCol.Header.className.replace(" resgui-4column ",""); RefCol.Column.className = RefCol.Column.className.replace(" resgui-4column ",""); break; } case 6: {RefCol.Header.className = RefCol.Header.className.replace(" resgui-6column ",""); RefCol.Column.className = RefCol.Column.className.replace(" resgui-6column ",""); break; } case 7: {RefCol.Header.className = RefCol.Header.className.replace(" resgui-7column ",""); RefCol.Column.className = RefCol.Column.className.replace(" resgui-7column ",""); break; } case 8: {RefCol.Header.className = RefCol.Header.className.replace(" resgui-8column ",""); RefCol.Column.className = RefCol.Column.className.replace(" resgui-8column ",""); break; } case 9: {RefCol.Header.className = RefCol.Header.className.replace(" resgui-9column ",""); RefCol.Column.className = RefCol.Column.className.replace(" resgui-9column ",""); break; } case 10: {RefCol.Header.className = RefCol.Header.className.replace(" resgui-10column ",""); RefCol.Column.className = RefCol.Column.className.replace(" resgui-10column ",""); break; } case 11: {RefCol.Header.className = RefCol.Header.className.replace(" resgui-11column ",""); RefCol.Column.className = RefCol.Column.className.replace(" resgui-11column ",""); break; } case 12: {RefCol.Header.className = RefCol.Header.className.replace(" resgui-12column ",""); RefCol.Column.className = RefCol.Column.className.replace(" resgui-12column ",""); break; } case 13: {RefCol.Header.className = RefCol.Header.className.replace(" resgui-13column ",""); RefCol.Column.className = RefCol.Column.className.replace(" resgui-13column ",""); break; } case 14: {RefCol.Header.className = RefCol.Header.className.replace(" resgui-14column ",""); RefCol.Column.className = RefCol.Column.className.replace(" resgui-14column ",""); break; } case 15: {RefCol.Header.className = RefCol.Header.className.replace(" resgui-15column ",""); RefCol.Column.className = RefCol.Column.className.replace(" resgui-15column ",""); break; } case 16: {RefCol.Header.className = RefCol.Header.className.replace(" resgui-16column ",""); RefCol.Column.className = RefCol.Column.className.replace(" resgui-16column ",""); break; } case 17: {RefCol.Header.className = RefCol.Header.className.replace(" resgui-17column ",""); RefCol.Column.className = RefCol.Column.className.replace(" resgui-17column ",""); break; } case 18: {RefCol.Header.className = RefCol.Header.className.replace(" resgui-18column ",""); RefCol.Column.className = RefCol.Column.className.replace(" resgui-18column ",""); break; } case 19: {RefCol.Header.className = RefCol.Header.className.replace(" resgui-19column ",""); RefCol.Column.className = RefCol.Column.className.replace(" resgui-19column ",""); break; } case 20: {RefCol.Header.className = RefCol.Header.className.replace(" resgui-20column ",""); RefCol.Column.className = RefCol.Column.className.replace(" resgui-20column ",""); break; } default: {RefCol.Header.className = RefCol.Header.className.replace(" resgui-5column ",""); RefCol.Column.className = RefCol.Column.className.replace(" resgui-5column ",""); break; } } } RefCol.Header.className += resguiValue; RefCol.columnSize = columnSize; RefCol.Column.className += resguiValue; Table.ColumnsWidth(); } Table.ColumnsWidth = function() { var FixedWidth = 0; for(var i in FixedColumns.childNodes) { if (FixedColumns.childNodes[i].tagName != undefined) FixedWidth += FixedColumns.childNodes[i].offsetWidth; } Columns.style.width="calc(" + window.innerWidth+ "px - " + FixedWidth + "px)"; FixedWidth +=17; HeaderContainer.style.width="calc(" + window.innerWidth+ "px - " + FixedWidth + "px)"; } Table.AddColumn = function(Label, columnSize) { if (columnSize == null) columnSize = 5; if (columnSize == undefined) columnSize = 5; var Header = document.createElement("div"); HeaderContainer.appendChild(Header); Header.className = " relative-full-height align-items-center decor-solid-border-right-group-header-color"; Header.Label = Label var Column = document.createElement("div"); Column.Fixed = false; Column.className =" relative-full-height column-direction " Columns.appendChild(Column); var RefCol = new Object(); RefCol.Header = Header; RefCol.Column = Column; RefCol.Cells = new Array(); Header.Column = RefCol; Column.Column = RefCol; Table.ColumnList.push(RefCol); for(var i in Table.RowList) { var Cell = document.createElement("div"); Cell.className = "relative-full-width resgui-three-quarter-row decor-solid-border-bottom-group-header-color decor-solid-border-right-group-header-color"; Table.RowList[i].Cells.push(Cell); Cell.Row = Table.RowList[i]; Column.appendChild(Cell); Cell.Column = RefCol; RefCol.Cells.push(Cell); } Table.ColumnSetWidth(RefCol, columnSize); return RefCol; } Table.DeleteColumn= function(Column) { if (Column == null) return; if (Column.Cells == null) return; var Index = Table.ColumnList.indexOf(Column); if (Index !== -1) Table.ColumnList.splice(Index,1); Column.Column.parentNode.removeChild(Column.Column); Column.Header.parentNode.removeChild(Column.Header); Table.ColumnsWidth(); } Table.ShiftRightColumn = function(Column) { if (Column == null) return; if (Column.Column == null) return; if (Column.Column.nextSibling == null) return; var oldcol = Column.Column.nextSibling.nextSibling; oldhea = Column.Header.nextSibling.nextSibling; Column.Column.parentNode.insertBefore(Column.Column.parentNode.removeChild(Column.Column), oldcol); Column.Header.parentNode.insertBefore(Column.Header.parentNode.removeChild(Column.Header), oldhea); var pos = Table.ColumnList.indexOf(Column); Table.ColumnList.splice(pos,1); Table.ColumnList.splice(pos+1,0, Column); for (var iRow in Table.RowList) { var OriginalCell = Table.RowList[iRow].Cells[pos]; Table.RowList[iRow].Cells.splice(pos,1); Table.RowList[iRow].Cells.splice(pos + 1,0, OriginalCell); } } Table.ShiftLeftColumn = function(Column) { if (Column == null) return; if (Column.Column == null) return; if (Column.Column.previousSibling == null) return; var oldcol = Column.Column.previousSibling; oldhea = Column.Header.previousSibling; Column.Column.parentNode.insertBefore(Column.Column.parentNode.removeChild(Column.Column), oldcol); Column.Header.parentNode.insertBefore(Column.Header.parentNode.removeChild(Column.Header), oldhea); var pos =Table.ColumnList.indexOf(Column); Table.ColumnList.splice(pos,1); Table.ColumnList.splice(pos - 1,0,Column); for (var iRow in Table.RowList) { var OriginalCell = Table.RowList[iRow].Cells[pos]; Table.RowList[iRow].Cells.splice(pos, 1); Table.RowList[iRow].Cells.splice(pos - 1,0, OriginalCell); } } Table.AddRow = function() { var Row = new Object(); Row.Cells = new Array(); Table.RowList.push(Row); for( var Col in Table.ColumnList) { var Cell = document.createElement("div"); Cell.className="relative-full-width resgui-three-quarter-row decor-solid-border-bottom-group-header-color decor-solid-border-right-group-header-color"; Table.ColumnList[Col].Column.appendChild(Cell); Table.ColumnList[Col].Cells.push(Cell); Cell.Row = Row; Cell.Column = Table.ColumnList[Col]; Row.Cells.push(Cell); } return Row; } Table.AddRowAtIndex = function(Index) { var Row = new Object(); Row.Cells = new Array(); for( var Col in Table.ColumnList) { var Cell = document.createElement("div"); Cell.className="relative-full-width resgui-three-quarter-row decor-solid-border-bottom-group-header-color decor-solid-border-right-group-header-color"; if(Table.ColumnList[Col].Cells.length > Index) { Table.ColumnList[Col].Column.insertBefore(Cell, Table.ColumnList[Col].Cells[Index]); Table.ColumnList[Col].Cells.splice(Index, 0, Cell); } else { Table.ColumnList[Col].Column.appendChild(Cell); Table.ColumnList[Col].Cells.push(Cell); } Cell.Row = Row; Cell.Column = Table.ColumnList[Col]; Row.Cells.push(Cell); } if(Table.RowList.length > Index) Table.RowList.splice(Index, 0, Row); else Table.RowList.push(Row); return Row; } Table.DeleteRow = function(Row) { if (Row == null) return; if (Row.Cells == null) return; var Index = Table.RowList.indexOf(Row); if (Index !== -1) Table.RowList.splice(Index,1); for (var i in Row.Cells) { if(Row.Cells[i].parentNode == null) continue; Row.Cells[i].parentNode.removeChild(Row.Cells[i]); for( var Col in Table.ColumnList) { Index = Table.ColumnList[Col].Cells.indexOf(Row.Cells[i]); if (Index !== -1) { Table.ColumnList[Col].Cells.splice(Index, 1); } } } } Table.ShiftTopRow = function(Row) { if (Row == null) return; if (Row.Cells == null) return; for(var Cell in Row.Cells) { var prevRow = Row.Cells[Cell].previousSibling; if (prevRow == null) return; Row.Cells[Cell].parentNode.insertBefore(Row.Cells[Cell].parentNode.removeChild(Row.Cells[Cell]), prevRow); } } Table.ShiftBottomRow = function(Row) { if (Row == null) return; if (Row.Cells == null) return; for(var Cell in Row.Cells) { var prevRow = Row.Cells[Cell].nextSibling; if (prevRow == null) return; var prevRow = prevRow.nextSibling; if (prevRow == null) { Row.Cells[Cell].parentNode.appendChild( Row.Cells[Cell].parentNode.removeChild(Row.Cells[Cell])); } else Row.Cells[Cell].parentNode.insertBefore(Row.Cells[Cell].parentNode.removeChild(Row.Cells[Cell]), prevRow); } } Table.ClearAllRows = function() { for(var i =Table.RowList.length - 1; i>=0; i--) { Table.DeleteRow(Table.RowList[i]); } } if (ElementContainer != null) ElementContainer.appendChild(Table); return Table; }; } else console.log("This library is an extention of Prime.GUI.js Framework. Add script reference to this library!!!");