Search code examples
gouser-interfacefyne

Fyne Table not showing data initially


I have a Fyne table that I am populating with data

type transaction struct {
    Name   string
    Amount float64
    Date   time.Time
    Memo   string
}

var transactions []transaction

func init() {// Data population omitted }

func makeCenter() *fyne.Container {
    table := widget.NewTable(
        func() (int, int) {
            return len(transactions), 4
        },
        func() fyne.CanvasObject {
            return widget.NewLabel("wide content")
        },
        func(i widget.TableCellID, o fyne.CanvasObject) {
            switch i.Col {
            case 0:
                o.(*widget.Label).SetText(transactions[i.Row].Name)
            case 1:
                o.(*widget.Label).SetText(transactions[i.Row].Date.Format(YYYYMMDD))
            case 2:
                o.(*widget.Label).SetText(fmt.Sprintf("%.2f", transactions[i.Row].Amount))
            case 3:
                o.(*widget.Label).SetText(transactions[i.Row].Memo)
            }
        },
    )
    table.SetColumnWidth(0, 200)
    table.SetColumnWidth(1, 100)
    table.SetColumnWidth(2, 100)
    table.SetColumnWidth(3, 300)
    split := container.NewHSplit(makeLeftSidebar(), table)
    split.Offset = 0.2
    return container.NewMax(split)
}

When my window initially is displayed, the table has no data enter image description here

If I click in any cell, the data populates enter image description here

I have run this through the debugger and have found that the NewTable's create function does not get called when the UI is created. Only after a click do I get a break in the create function.

[Update] This issue is a known bug and is referenced at https://github.com/fyne-io/fyne/issues/3198 and https://github.com/fyne-io/fyne/issues/3034.


Solution

  • Sounds like something that should be listed in the bug tracker on GitHub rather than here…