Odoo Help

Welcome!

This community 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.

1

How to run javascript only after the view has loaded

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

    }

});

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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