[英]Odoo - Disable selection option in tree view for some rows based on condition
Provide one unique id to each and every checkbox.为每个复选框提供一个唯一的 ID。
Use Jquery or javascript onLoad or document.ready method to disable the checkbox.使用 Jquery 或 javascript onLoad 或 document.ready 方法禁用复选框。 create for loop and write simple disable code for your matching value.
创建 for 循环并为您的匹配值编写简单的禁用代码。
document.getElementById("myCheck").disabled = true; document.getElementById("myCheck").disabled = true;
I m not sure about odoo.我不确定odoo。 but I have a little bit of knowledge about odoo.
但我对odoo有一点了解。 you have to set a data field for this if dynamic data come from Database.
如果动态数据来自数据库,则必须为此设置一个数据字段。
According to the documentation , there is no multi editing feature.根据文档,没有多重编辑功能。
The checkbox selector is added in _renderSelector function of the ListRenderer
widget, so you need to override it to disable the checkbox based on condition.复选框选择器添加在ListRenderer小部件的
ListRenderer
function 中,因此您需要覆盖它以根据条件禁用复选框。
In the following example we disable the selection checkbox when the state
(hard coded) field value is equal to draft
.在以下示例中,当
state
(硬编码)字段值等于draft
时,我们禁用选择复选框。
Example:例子:
odoo.define('web.CustomListRenderer', function (require) {
"use strict";
var ListRenderer = require('web.ListRenderer');
ListRenderer.include({
_renderRow: function (record) {
var self = this;
var tr = this._super(record);
tr.find("input[type='checkbox']").prop('disabled', record.data.state == 'draft');
return tr;
},
});
});
You can pass an evaluation domain in the action context, then evaluate the domain in the _renderSelector
function using the current record value.您可以在操作上下文中传递评估域,然后使用当前记录值评估
_renderSelector
function 中的域。
We initialize the domain in init
function and use the compute function to get the evaluation result:我们在
init
function 中初始化域并使用计算function 得到评估结果:
odoo.define('web.CustomListRenderer', function (require) {
"use strict";
var ListRenderer = require('web.ListRenderer');
var Domain = require('web.Domain');
ListRenderer.include({
init: function (parent, state, params) {
this._super.apply(this, arguments);
if (state.context.selection_domain) {
this.domain = new Domain(state.context.selection_domain, state.context);
}
},
_renderRow: function (record) {
var self = this;
var tr = this._super(record);
if (record.evalContext.selection_domain) {
tr.find("input[type='checkbox']").prop('disabled', this.domain.compute(record.data));
}
return tr;
},
});
});
You need to add the selection_domain
to the action context:您需要将
selection_domain
添加到操作上下文中:
{..., 'selection_domain': [('state', '=', 'draft')]}
Check the Assets Management documentation to see how to add the above JavaScript code to the web assets, you can also see an example in Adding files in an asset bundle section.查看资产管理文档以了解如何将上述 JavaScript 代码添加到 web 资产中,您还可以在资产包中添加文件部分中查看示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.