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

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.

主站蜘蛛池模板: 沙湾县| 开江县| 冷水江市| 聂拉木县| 湟中县| 含山县| 烟台市| 垣曲县| 天柱县| 全南县| 大庆市| 建平县| 兴化市| 湖南省| 噶尔县| 小金县| 湖州市| 名山县| 迁安市| 若尔盖县| 盖州市| 光山县| 蓬安县| 新源县| 务川| 富裕县| 武强县| 广平县| 滕州市| 嵊州市| 鄂托克前旗| 绿春县| 元阳县| 六盘水市| 称多县| 南江县| 博爱县| 晋江市| 永清县| 五华县| 鹤壁市|