This question has been flagged
2 Replies
13743 Views

I need to run a jQuery script that does things with my list view.

I created the module with a JS file, but it tries to run it before the list view has loaded. That obviously does not work.

So I made the script check, if the list view exists before running rest of the script, which works great for the first time a page is loaded, but fails on subsequent page loads because odoo only reloads the views and not the page itself.

I was able to make the script work by putting it inside the web module's view_list.js instance.web.ListView.List init: function (around row 900). I figured i'd extend the function with my own module but all my attempts have failed.

Please explain in plain english how to extend the init function, so wouldn't have to modify the core module. Or if there's another way to run the JS each time a view is loaded, not only on page loads refreshes, that would help too.

Avatar
Discard

I have exactly the same problem. Did you find a good solution?

Best Answer

I solved it in V9 with

var render_list = {};

instance.web.my_view = instance.web.ListView.extend({

    set_default_options: function (options) {

        this._super(options);

        this.options.ListType = instance.web.my_list;

        render_list = jQuery.Deferred();

    },

});

instance.web.my_list = instance.web.ListView.List.extend({

    render: function () {

        setTimeout(function() {render_list.resolve();}, 100); // 100 milliseconds delay

    }

});

Avatar
Discard