Question

I have a Store configured with a proxy to POST data to the server. I add records to this store dynamically. After calling the sync() method on the store the data gets sent to the server. But looking at the network traffic I see that the whole records data is sent. How can I configure the store to send only individual data (like only IDs of the record)?

I have tried seeting the WriteAllFields property to false on the JSON writter connected to the proxy but this did not help

I have also tried this approach: Ext.JS Prevent Proxy from sending extra fields but the request was not even performed

var documentStore = Ext.getStore('Document');
var trashStore = Ext.getStore('TrashDocuments');

documentStore.each (function(record) {

    console.debug(record);

    //record.phantom = true;
    //record.setDirty();

    trashStore.add(record);
    documentStore.remove(record);
});


var newWriter = Ext.create('Ext.data.writer.Json',{
  getRecordData: function(record){
       return {'id':record.data.id};
  }
});

trashStore.getProxy().setWritter(newWritter);

trashStore.sync({
            success: function()
            {
                console.debug("success!!");
            },
            failure: function()
            {
                console.debug("failed...");
            },
            callback: function()
            {
                console.debug("calling callback");
            },
            scope: this
        });

console.debug("END");
Was it helpful?

Solution

writeAllFields config is not working because that is only meaningful for non-phantom records; any fields of a phantom (new) record will be viewed as "changed" and therefore included in the request packet.

To exclude specific fields from being included in the request, add persist:false to the fields you don't want to include.

That being said, I don't quite understand why you'd only want to write the ids of a newly added record. Unless you are explicitly having Ext JS create those ids for you, what are you actually going to be sending to server? I don't know your use case, but typically it is desirable to have your persistence layer (e.g., a database) assign identifiers to your records.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top