The list helper generates a sequence of rows from a Go slice, automatically prepending a header row. This is useful for creating tabular data like invoices, reports, or catalogs.
To use this helper, your data items must implement the Listable interface. The helper provides two main functions depending on whether you are using a slice of values or a slice of pointers:
list.Build[T Listable](arr []T): Use this for slices of values ([]T).list.BuildFromPointer[T Listable](arr []*T): Use this for slices of pointers ([]*T). This is necessary because Go generics cannot automatically dereference pointers.
Integration:
Pass the returned []core.Row directly to the Maroto instance method m.AddRows(rows...).
Important Notes:
- Header Generation: The header row is automatically produced by calling
GetHeader() on the first element of the slice. - Errors: Both functions return an error if the slice is empty (
ErrEmptyArray) or if a pointer element in the slice is nil (ErrNilElementInArray).