authors.go 1.5 KB

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