question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Show loading spinner while model is loading

See original GitHub issue

Hi, before using your pagination, i use to have a loading var on my controllers set to false, whenever i changed the model i would set this loading to true and to false again on the promise return, success/fail method(i mean “save().then(success, fail)”), so i can show a loading spinner on the view(just in the table area) while model is loading.

Question is, how can i implement this with this pagination? i thought something like this:

var loading = false,
fetchContent: function() {
    this.set('loading', true);
    res.then(function(rows) {
        this.set('loading', false);
    }
}

then in my template:

{{#if loading}}
<!-- Show loading -->
{{else}}
<!-- List entries -->
{{/if}}

I intend to use a reopen(paged-remote-array) on a mixing to add this implementation. Thank you.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
matheusdavidsoncommented, Dec 23, 2014

Hey @mharris717, i did like this(have a look at the manipulation of loading property):

  • Added a loading property
  • Set loading to true at the beginning
  • Set loading to false at success and fail
loading: false,
fetchContent: function() {
        // Setting loading
        this.set('loading', true);

        var store = this.get('store');
        var modelName = this.get('modelName');

        var ops = this.get('paramsForBackend');
        var res = store.find(modelName, ops);
        this.incrementProperty("numRemoteCalls");
        var me = this;

        res.then(function(rows) {
            Util.log("PagedRemoteArray#fetchContent in res.then " + rows);
            var newMeta = {};
            var totalPagesField = me.get('paramMapping').total_pages;
            if (rows.meta) {
                for (var k in rows.meta) {
                    newMeta[k] = rows.meta[k];
                    if (totalPagesField && totalPagesField === k) {
                        newMeta['total_pages'] = rows.meta[k];
                    }
                }
            }

            // Unset loading
            me.set('loading', false);
            return me.set("meta", newMeta);
        }, function(error) {
            // Unset loading
            me.set('loading', false);
            Util.log("PagedRemoteArray#fetchContent error " + error);
        });

        return res;
    },

then in my templates, i have:

{{#if model.loading}}
    {{partial "loading"}}
    <br />
{{else}}
-- table with entries --
{{/if}}

{{partial "loading"}} is a partial with a spinning loader

It works very well like this, if you want to implement something like this would be a nice idea. You could just give access to the loading property so the user can manipulate they template like this if they want to.

0reactions
mharris717commented, Aug 28, 2015

Added. https://github.com/mharris717/ember-cli-pagination/pull/137

Sorry I took so long here. Life really got in the way for a while. Thanks for taking the time to contribute!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Display Spinner on the Screen till the data from the API ...
The task is to display a spinner on the page until the response from the API comes. Here we will be making a...
Read more >
How to show Page Loading div until the page has finished ...
Show activity on this post. This script will add a div that covers the entire window as the page loads. It will show...
Read more >
How to manually show and hide loading or spinning image?
Instead of default datasource config/method to load remote data, I am using a custom function to load data and I like to manually...
Read more >
How to display loading indicator while Blazor component is ...
To fix this, we will add a loading indicator. The loading indicator will be displayed till the Employees property is Null and the...
Read more >
Spinners - Bootstrap
Bootstrap “spinners” can be used to show the loading state in your projects. ... While it doesn't technically spin, it does repeatedly grow!...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found