官术网_书友最值得收藏!

Adding list and search views

When viewing a model in list mode, a <tree> view is used. Tree views are capable of displaying lines organized in hierarchies, but most of the time they are used to display plain lists.

We can add the following <tree> view definition to todo_view.xml:

<record id="view_tree_todo_task" model="ir.ui.view"> 
  <field name="name">To-do Task Tree</field> 
  <field name="model">todo.task</field> 
  <field name="arch" type="xml"> 
    <tree colors="decoration-muted:is_done==True"> 
      <field name="name"/> 
      <field name="is_done"/> 
    </tree> 
  </field> 
</record> 

This defines a list with only two columns: name and is_done. We also added a nice touch: the lines for done tasks (is_done==True) are shown as grayed out. This is done by applying the muted Bootstrap class. Check http://getbootstrap.com/docs/3.3/css/#helper-classes-colors for more information on Bootstrap and its contextual colors.

Because is_done is a Boolean field, the "decoration-muted:is_done==True" can elegantly be simplified to "decoration-muted:is_done". Try it!

At the top-right corner of the list, Odoo displays a search box. The fields it searches in and the available filters are defined by a <search> view.

As before, we will add this to todo_view.xml:

<record id="view_filter_todo_task" model="ir.ui.view"> 
  <field name="name">To-do Task Filter</field> 
  <field name="model">todo.task</field> 
  <field name="arch" type="xml"> 
    <search> 
      <field name="user_id"/> 
      <filter string="Not Done" 
        domain="[('is_done','=',False)]"/> 
      <filter string="Done" 
        domain="[('is_done','!=',False)]"/> 
    </search> 
  </field> 
</record> 

The <field> elements define fields that are also searched when typing in the search box. We added user_id to automatically suggest searching in the Responsible field. The <filter> elements add predefined filter conditions, which can be toggled with a user click, defined using a specific syntax. This will be addressed in more detail in Chapter 9, Backend Views - Design the User Interface.

主站蜘蛛池模板: 高青县| 阜康市| 昌黎县| 鹤壁市| 蒲城县| 潞城市| 乌拉特中旗| 岳阳市| 潜江市| 滁州市| 浑源县| 拉孜县| 吉安市| 榆社县| 日喀则市| 马边| 手游| 山西省| 尤溪县| 双辽市| 洛隆县| 南安市| 眉山市| 阿荣旗| 仁寿县| 富锦市| 金昌市| 资溪县| 余庆县| 牙克石市| 章丘市| 成都市| 佛坪县| 株洲县| 榆树市| 九龙县| 阜新| 于都县| 遂溪县| 甘肃省| 清原|