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.
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:
-
Register Child resource in qor.
-
Child model must implement qor.admin.ResourceNamer interface.
func (c Child) ResourceName() string {
return "ChildResource"
}- When adding the resource
resto qor, call resource.Meta() wrapper:
ajaxor.Meta(res, &admin.Meta{
Name: "Child",
Type: "select_one",
})-
When using collection_edit edit control, specify .Resource field (your added to qor and probably invisible resource) in .Meta explitly.
-
Ajax selects should now replace default ones
-
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}}
}- Does not use standard material-design theme.
Released under the MIT License.