[CLOSED] Store: Is it possible to QueryBy a store with another store?

  1. #1

    [CLOSED] Store: Is it possible to QueryBy a store with another store?

    Hi,

    I have 2 stores, LEFT (source) and RIGHT (shopping cart).
    What I want to do is when the item exist in the RIGHT store, it will hide the LEFT by setting "HideLeftRow" as true.
    (virtually moving an item from LEFT to RIGHT). Below is the code I am using now and it is working fine.
    But my LEFT store can go up to 1000 items, and if the RIGHT store contains about 200 items, and when this happens, it is very slow.

    gridRight.store.each(function(record, index) {
      var index = gridLeft.store.findExact('LeftID',record.get('RightID'));
      if(index >= 0){
        var recordLeft = gridLeft.store.getAt(index);
        recordLeft.set('HideLeftRow', true);
      }
    });


    I am wondering if its possible to use QueryBy with another store, and if it is possible, will this improve the performance?

    Something like this? << not working, just thinking out loud >>
    gridLeft.store.queryBy(function(records){
      records (in gridRight);
    }

    Or is there any other way that might help this function run faster?

    Thanks, J
    Last edited by Daniil; Nov 03, 2011 at 9:40 AM. Reason: [CLOSED]
  2. #2
    Hi,

    This code should work much faster:
    var storeLeft = gridLeft.store;
    gridRight.store.each(function (record) {
        var index = storeLeft.findExact('LeftID', record.data.RightID);
        if (index > -1) {
            storeLeft.getAt(index).data.HideLeftRow = true;
        }
    });
    gridLeft.getView().refresh();
    And lets focus on:
    var index = storeLeft.findExact('LeftID', record.data.RightID);
    I think you don't need to use different ids. What is the reason?

    You should be able to make the same ids for records in the both stores. Then the code can look like this:
    var storeLeft = gridLeft.store;
    gridRight.store.each(function (record) {
        storeLeft.getById(record.id).data.HideLeftRow = true;
    });
    gridLeft.getView().refresh();
    I'm afraid I don't understand this:
    I am wondering if its possible to use QueryBy with another store, and if it is possible, will this improve the performance?

    Something like this? << not working, just thinking out loud >>
    gridLeft.store.queryBy(function(records){
      records (in gridRight);
    }
    Please clarify.

    As well the Store's .filter() and .filterBy() methods can help:
    http://docs.sencha.com/ext-js/3-4/#!...-method-filter
    http://docs.sencha.com/ext-js/3-4/#!...ethod-filterBy
    Last edited by Daniil; Nov 03, 2011 at 8:11 AM.
  3. #3
    Hi Daniil,

    Thanks. I will try to do the first suggestion you provided.

    As for your questions:
    var index = storeLeft.findExact('LeftID', record.data.RightID);
    I only did this for easier to explain between left ID and right ID but yes, it is the same ID.


    As for the QueryBy, my idea is from SQL query like:

    UPDATE HideLeftRow = true FROM gridLeft WHERE gridLeft.ID IN (SELECT ID FROM gridRight)
    I know its very different from STORE, which is why I was wondering if its possible and perhaps faster if I can avoid the "gridRight.store.each" looping.

    Thanks again for the quick response and the suggestion.
  4. #4
    Well, I think it's impossible to achieve that.

    And I'm not sure you can avoid looping a store.

    Can not you update a record when you move it from the left on the right?
  5. #5
    Hi Daniil,

    The record on the right side are details data retrieved from database, and the left side is from a master table. So the right table is populated from database and then the left is removed based on what is on the right. Aside from manual movement from left-right / right-left.

    But your recommendation has improved the performance and I suppose it is impossible with javascript to achieve what SQL can.

    Thank you again, please close this ticket.

    Regards, J

Similar Threads

  1. Replies: 1
    Last Post: Jun 26, 2012, 1:40 PM
  2. Replies: 3
    Last Post: Feb 21, 2012, 10:49 AM
  3. [CLOSED] Access Grid Data Store and manually store to database
    By macap in forum 1.x Legacy Premium Help
    Replies: 8
    Last Post: Oct 05, 2011, 8:52 AM
  4. [CLOSED] Store Load-handler cant reload child store
    By Jurke in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Feb 04, 2011, 7:56 AM
  5. Replies: 4
    Last Post: Dec 01, 2010, 10:48 AM

Posting Permissions