ExAdmin v0.8.3-build.2 ExAdmin.Show
Override the default show page for an ExAdmin resource.
By default, ExAdmin renders the show page without any additional configuration. It renders each column in the model, except the id, inserted_at, and updated_at columns in an attributes table.
To customize the show page, use the show
macro.
Examples
register_resource Survey.Seating do
show seating do
attributes_table do
row :id
row :name
row :image, [image: true, height: 100], &(ExAdminDemo.Image.url({&1.image, &1}, :thumb))
end
panel "Answers" do
table_for(seating.answers) do
column "Question", fn(answer) ->
"#{answer.question.name}"
end
column "Answer", fn(answer) ->
"#{answer.choice.name}"
end
end
end
end
Summary
Macros
Add a select box to add N:M associations to the resource on show page
Add a select box to add N:M associations to the resource on show page
Display a table of the model’s default attributes
Display a table of the model’s attributes
Display a table of a specific model’s attributes
Add a markup block to a form
Adds a new panel to the show page
Customize the show page
Add a table for a :has_many
association or a list of maps
Functions
Macros
Add a select box to add N:M associations to the resource on show page.
Options
resource_key
- foreign key in the intersection table for resource modelassoc_name
- name of associationassoc_key
- foreign key in the intersection table for association modelassoc_model
- association Ecto modelautocomplete
- preload all possible associations iffalse
and use autocomplete iftrue
Examples
show post do
attributes_table
panel "Tags" do
table_for(post.post_tags) do
column :tag
end
markup_contents do
association_filler(post, resource_key: "post_id", assoc_name: "tags",
assoc_key: "tag_id", autocomplete: false)
end
end
end
Add a select box to add N:M associations to the resource on show page.
Note: If you have custom keys in intersection table, please use association_filler/2 to specify them explicit.
Examples
show post do
attributes_table
panel "Tags" do
table_for(post.post_tags) do
column :tag
end
markup_contents do
association_filler post, :tags, autocomplete: true
end
end
end
Display a table of the model’s default attributes.
Examples
# all fields except :id, :inserted_at, :updated_at
attributes_table
Display a table of the model’s attributes.
When called with a block, the rows specified in the block will be displayed.
When called without a block, the default attributes table will be displayed.
Call with opts:
only: list
- select which fields to show.except: field_list
- select which fields to exclude.all: true
- include fields :id, :inserted_at, :updated_at which are excluded by default.
Examples
# only fields :name and :email
attributes_table do
row :name
row :email
end
# all fields including :id, :inserted_at, :updated_at
attributes_table all: true
# only fields :name and :email
attributes_table only: [:name, :email]
# all fields except :password, :id, :inserted_at, :updated_at
attributes_table except: [:password]
# all fields except :password
attributes_table except: [:password], all: true
Display a table of a specific model’s attributes.
When called with a block, the rows specified in the block will be displayed.
When called without a block, the default attributes table will be displayed.
Add a markup block to a form.
Allows the use of the Xain markup to be used in a panel.
Examples
show user do
attributes_table
panel "Testing" do
markup_contents do
div ".my-class" do
test "Tesing"
end
end
end
Adds a new panel to the show page.
The block given must include one of two commands:
table_for
- Displays a table for a:has_many
association.contents
- Add HTML to a panel
Customize the show page.
Refer to the other examples in this Module.
Example
register_resource MyProject.User do
show user do
attributes_table
end
end
Add a table for a :has_many
association or a list of maps.
Examples
has_many association
show account do
attributes_table do
row :username
row :email
row :contact
end
panel "Inventory" do
table_for account.inventory do
column "Asset", &__MODULE__.inventory_name/1
column "PO", &(&1.sales_order.po)
column :quantity
end
end
end
Array of maps
show user do
attributes_table do
row :name
end
panel "Addresses" do
table_for user.addresses do
column :street
column :city
end
end
end