jedib0t / go-pretty

Table-writer and more in golang!
MIT License
3.06k stars 120 forks source link

Paging result not expected #312

Closed xjxl520303 closed 8 months ago

xjxl520303 commented 8 months ago

Describe the bug When using t.SetPageSize() method, the result page size and page number not right, and even show me some empty row data.

To Reproduce

Download Titanic data and convert to .xlsx, and saved to disk, then using Go Excelize lib to open and read some line, set paging.

package main

import (
    "fmt"
    "os"

    "github.com/jedib0t/go-pretty/v6/table"
    "github.com/xuri/excelize/v2"
)

func main() {
    f, err := excelize.OpenFile("E:\\ExcelDemo\\titanic.xlsx")
    if err != nil {
        fmt.Println(err)
        return
    }
    defer func() {
        if err := f.Close(); err != nil {
            fmt.Println(err)
        }
    }()
    rows, err := f.GetRows("titanic")
    if err != nil {
        fmt.Println(err)
        return
    }

    t := table.NewWriter()
    t.SetOutputMirror(os.Stdout)

    tableHeader := make(table.Row, 0)
    for _, cell := range rows[0] {
        tableHeader = append(tableHeader, cell)
    }
    t.AppendHeader(tableHeader)

    for _, row := range rows[1:7] {
        innerRow := make(table.Row, 0)
        for _, cell := range row {
            innerRow = append(innerRow, cell)
        }
        t.AppendRow(innerRow)
        t.AppendSeparator()
    }
    t.SetPageSize(2)
    t.Render()
}

Screenshots 企业微信截图_171212629498

Software (please complete the following information):

jedib0t commented 8 months ago

Hey @xjxl520303 thanks for identifying and reporting this bug in a easy-to-reproduce manner. Appreciate the details! 👍🏽

I've fixed this bug in https://github.com/jedib0t/go-pretty/releases/tag/v6.5.7 --- please try and let me know.

Just FYI, the issue was related to manually adding Separators with Paging.

xjxl520303 commented 8 months ago

@jedib0t tky fixed the bug, here is another bug I found https://github.com/jedib0t/go-pretty/issues/315