Odoo Help

1

How to run javascript only after the view has loaded

By
Timo Ahtikari
on 7/2/14, 8:48 AM 1,768 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.

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

Henrik Norlin
on 11/30/15, 9:01 AM
0
Henrik Norlin
On 11/30/15, 1:09 PM

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

    }

});

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 7/2/14, 8:48 AM
Seen: 1768 times
Last updated: 11/30/15, 1:09 PM