我认为你应该在网络模块中扩展(也许包括)一些小部件。如果你去文件/addons/web/static/src/js/view_list.js
,您可以看到呈现表格的小部件:
instance.web.ListView = instance.web.View.extend( /** @lends instance.web.ListView# */ {
_template: 'ListView',
display_name: _lt('List'),
defaults: {
// records can be selected one by one
'selectable': true,
// list rows can be deleted
'deletable': false,
// whether the column headers should be displayed
'header': true,
// display addition button, with that label
'addable': _lt("Create"),
// whether the list view can be sorted, note that once a view has been
// sorted it can not be reordered anymore
'sortable': true,
// whether the view rows can be reordered (via vertical drag & drop)
'reorderable': true,
'action_buttons': true,
//whether the editable property of the view has to be disabled
'disable_editable_mode': false,
},
view_type: 'tree',
events: {
'click thead th.oe_sortable[data-id]': 'sort_by_column'
},
// [...]
sort_by_column: function (e) {
e.stopPropagation();
var $column = $(e.currentTarget);
var col_name = $column.data('id');
var field = this.fields_view.fields[col_name];
// test whether the field is sortable
if (field && !field.sortable) {
return false;
}
this.dataset.sort(col_name);
if($column.hasClass("sortdown") || $column.hasClass("sortup")) {
$column.toggleClass("sortup sortdown");
} else {
$column.addClass("sortdown");
}
$column.siblings('.oe_sortable').removeClass("sortup sortdown");
this.reload_content();
},
如您所见,有一个事件声明为sort_by_column
,所以你必须以类似的方式添加你想要的插件。
如果您对继承和修改小部件有任何疑问,您可以访问Odoo 文档 http://www.odoo.com/documentation/10.0/reference/javascript.html
如果您使用的是版本 10,您可以检查它是如何构建的here https://github.com/OCA/OCB/blob/10.0/addons/web/static/src/js/views/list_view.js#L37
/addons/web/static/src/js/views/list_view.js