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

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.

主站蜘蛛池模板: 突泉县| 靖西县| 莱州市| 琼结县| 柏乡县| 太原市| 工布江达县| 巨鹿县| 都安| 吐鲁番市| 马尔康县| 北宁市| 日土县| 云梦县| 岚皋县| 青神县| 无锡市| 甘孜| 新野县| 镶黄旗| 巫溪县| 星座| 利津县| 永靖县| 固镇县| 丽江市| 隆子县| 乌兰察布市| 炉霍县| 正安县| 盈江县| 天峻县| 合作市| 昂仁县| 宝鸡市| 丹凤县| 宜宾市| 霍城县| 麦盖提县| 于田县| 合作市|