Skip to content
trendeverPublic

About

ajax select_one and select_many meta for qor (select2)

Resources

Stars

4 stars

Watchers

5 watching

Forks

Latest commit

 

History

25 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ajaxor

What it is

Ajaxor is a plugin for qor uses jQuery select2 selectors to load only necessary entries using REST api.

Usual select_one and select_many qor meta types are very plain: they generate <select> with an <option> for every selectable item. While they are extremely plain and simple, they bring us very big and slow pages (2MB of HTML and 2 seconds of download for an selector with 9000 entries). That makes them unsuitable for real enterprise use.

How to use it

Suppose, we have the following models:

type Parent struct {
  gorm.Model
  
  ChildID uint
  Child   Child
}

type Child struct {
  gorm.Model

  Name string
}

In order to make Ajaxor work we have to:

  1. Register Child resource in qor.

  2. Child model must implement qor.admin.ResourceNamer interface.

func (c Child) ResourceName() string {
  return "ChildResource"
}
  1. When adding the resource res to qor, call resource.Meta() wrapper:
  ajaxor.Meta(res, &admin.Meta{
  	Name: "Child",
  	Type: "select_one",
  })
  1. When using collection_edit edit control, specify .Resource field (your added to qor and probably invisible resource) in .Meta explitly.

  2. Ajax selects should now replace default ones

  3. There's also URL overriding mechanism available. In case you don't have a separate Visible resource for Child model, you can still make it clickable:

func (c Child) GetURLValue() interface{} {
  // return parent stub
  return Parent{Model: gorm.Model{ID: c.ParentID}}
}

Current issues

  • Does not use standard material-design theme.

License

Released under the MIT License.

About

ajax select_one and select_many meta for qor (select2)

Resources

Stars

4 stars

Watchers

5 watching

Forks

Releases

Packages

Contributors

Languages

⌂ 换网址