[CLOSED] General store questions : insert/remove, dirty, getRowsValues

  1. #1

    [CLOSED] General store questions : insert/remove, dirty, getRowsValues

    Hi

    I got a few general gridpanel store questions on how to do it the right/best way:


    Setting:
    I have a simple gridpanel with an attached store, nothing fancy.

    1)
    To insert a row directly via javascript:
    #{STORE}.insert(index, records);
    It is working flawlessly but is this correct? What about the dirty flag? Because I don't see it in the gridpanel row...

    2)
    To remove a row directly via javascript:
    #{STORE}.removeAt(#{STORE}.indexOf(record));
    It is working flawlessly but is this correct? What about the dirty flag?

    3)
    I would like to submit via a DirectMethod the dirty rows of this grid...
    #{GRIDPANEL}.getRowsValues({dirtyRowsOnly: true});
    doesn't submit any rows at all. I would love to get an array or something in code behind where I can quickly filter the deleted and new ones to update my database.

    Thank you very much.
    Last edited by Daniil; Sep 23, 2013 at 11:26 AM. Reason: [CLOSED]
  2. #2
    Hi @tMp,

    Quote Originally Posted by tMp View Post
    1)
    To insert a row directly via javascript:
    #{STORE}.insert(index, records);
    It is working flawlessly but is this correct? What about the dirty flag? Because I don't see it in the gridpanel row...
    The dirty flag means that an existing record has been modified. If you insert a new record, it is treated as a new one. There is a possibility to highlight a new record:
    https://examples2.ext.net/#/GridPane...rking_Records/

    If you need to retrieve all new records, you can use:
    store.getNewRecords();
    Quote Originally Posted by tMp View Post
    2)
    To remove a row directly via javascript:
    #{STORE}.removeAt(#{STORE}.indexOf(record));
    It is working flawlessly but is this correct? What about the dirty flag?
    Correct. Or the remove method:
    #{STORE}.remove(records); // records can be a single record or an array of records
    Do you need something to retrieve the deleted records further? If so, you can use:
    store.getRemovedRecords();
    Quote Originally Posted by tMp View Post
    3)
    I would like to submit via a DirectMethod the dirty rows of this grid...
    #{GRIDPANEL}.getRowsValues({dirtyRowsOnly: true});
    doesn't submit any rows at all. I would love to get an array or something in code behind where I can quickly filter the deleted and new ones to update my database.
    To get all the updated, removed, new records, please use:
    store.getChangedData();
    Here is an example:
    https://examples2.ext.net/#/GridPanel/Update/Batch/
  3. #3
    Hi Daniil,

    Thanks for you answers!

    1) pefect!

    2) change it because it looks easier to me your way ;)

    3) have to play a little bit with it because I got some questions how this example works...

    - Why the
    Before="return #{Store1}.isDirty();"
    ?

    - Can I use
    "#{Store1}.getChangedData();"
    in a DirectMethod too? Because I am only using DirectMethods without any "record"-objects to store the extraParams on the server side. I would like to just go through the created/deleted/changed records an save them directly to the database...

    Thank you very much.
    Last edited by Daniil; Sep 20, 2013 at 1:09 PM. Reason: Please use [CODE] tags
  4. #4
    Quote Originally Posted by tMp View Post
    - Why the
    Before="return #{Store1}.isDirty();"
    ?
    Returing false from a DirectEvent's Before handler prevents that DirectEvent. If no change in the Store, then nothing to save, then no need in the DirectEvent.

    Store's isDirty
    isDirty : function () {
        return this.getNewRecords().length > 0 || this.getUpdatedRecords().length > 0 || this.getRemovedRecords().length > 0;
    }
    You see it takes updated, removed, new records into account. So, it is not the same as a record's dirty flag.

    Quote Originally Posted by tMp View Post
    - Can I use
    "#{Store1}.getChangedData();"
    in a DirectMethod too? Because I am only using DirectMethods without any "record"-objects to store the extraParams on the server side. I would like to just go through the created/deleted/changed records an save them directly to the database...
    Yes, you can. Just use it as a DirectMethod argument. Please do not forget to encode:
    App.Direct.SomeDirectMethod(Ext.encode(store.getChangedData()));
  5. #5
    @Daniil

    Thank you very much. Everything working smoothly now!

Similar Threads

  1. [CLOSED] TreePanel remove dirty red arrow flag
    By jchau in forum 2.x Legacy Premium Help
    Replies: 4
    Last Post: Feb 09, 2013, 4:40 AM
  2. Remove red dirty flags from grid.
    By AaronB3 in forum 1.x Help
    Replies: 2
    Last Post: Jun 27, 2011, 9:47 PM
  3. Store - Determine if dirty?
    By Tbaseflug in forum 1.x Help
    Replies: 4
    Last Post: Dec 02, 2010, 1:29 PM
  4. general questions
    By idrissb in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Jan 13, 2009, 12:31 PM
  5. General Questions and Comments
    By Dewey in forum Open Discussions
    Replies: 2
    Last Post: Mar 17, 2008, 7:54 PM

Tags for this Thread

Posting Permissions