Documentation
¶
Overview ¶
Package list implements creation of lists (old tablelist).
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Build ¶
Build is responsible to receive a collection of objects that implements Listable and build the rows of TableList. This method should be used in case of a collection of values.
Example ¶
ExampleBuild demonstrates how to create a list of rows based into an array of objects.
/*
// Obj implements Listable interface
type Obj struct {
ID int
Name string
}
// GetHeader is a method from Listable interface to create a header row
// based in an array element.
func (o Obj) GetHeader() core.Row {
idCol := text.NewCol(6, "ID")
nameCol := text.NewCol(6, "Name")
return row.New(5).Add(idCol, nameCol)
}
// GetContent is a method from Listable interface to create a row
// based in an array element.
// i is the current index of the object list to be added into a row
// this can be used to customize pair/odd rows.
func (o Obj) GetContent(_ int) core.Row {
idCol := text.NewCol(6, fmt.Sprintf("%d", o.ID))
nameCol := text.NewCol(6, o.Name)
return row.New(5).Add(idCol, nameCol)
}
*/
objs := []Obj{
{
ID: 0,
Name: "obj name 0",
},
{
ID: 1,
Name: "obj name 1",
},
}
rows, _ := list.Build[Obj](objs)
m := maroto.New()
m.AddRows(rows...)
// generate document
func BuildFromPointer ¶
BuildFromPointer is responsible to receive a collection of objects that implements Listable and build the rows of TableList. This method should be used in case of a collection of pointers.
Example ¶
ExampleBuild demonstrates how to create a list of rows based into an array of pointer objects.
/*
// Obj implements Listable interface
type Obj struct {
ID int
Name string
}
// GetHeader is a method from Listable interface to create a header row
// based in an array element.
func (o Obj) GetHeader() core.Row {
idCol := text.NewCol(6, "ID")
nameCol := text.NewCol(6, "Name")
return row.New(5).Add(idCol, nameCol)
}
// GetContent is a method from Listable interface to create a row
// based in an array element.
// i is the current index of the object list to be added into a row
// this can be used to customize pair/odd rows.
func (o Obj) GetContent(_ int) core.Row {
idCol := text.NewCol(6, fmt.Sprintf("%d", o.ID))
nameCol := text.NewCol(6, o.Name)
return row.New(5).Add(idCol, nameCol)
}
*/
objs := []*Obj{
{
ID: 0,
Name: "obj name 0",
},
{
ID: 1,
Name: "obj name 1",
},
}
rows, _ := list.BuildFromPointer[Obj](objs)
m := maroto.New()
m.AddRows(rows...)
// generate document
Types ¶
Click to show internal directories.
Click to hide internal directories.