cli-table / cli-table3

Pretty unicode tables for the command line
MIT License
534 stars 44 forks source link

Table is not formatted correctly #332

Closed orizzontiholding closed 9 months ago

orizzontiholding commented 10 months ago

I'm facing a problem with the table layout, I need to have 36 entry for the headers and the table will be not displayed correctly. Is there any option or any way I can use to get a well formatted table?

Here is the code I have at the moment.

                        let tableHead = ['stato dispositivo', 'nome host', 'nome dipendente', 'cognome dipendente', 'nome brand', 'codice filiale', 'marca dispositivo', 'modello dispositivo', 'matricola dispositivo', 'categoria dispositivo', 'locazione dispositivo', 'indirizzo ip', 'os dispositivo', 'os key', 'software_dispositivo', 'software_key', 'account software', 'cpu dispositivo', 'n core', 'ram', 'storage', 'anno', 'data consegna', 'numero tel', 'tipo sim', 'tipo contratto', 'opz internet', 'imei dispositivo', 'iccid dispositivo', 'fornitore dispositivo', 'valore dispositivo', 'tipo acquisto']
                        tableHead = tableHead.map( (h) => {
                            return h.toUpperCase()
                        });
                        let results = devicesList.filter( (el) => {
                            if( el.categoria_dispositivo  === answer ){
                                return el
                            }
                        });
                        let table = new Table({
                            head: tableHead,
                        });
                        for( let i = 0; i < results.length; i++ ){
                           table.push(Object.values(results[i]));
                        }
                        console.log(table.toString());
speedytwenty commented 9 months ago

The devicesList variable in your code is not defined so I can't attempt to produce whatever issue you're having.

I can generate a properly formatted 36 column table no problem:

image

So this is likely an issue with your implementation code. I'd advise looking at: table.push(Object.values(results[i]));

The array pushed into the table row should have 36 items ordered in correspondence with the headers.

Please reopen this issue with steps to reproduce if the row data is correct and the issue persists.