跳转到主要内容

允许您根据记录中的数据动态着色树视图中的字段

项目描述

Beta License: AGPL-3 OCA/web Translate me on Weblate Try me on Runboat

本模块旨在为树视图中根据记录中的数据动态着色字段提供支持。

它为字段提供了类似于树标签中“colors”属性的语法属性。

此外,它还为树标签的“colors”提供了“color_field”属性,用于使用字段值作为颜色。

功能

  • 在字段“options”上添加属性“bg_color”,以在树视图中着色单元格的背景

  • 在字段“options”上添加属性“fg_color”,以更改树视图中单元格的文本颜色

  • 在树元素的“colors”上添加属性“color_field”,用作文本颜色

  • 在树元素的“colors”上添加属性“bg_color_field”,用作背景颜色

目录表

用法

  • 在树视图声明中,将options='{"bg_color": "red: customer==True"}属性放入field标签中

    ...
    <field name="arch" type="xml">
        <tree string="View name">
            ...
            <field name="name" options='{"bg_color": "red: customer == True"}'/>
            ...
        </tree>
    </field>
    ...
    
    With this example, column which renders 'name' field will have its background colored in red.
  • 在树视图声明中,将options='{"fg_color": "white:customer == True"}'属性放入field标签中

    ...
    <field name="arch" type="xml">
        <tree string="View name">
            ...
            <field name="name" options='{"fg_color": "white:customer == True"}'/>
            ...
        </tree>
    </field>
    ...
    
    With this example, column which renders 'name' field will have its text colored in white on a customer records.
  • 在树形视图声明中,请在 tree 标签中使用 options='"color_field": "my_color"' 属性。

    ...
    <field name="arch" type="xml">
        <tree string="View name" colors="color_field: my_color; bg_color_field: my_background_color" >
            ...
            <field name="my_color" invisible="1"/>
            <field name="my_background_color" invisible="1"/>
            ...
        </tree>
    </field>
    ...
  • 您还可以使用 colors="bg_color_field: my_color" 来定义将用于行背景色的字段名称。

  • 如果您想使用多个颜色,可以使用分号‘;’分隔属性。

options='{"fg_color": "red:red_color == True; green:green_color == True"}'

示例

...
 <field name="arch" type="xml">
     <tree string="View name">
         ...
         <field name="name" options='{"fg_color": "red:red_color == True; green:green_color == True"}'/>
         ...
     </tree>
 </field>
 ...

 With this example, the content of the field named `my_color` will be used to
 populate the `my_color` CSS value. Use a function field to return whichever
 color you want depending on the other record values. Note that this
 overrides the rest of `colors` attributes, and that you need the tree
 to load your field in the first place by adding it as invisible field.

请注意,您应始终为字段‘options’使用单引号,并将嵌套值用双引号括起来,因为‘options’是一个JSON对象。

错误跟踪器

错误在 GitHub Issues 上跟踪。如果遇到问题,请检查是否已报告您的问题。如果您是第一个发现它的人,请提供详细且受欢迎的 反馈,以帮助我们解决问题。

请不要直接联系贡献者以获取支持或帮助解决技术问题。

致谢

作者

  • Camptocamp

  • Therp BV

  • GRAP

贡献者

维护者

此模块由OCA维护。

Odoo Community Association

OCA,或Odoo社区协会,是一个非营利组织,其使命是支持Odoo功能的协作开发并促进其广泛使用。

此模块是GitHub上的OCA/web项目的组成部分。

欢迎您贡献。要了解如何贡献,请访问https://odoo-community.org/page/Contribute

项目详情


下载文件

下载适用于您的平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源代码分发

此版本没有可用的源代码分发文件。请参阅生成分发存档的教程

构建的发行版

由以下支持