render() {
        var allKeys = Object.keys(this.data[0])

        // Create columns names (from keys)
        for (var i = 0; i < allKeys.length; i++) {
            var newKey = document.createElement('div')
            newKey.innerHTML = `
            <style>
            .gus_dt_key {
                height: 100%;
                min-width: 80px;

                margin-left: 10px;

                display: grid;
                align-content: center;
            }
            </style>
            <div class="gus_dt_key" part="column-name">
                ${allKeys[i]}
            </div>
            `
            this.header.appendChild(newKey)
        }

        // Display the elements
        for (var i = 0; i < this.displayLimit; i++) {
            var newRow = this.createRow()
            var rowInsert = newRow.children[1]
            // Add the cells to the row
            for (var n = 0; n < allKeys.length; n++) {
                var newCell = this.createCell(this.data[i][allKeys[n]])
                rowInsert.appendChild(newCell)
            }
            this.content.appendChild(newRow)
        }

        // Resize the cells
        for (var i = 0; i < allKeys.length; i++) { // For each column
            var largestCellSize = 0;

            // Get the largest cell
            for (var cell = 0; cell < this.displayLimit; cell++) { // For each cell
                // Get the cell
                var actualCell = this.content.children[cell].children[1].children[i]

                // Compare its size
                if (actualCell.clientWidth > largestCellSize) {
                    largestCellSize = actualCell.clientWidth
                }
            }

            // Apply the biggest width to each cell
            for (var cell = 0; cell < this.displayLimit; cell++) { // For each cell
                // Get the cell
                var actualCell = this.content.children[cell].children[1].children[i]

                actualCell.style.width = `${largestCellSize + 10}px`

                this.header.children[i].style.width = `${largestCellSize + 10}px`
            }
        }
    }
// Re-render the whole data table
Re-render the whole data table
Re - render the whole data table
render() {
        var allKeys = Object.keys(this.data[0])
        for (var i = 0; i < allKeys.length; i++) {
            var newKey = document.createElement('div')
            newKey.innerHTML = `
            <style>
            .gus_dt_key {
                height: 100%;
                min-width: 80px;
                margin-left: 10px;
                display: grid;
                align-content: center;
            }
            </style>
            <div class="gus_dt_key" part="column-name">
                ${allKeys[i]}
            </div>
            `
            this.header.appendChild(newKey)
        }
        for (var i = 0; i < this.displayLimit; i++) {
            var newRow = this.createRow()
            var rowInsert = newRow.children[1]
            for (var n = 0; n < allKeys.length; n++) {
                var newCell = this.createCell(this.data[i][allKeys[n]])
                rowInsert.appendChild(newCell)
            }
            this.content.appendChild(newRow)
        }
        for (var i = 0; i < allKeys.length; i++) { 
            var largestCellSize = 0;
            for (var cell = 0; cell < this.displayLimit; cell++) { 
                var actualCell = this.content.children[cell].children[1].children[i]
                if (actualCell.clientWidth > largestCellSize) {
                    largestCellSize = actualCell.clientWidth
                }
            }
            for (var cell = 0; cell < this.displayLimit; cell++) { 
                var actualCell = this.content.children[cell].children[1].children[i]
                actualCell.style.width = `${largestCellSize + 10}px`
                this.header.children[i].style.width = `${largestCellSize + 10}px`
            }
        }
    }
render ( ) { var allKeys = Object . keys ( this . data [ 0 ] ) for ( var i = 0 ; i < allKeys . length ; i ++ ) { var newKey = document . createElement ( 'div' ) newKey . innerHTML = ` ${ allKeys [ i ] } ` this . header . appendChild ( newKey ) } for ( var i = 0 ; i < this . displayLimit ; i ++ ) { var newRow = this . createRow ( ) var rowInsert = newRow . children [ 1 ] for ( var n = 0 ; n < allKeys . length ; n ++ ) { var newCell = this . createCell ( this . data [ i ] [ allKeys [ n ] ] ) rowInsert . appendChild ( newCell ) } this . content . appendChild ( newRow ) } for ( var i = 0 ; i < allKeys . length ; i ++ ) { var largestCellSize = 0 ; for ( var cell = 0 ; cell < this . displayLimit ; cell ++ ) { var actualCell = this . content . children [ cell ] . children [ 1 ] . children [ i ] if ( actualCell . clientWidth > largestCellSize ) { largestCellSize = actualCell . clientWidth } } for ( var cell = 0 ; cell < this . displayLimit ; cell ++ ) { var actualCell = this . content . children [ cell ] . children [ 1 ] . children [ i ] actualCell . style . width = ` ${ largestCellSize + 10 } ` this . header . children [ i ] . style . width = ` ${ largestCellSize + 10 } ` } } }
Re-render the whole data table
Re - render the whole data table
// Create columns names (from keys) // Display the elements // Add the cells to the row // Resize the cells // For each column // Get the largest cell // For each cell // Get the cell // Compare its size // Apply the biggest width to each cell // For each cell // Get the cell