[CLOSED] Added Records don't show up as modified

  1. #1

    [CLOSED] Added Records don't show up as modified

    Hey Geoff,

    I'm not sure if you've addressed this or not, but I found out tonight that added records to the store don't show up as "modified" so they aren't picked up on the save from the new grid.

    I found a post about it here on the ext forums: http://extjs.com/forum/showthread.php?t=41651 We might consider adding something similar.

    I'm adding a new record by creating the record and then just doing a store.add on it.
    Last edited by Daniil; Jun 14, 2011 at 11:18 AM. Reason: [CLOSED]
  2. #2

    RE: Added Records don't show up as modified

    Hi Dave,

    How are you added records? Can you post your code? The GridPanel (Coolite version) has addRecord and insertRecord functions. If you use own code for insert a new record to the store then please ensure that record has newRecord = true field

    Please let me know if addRecord or insertRecord functions don't work for you


  3. #3

    RE: Added Records don't show up as modified

    Here's some sample code for when I'm adding a record - newRecord doesn't make any difference

        recDef = Ext.data.Record.create(['NoteId', 'Username', 'ShowOnTrackingSheet', 'Updated', 'ShortText', 'FullNote']);    
        newrec = new recDef({ShowOnTrackingSheet:show, FullNote:fullnote});
        newrec.newRecord = true;
        this.add(newrec);
    I'm not adding to the grid - I'm adding directly to a store. I'm going to change this now - I was using two stores, but I think only one store is really needed.

    But, the point still stands: if you add a record via this code, the record you've added doesn't show up as a modified record. the save() function on the coolite store runs "json.getChangedData" to see if anything had changed. This looks only at deleted and modified records, and the store doesn't show added records as either of these. (which I don't really understand...)

    Anyway, a new record isn't added to the modified, so it doesn't get picked up and the save proxy isn't called.

    My suggestion would be to override the add method on Store, add the records that have been added to the modified collection, and then call the normal add method. Or - do it on the save, based on the newRecord flag.
  4. #4

    RE: Added Records don't show up as modified

    Hi Dave,

    I reproduced your problem. The fix will be ready soon. For now you can use next workaround:

        recDef = Ext.data.Record.create(['NoteId', 'Username', 'ShowOnTrackingSheet', 'Updated', 'ShortText', 'FullNote']);    
           // need to use default values, in other case the cells in grid will be don't marked
        // as modified (but the saving will be perform in any case). 
        //If no need cell marking then just use a empty object {}
    
        newrec = new recDef({ShowOnTrackingSheet:'', FullNote:''});
        newrec.newRecord = true;
        this.add(newrec);
        newrec.set('ShowOnTrackingSheet', show);
        newrec.set('FullNote', fullnote);

  5. #5

    RE: Added Records don't show up as modified



    Hello.
    I also got this problem, and can't get it to work even with tour workaround, and I'm getting stuck with it :/

    I'm adding some pics by drag/drop to a dataview, and handling the drop in order to add them to a store :


    Original version : working fine, except that records are not set modified/dirty.
    onNodeDrop: function(target, dd, e, data) {
     if (g.store.find('id', data.pictureData.id) != -1)
      return false;
     var store = g.store;
     var record = Ext.data.Record.create([
           { name: 'id' },
           { name: 'name' },
           { name: 'urlMini' }
            ]);
     var ajoutPicture = new record({
      id: data.pictureData.id,
      name: data.pictureData.miniName,
      urlMini: data.pictureData.urlMini
     });
     
     store.insert(0, ajoutPicture);
      
     g.setTemplate(tplSelection);
     g.refresh();
     nbElement = store.data.length;
     scrollToEnd(refresh_arrows());
     document.getElementById('nbImages').innerText = '(' + nbElement + ')';
     document.getElementById('viderSelectionDiv').style.visibility = 'visible';
    
    
     return true;
    }
    Workaround : fails with "'parentNode is Null or not an object", and no modified record either.
    onNodeDrop: function(target, dd, e, data) {
     if (g.store.find('id', data.pictureData.id) != -1)
      return false;
     var store = g.store;
     var record = Ext.data.Record.create([
           { name: 'id' },
           { name: 'name' },
           { name: 'urlMini' }
            ]);
     var ajoutPicture = new record({
      id: '',
      name: '',
      urlMini: ''
     });
     
     ajoutPicture.newRecord = true;
     store.add(ajoutPicture);
     
     ajoutPicture.set('id', data.pictureData.id);
     ajoutPicture.set('name', data.pictureData.miniName);
     ajoutPicture.set('urlMini', data.pictureData.urlMini);
     
     g.setTemplate(tplSelection);
     g.refresh();
     nbElement = store.data.length;
     scrollToEnd(refresh_arrows());
     document.getElementById('nbImages').innerText = '(' + nbElement + ')';
     document.getElementById('viderSelectionDiv').style.visibility = 'visible';
    
    
     return true;
    }
    I was able to set a record dirty by simply adding
        pictureData.set('foo', 'bar');
    after Insert, but I got the same javascript error.

    Any idea how I could fix that? I would like it to work with v0.6 in order to avoid any breaking changes :(

    Thx :)
  6. #6

    RE: Added Records don't show up as modified

    Hi Rod,

    you can look into the insertRecord of GridPanel. In this function you can see how to add row which will be marked as dirty

    insertRecord: function(rowIndex, values) {
            var f = this.record.prototype.fields, dv = [];
            for (var i = 0; i < f.length; i++) {
                dv[f.items[i].name] = f.items[i].defaultValue;
            }
            var record = new this.record(dv);
            record.firstEdit = true;
            record.newRecord = true;
            this.stopEditing();
            this.store.insert(rowIndex, record);
            values = values || {};
            for (var v in values) {
                record.set(v, values[v]);
            }
    }
    Hope this help

Similar Threads

  1. Replies: 4
    Last Post: Jun 08, 2012, 10:05 AM
  2. Replies: 7
    Last Post: Mar 21, 2012, 10:24 AM
  3. Replies: 5
    Last Post: Jun 14, 2011, 11:47 AM
  4. [CLOSED] Modified records in store get purged prior to BeforeLoad event
    By Mark.Cooke in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Sep 20, 2010, 7:08 PM
  5. [CLOSED] added records disappear with pagingtoolbar
    By smmille1 in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Aug 17, 2010, 6:07 PM

Posting Permissions