Skip to content

How to represnt this lua table? tbl = { ["x"] = "xxx", ["y"] = "yyy", ["z"] = "zzz"} #324

Discussion options

You must be logged in to vote

First convert your data shape:

local tbl = {
  ["1"] = "foo",
  ["2"] = "bar",
  ["3"] = "baz",
}

local data = {}

for id, name in pairs(tbl) do
  table.insert(data, { id = id, name = name })
end

--[[
local data = {
  { id = "1", name = "foo" },
  { id = "2", name = "bar" },
  { id = "3", name = "baz" },
}
--]]

Then update your table definition:

dada_table = NuiTable({
  bufnr = dada_pane.bufnr,
  columns = {
    {
      align = "center",
      header = "DADA",
      columns = {
        { accessor_key = "id", header = "ID" },
        { accessor_key = "name", header = "Name" },
      },
    },
  },
  data = data,
})

Ref: https://github.com/MunifTanjim/nui.nvim/blob/main/lua/nui/table/REA…

Replies: 5 comments 34 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by andreacfromtheapp
Comment options

You must be logged in to vote
1 reply
@MunifTanjim
Comment options

Comment options

You must be logged in to vote
10 replies
@andreacfromtheapp
Comment options

@MunifTanjim
Comment options

@andreacfromtheapp
Comment options

@MunifTanjim
Comment options

@andreacfromtheapp
Comment options

Comment options

You must be logged in to vote
10 replies
@MunifTanjim
Comment options

@andreacfromtheapp
Comment options

@MunifTanjim
Comment options

@andreacfromtheapp
Comment options

@andreacfromtheapp
Comment options

Comment options

You must be logged in to vote
13 replies
@andreacfromtheapp
Comment options

@andreacfromtheapp
Comment options

@andreacfromtheapp
Comment options

@MunifTanjim
Comment options

@andreacfromtheapp
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants