At this point, list views should need little introduction, but we are still going to discuss the attributes that can be used with them. Here is an example of a list view for our To-Do Tasks:
<record id="todo_app.view_tree_todo_task" model="ir.ui.view"> <field name="model">todo.task</field> <field name="arch" type="xml"> <tree decoration-muted="is_done" decoration-bf="state=='open'" delete="false"> <field name="name"/> <field name="user_id"/> <field name="is_done"/> <field name="state" invisible="1"/> </tree> </field> </record>
The row text color and font can change dynamically depending on the results of a Python expression evaluation. This is done through decoration–NAME
attributes, with the expression to evaluate based on field attributes. The NAME
part can be bf
or it
, for bold and italic fonts, or any Bootstrap text contextual colors: danger
, info
, muted
, primary
, success
, or warning
. The Bootstrap documentation has examples on how these are presented: http://getbootstrap.com/css/#helper-classes-colors.
Remember that fields used in expressions must be declared in a <field>
element, so that web client knows that that column needs to be retrieved from the server. If we don't want to have it displayed to the user, we should use the invisible="1"
attribute on it.
Other relevant attributes of the tree element are:
default_order
allows to override the model's default sort order, and its value follows the same format as in order attribute used in model definitions.create
, delete
, and edit
, if set to false
(in lowercase) disables the corresponding action on the list view.editable
makes records editable directly on the list view. Possible values are top
and bottom
, the location where the new records will be added.A list view can contain fields and buttons, and most of their attributes for forms are also valid here.
In list views, numeric fields can display summary values for their column. For this add to the field one of the available aggregation attributes, sum
, avg
, min
, or max
, and assign to it the label text for the summary value. For example:
<field name="amount" sum="Total Amount" />