如何在Odoo的列表视图中添加外部jQuery插件? [英] How to add an external jQuery plugin to the list view on Odoo?

查看:521
本文介绍了如何在Odoo的列表视图中添加外部jQuery插件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Odoo 10e.我想将一个jQuery插件集成到我的模块中.

I am using Odoo 10e. I want to integrate a jquery plugin into my module.

我想集成jQuery插件 jquery-resizable-columns .它简单易用,可帮助用户即时调整表的列大小,而我想将其应用于特定模型的列表视图

I want to integrate the jQuery plugin jquery-resizable-columns. It simple helps user to resize columns of table on the fly and I want to apply this on a specific model's list view

我应该扩展哪种方法以添加插件?

Which method should I extend in order to add the plugin?

推荐答案

我认为您应该在网络模块中扩展(也许包括)一些小部件.如果转到文件/addons/web/static/src/js/view_list.js,则可以看到呈现表的小部件:

I think you should extend (maybe include) some widget in the web module. If you go to the file /addons/web/static/src/js/view_list.js, you can see the widget that renders the table:

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,因此您必须以类似的方式添加所需的插件.

As you can see there is an event declared as sort_by_column, so you would have to add the plugin you want in a similar way.

如果您对继承和修改窗口小部件有任何疑问,可以访问 Odoo文档

And if you have any doubts inheriting and modifying widgets you can go to the Odoo Documentation

如果您使用的是版本10,则可以检查其构建方式

And if you are using the version 10 you can check how it is built here /addons/web/static/src/js/views/list_view.js

这篇关于如何在Odoo的列表视图中添加外部jQuery插件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆