1. #1
    Ext User
    Join Date
    Dec 2009
    Location
    Japan
    Posts
    43
    Vote Rating
    0
    ironlion is on a distinguished road

      0  

    Default How to check datastore is loaded?

    How to check datastore is loaded?


    How to check data store is loaded?
    Is there any direct method something like below?
    Code:
    myStore.isLoaded()

  2. #2
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    17,054
    Vote Rating
    659
    evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute

      0  

    Default


    Use the load event:

    Code:
    store.on('load', function(){
        //do something
    });
    Evan Trimboli
    Sencha Developer
    Twitter - @evantrimboli
    Don't be afraid of the source code!

  3. #3
    Ext User
    Join Date
    Dec 2009
    Location
    Japan
    Posts
    43
    Vote Rating
    0
    ironlion is on a distinguished road

      0  

    Default


    Load event fires after records has been loaded. I am asking the way to check data store loaded or not.

  4. #4
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    17,054
    Vote Rating
    659
    evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute

      -1  

    Default


    That's how you check, once the load event fires.
    Evan Trimboli
    Sencha Developer
    Twitter - @evantrimboli
    Don't be afraid of the source code!

  5. #5
    Ext User
    Join Date
    Dec 2009
    Location
    Japan
    Posts
    43
    Vote Rating
    0
    ironlion is on a distinguished road

      0  

    Default


    Quote Originally Posted by evant View Post
    That's how you check, once the load event fires.
    Let's assume myStore is not loaded yet. Then how to check it is not loaded?

  6. #6
    Sencha Premium Member MaximGB's Avatar
    Join Date
    Jun 2007
    Location
    Moscow, Russia
    Posts
    508
    Vote Rating
    5
    MaximGB is on a distinguished road

      2  

    Default


    Extend the store - add the 'loaded' property to the child class, override 'initComponent()' and attach to 'load' event inside it, raise the 'loaded' to true inside the event handler, add the 'isLoaded()' method returning value of the 'loaded' property.

    Other way, if you use http transport - store.proxy.conn.isLoading()
    Use the force - read the source.

  7. #7
    Ext User
    Join Date
    Dec 2009
    Location
    Japan
    Posts
    43
    Vote Rating
    0
    ironlion is on a distinguished road

      0  

    Default


    Thanks MaximGB, that's good idea.

  8. #8
    Sencha User Eugen_'s Avatar
    Join Date
    Feb 2010
    Posts
    106
    Vote Rating
    -4
    Eugen_ is infamous around these parts

      -1  

    Default


    Quote Originally Posted by ironlion View Post
    Let's assume myStore is not loaded yet. Then how to check it is not loaded?
    if a loaded store has at least one record always you can use the getCount() method

  9. #9
    Sencha User realjax's Avatar
    Join Date
    Aug 2009
    Location
    Netherlands
    Posts
    412
    Vote Rating
    6
    realjax is on a distinguished road

      1  

    Default


    Quote Originally Posted by Eugen_ View Post
    if a loaded store has at least one record always you can use the getCount() method
    I'd strongly advise against this. Its dangerous because this just gets you the number of records. It doesn't tell you if that number is after or before loading. Before initial loading getCount returns zero, but after loading and getting back zero records you get the same result..

  10. #10
    Sencha User Eugen_'s Avatar
    Join Date
    Feb 2010
    Posts
    106
    Vote Rating
    -4
    Eugen_ is infamous around these parts

      -2  

    Default


    Quote Originally Posted by realjax View Post
    I'd strongly advise against this. Its dangerous because this just gets you the number of records. It doesn't tell you if that number is after or before loading. Before initial loading getCount returns zero, but after loading and getting back zero records you get the same result..
    There is no difference between isLoaded() and if (getCount() > 0) if a store contains at least one record always after loading. Before loading we can clear the store. In over case we need to catch 'load' event.