Added Records don't show up as modified
Coolite Toolkit Version 0.8.2 now available for DOWNLOAD | See also Examples Explorer | Version 1.0 available Q1 2010
 

Coolite Forums

Welcome Guest ( Login | Register )
 
Added Records don't show up as modified
Subscribe
Last Login: 10/2/2008 10:40:47 AM
Posts: 26,
Posted 8/31/2008 6:05:39 PM

Group: Coolite Premium Member & Early Adopter
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 Login: Today @ 2:49:01 PM
Posts: 6,184,
Posted 8/31/2008 11:12:41 PM

Group: Core Development Team
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



--
Vladimir Shcheglov
Coolite Inc.
Development Team
Forum Guidelines | Coolite Examples | Coolite API Docs | ExtJS API Docs | Twitter
Last Login: 10/2/2008 10:40:47 AM
Posts: 26,
Posted 9/1/2008 5:55:56 AM

Group: Coolite Premium Member & Early Adopter
 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.
Last Login: Today @ 2:49:01 PM
Posts: 6,184,
Posted 9/1/2008 6:37:40 AM

Group: Core Development Team
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);





--
Vladimir Shcheglov
Coolite Inc.
Development Team
Forum Guidelines | Coolite Examples | Coolite API Docs | ExtJS API Docs | Twitter
Last Login: 9/16/2009 5:19:16 AM
Posts: 66,
Posted 11/19/2008 9:22:31 AM

Group: Coolite Early Adopter

 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

Last Login: Today @ 2:49:01 PM
Posts: 6,184,
Posted 11/21/2008 2:54:34 AM

Group: Core Development Team
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

--
Vladimir Shcheglov
Coolite Inc.
Development Team
Forum Guidelines | Coolite Examples | Coolite API Docs | ExtJS API Docs | Twitter
« Prev Topic | Next Topic »
Reading This Topic
Active Users: 0 ( 0 guests, 0 members, 0 anonymous members )
No members currently viewing this topic.
All times are GMT -8:00, Time now is 4:38pm