github.com/kotovmak/go-admin@v1.1.1/tests/tables/authors.go (about) 1 package tables 2 3 import ( 4 "github.com/kotovmak/go-admin/context" 5 "github.com/kotovmak/go-admin/modules/db" 6 "github.com/kotovmak/go-admin/plugins/admin/modules/table" 7 "github.com/kotovmak/go-admin/template/types/form" 8 ) 9 10 // GetAuthorsTable return the model of table author. 11 func GetAuthorsTable(ctx *context.Context) (authorsTable table.Table) { 12 13 authorsTable = table.NewDefaultTable(table.DefaultConfig()) 14 15 // connect your custom connection 16 // authorsTable = table.NewDefaultTable(table.DefaultConfigWithDriverAndConnection("mysql", "admin")) 17 18 info := authorsTable.GetInfo() 19 info.AddField("ID", "id", db.Int).FieldSortable() 20 info.AddField("First Name", "first_name", db.Varchar) 21 info.AddField("Last Name", "last_name", db.Varchar) 22 info.AddField("Email", "email", db.Varchar) 23 info.AddField("Birthdate", "birthdate", db.Date) 24 info.AddField("Added", "added", db.Timestamp) 25 26 info.SetTable("authors").SetTitle("Authors").SetDescription("Authors") 27 28 formList := authorsTable.GetForm() 29 formList.AddField("ID", "id", db.Int, form.Default).FieldDisplayButCanNotEditWhenUpdate().FieldDisableWhenCreate() 30 formList.AddField("First Name", "first_name", db.Varchar, form.Text) 31 formList.AddField("Last Name", "last_name", db.Varchar, form.Text) 32 formList.AddField("Email", "email", db.Varchar, form.Text) 33 formList.AddField("Birthdate", "birthdate", db.Date, form.Text) 34 formList.AddField("Added", "added", db.Timestamp, form.Text) 35 36 formList.SetTable("authors").SetTitle("Authors").SetDescription("Authors") 37 38 return 39 }