[英]Odoo - Disable selection option in tree view for some rows based on condition
為每個復選框提供一個唯一的 ID。
使用 Jquery 或 javascript onLoad 或 document.ready 方法禁用復選框。 創建 for 循環並為您的匹配值編寫簡單的禁用代碼。
document.getElementById("myCheck").disabled = true;
我不確定odoo。 但我對odoo有一點了解。 如果動態數據來自數據庫,則必須為此設置一個數據字段。
根據文檔,沒有多重編輯功能。
復選框選擇器添加在ListRenderer小部件的ListRenderer
function 中,因此您需要覆蓋它以根據條件禁用復選框。
在以下示例中,當state
(硬編碼)字段值等於draft
時,我們禁用選擇復選框。
例子:
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;
},
});
});
您可以在操作上下文中傳遞評估域,然后使用當前記錄值評估_renderSelector
function 中的域。
我們在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;
},
});
});
您需要將selection_domain
添加到操作上下文中:
{..., 'selection_domain': [('state', '=', 'draft')]}
查看資產管理文檔以了解如何將上述 JavaScript 代碼添加到 web 資產中,您還可以在資產包中添加文件部分中查看示例。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.