Results 1 to 7 of 7

Thread: Removing a record from a store, but not yet triggering a server side delete

  1. #1
    Sencha User
    Join Date
    Apr 2010
    Posts
    21

    Default Answered: Removing a record from a store, but not yet triggering a server side delete

    I have a store, backed by a RESTful Model. This store is used through a ViewModel.

    When adding to the store, I have code that does:

    , addField: function () {
    var store = this.getReference('fieldgrid').getStore()
    store.add(new TemplateFieldModel());
    this.getReference('fieldeditform').show();
    }

    Here, I add a new record, then show an edit screen.

    I have code to remove:

    , removeField: function () {
    var g = this.getReference('fieldgrid');
    g.getStore().remove(g.getSelection());
    this.getReference('fieldgrid').setSelection();
    }

    Adding/removing should not sync to the backend server until a later point - until the user presses save. So users do a bunch of edits client side, before saving.

    I have two strange problems:

    1. When I add, as I do above, this triggers a GET call to the server. How can I turn this off?
    2. The removeField function works perfectly from a visual point of view - the record disappears from the grid, but when calling store.sync() during the save, a DELETE is not sent to the server. How can I make one sent to the server?
    I'm not sure if these are ExtJS 5.0 related. I'm assuming so at this stage as they are ViewModel+Store+Model.

  2. Regarding docs stating "TODO", just wait 'till you try figuring wtf is up with ViewModel, Session and Schema.

    drop removes it (afaik) from the store (and thus the grid) but delays the actual DELETE until later.



    But, from the top of my head, it seems you need some sort of hacking to get this thing done as quickly as possible.

    Add a 'ToDelete' field on the Model. Instead of doing erase or drop, just set it to true. In the grid you might want to do some strikethrough css-stuff to display it as 'to be deleted'.

    Listen for the beforeSync-event (or perhaps some other event, I can't say for sure) on the store and return cancel until you want it to do the actual creating and deleting.

    And then when you want it to do all the creating and deleting you fire the sync() manually on the store and make sure your event-hook returns true instead.

    Not exactly nice, but you are asking for a quite specific implementation.... and on a beta framework to boot =)

  3. #2
    Sencha Premium User
    Join Date
    Mar 2007
    Location
    Norway
    Posts
    197
    Answers
    7

    Default

    1. Not sure if it's the store or the model thats doing the get. Could it be that you have autoSync set to true on the store?

    2. Removing something from the store is not the same as deleting it. You might want to take a look at the methods drop and/or erase
    Founder of the Path of Exticism

  4. #3
    Sencha User
    Join Date
    Apr 2010
    Posts
    21

    Default

    Hiya,

    Hmm, so if I remove from a store, I need to first call erase() on the underlying model object. I hadn't thought of that.

    Removal from the server side works fine when I erase() the model directly. I'll try that. I don't have autoSync on.

    Ta

  5. #4
    Sencha Premium User
    Join Date
    Mar 2007
    Location
    Norway
    Posts
    197
    Answers
    7

    Default

    Just calling erase on the Model will remove it from the Store as well.

    However, the question about the GET. Do you have to add the empty Model to the store to edit it?




    PS: Set the post to answered.
    Founder of the Path of Exticism

  6. #5
    Sencha User
    Join Date
    Apr 2010
    Posts
    21

    Default

    Right, so just tested this:

    , removeField: function () {
    var g = this.getReference('fieldgrid');
    g.getSelection()[0].erase();
    }

    This works - but it erases the row from the server, and from the grid in the GUI immediately. I wan't it to not do that until I commit.

    I see the code (http://docs-origin.sencha.com/extjs/...el-method-drop) has a TODO to implement this... which made me laugh.

    Regarding the "add" - yes, I need to add it to the store because I am using bindings - {grid.selected.xxx} in my edit of the thing I just add. Still haven't found a solution to this issue.

  7. #6
    Sencha Premium User
    Join Date
    Mar 2007
    Location
    Norway
    Posts
    197
    Answers
    7

    Default

    Regarding docs stating "TODO", just wait 'till you try figuring wtf is up with ViewModel, Session and Schema.

    drop removes it (afaik) from the store (and thus the grid) but delays the actual DELETE until later.



    But, from the top of my head, it seems you need some sort of hacking to get this thing done as quickly as possible.

    Add a 'ToDelete' field on the Model. Instead of doing erase or drop, just set it to true. In the grid you might want to do some strikethrough css-stuff to display it as 'to be deleted'.

    Listen for the beforeSync-event (or perhaps some other event, I can't say for sure) on the store and return cancel until you want it to do the actual creating and deleting.

    And then when you want it to do all the creating and deleting you fire the sync() manually on the store and make sure your event-hook returns true instead.

    Not exactly nice, but you are asking for a quite specific implementation.... and on a beta framework to boot =)
    Founder of the Path of Exticism

  8. #7
    Sencha User
    Join Date
    Apr 2010
    Posts
    21

    Default

    Yes, I can (and will) hack around it - although TBH in this case I might just let the delete go through until the drop() code is written. It's not that critical.

    I'm trying to get as much of this code I'm writing as close to the "best practice" way going forward. I think I got it quite far - ViewModels, Models, ViewControllers etc are all in place. There are definite hacks around missing or broken features though.

    There are obviously some areas of the new 5.0 feature set that Sencha need to polish to work in real-world programs, and I've hit half-a-dozen of them this week. I am hopeful that there will be an improvement in the next few months.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •