1. #1
    Sencha User
    Join Date
    Feb 2009
    Posts
    75
    Vote Rating
    -1
    bareflix is an unknown quantity at this point

      0  

    Default How to send extra parameters to ext.DirectStore CRUD functions?

    How to send extra parameters to ext.DirectStore CRUD functions?


    I define my store for a list/form editing system as follows:

    Code:
    myStore = Ext.extend(Ext.data.DirectStore,
    {
        constructor: function (config)
        {
            var params = 
            {
                autoLoad: true,
                autoSave: true,
                paramsAsHash: false,
                totalProperty: 'count',
                root: 'result',    
                baseParams: {table: "skill"},
                paramOrder: ['table'],
                api:
                {
                    create: orbital.Skill.create,
                    read: orbital.Skill.read,
                    update: orbital.Skill.update,
                    destroy: orbital.Skill.destroy
                },
               writer: new Ext.data.JsonWriter(
                    {
                        encode: false,
                        returnJson: true,
                        writeAllFields: true
                    }),
            };
    
            config = Ext.apply (params, config);
            dynaStore.superclass.constructor.call(this, config);
        });
    I assign this as the store for my list and everything works great *except* the baseParams are not sent in the crud requests. I need to be able to send extra data, like the table name. How can I do this?

  2. #2
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    89
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    Which Ext version? This was something that got fixed some time ago.

  3. #3
    Sencha User
    Join Date
    Feb 2009
    Posts
    75
    Vote Rating
    -1
    bareflix is an unknown quantity at this point

      0  

    Default


    Sorry I forgot to mention the version. I'm using 3.2.1.

  4. #4
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    89
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    This was fixed somewhere in Ext 3.1.x, so that can't be the problem.

    Are you sure the baseParams aren't sent (the baseParams aren't in the root)?

    It should look something like:
    Code:
    {table: 'skill', result: {...}}

  5. #5
    Sencha User
    Join Date
    Feb 2009
    Posts
    75
    Vote Rating
    -1
    bareflix is an unknown quantity at this point

      0  

    Default


    I still haven't gotten this to work. The json data that is sent to the server looks like this:
    Code:
    {"action":"Skill","method":"read","data":null,"type":"rpc","tid":2}
    There's no "result" in there, I think you were thinking about the reply from the server.

    I've tried to trace this into the ext.js source. I've followed it down into Ext.data.DirectProxy's doRequest function.
    There is some code I don't understand in there about directFn.directCfg.method.len and this.paramsAsHash. I've tried paramsAsHash true and false with no difference. At the bottom of doRequest I see:

    Code:
            args.push(this.createCallback(action, rs, trans), this);
            directFn.apply(window, args);
    and I haven't been able to follow it from there.
    If I dump out args I get:
    Code:
    [Object { table="Skill"}, function(), Object { api=Object,  more...}]
    so my table=Skill is getting that far.

    any suggestions on what else to try or how to trace it into the actual ext.Direct call would be greatly appreciated.

  6. #6
    Sencha User
    Join Date
    May 2010
    Location
    London, UK
    Posts
    21
    Vote Rating
    0
    meercat is on a distinguished road

      0  

    Default


    It's a bit late to join the thread, but I add extra parameters to my calls by overriding the functions in the Writer that construct the record that's sent.

    So for example, I have the following base class

    Code:
    myNameSpace.DirectStore = Ext.extend(Ext.data.DirectStore, {
        // a store is not a component, so we override the ctor, not initComponent()
        constructor : function(config){
            var c = Ext.apply({}, {
                paramsAsHash: true,
                batch:    true,
                autoSave: true
            }, config);
    
            var me = this;
            myNameSpace.DirectStore.superclass.constructor.call(this, Ext.apply(c, {
                // any further overrides 
                writer: new Ext.data.JsonWriter({
                    encode: false,          // DirectProxy will do this for us
                    writeAllFields: true,   // write all fields for updates, not just those that changed
                    destroyRecord : function(rec){
                        // all my routines require no more than the core ID in the delete record
                        var r = { };
                        r[c.idProperty] = rec.id;
                        return r;
                    },
                    createRecord: function(rec){
                        // my extension 'staticfields' are added to the record to create an entry
                        // but are not stored per record (eg the owning chart) or written on updates
                        var base = this.toHash(rec);
                        if (Ext.isObject(me.staticfields)) {
                            base = Ext.apply(base, me.staticfields);
                        }
                        return base;
                    }
                })
            }));
        }
    }
    and then when I make a one of these stores I add parameters such as

    Code:
                            staticfields: {
                                // our extension for fields to add to creation but that don't need storing
                                chart: somefunc()
                            },
    This way the extra parameters get attached to the records for create actions (and you'll see I also modify the record sent for destroy actions to send the ID alone - YMMV)
    Last edited by meercat; 15 Sep 2010 at 6:06 AM. Reason: Forgot code tags around the code extracts

Similar Threads

  1. Ext.DirectStore in EditorGridPanel CRUD-like api question.
    By Fredric Berling in forum Ext 3.x: Help & Discussion
    Replies: 3
    Last Post: 17 Jan 2010, 8:03 AM
  2. DirectStore - send parameters
    By archmisha in forum Ext 3.x: Help & Discussion
    Replies: 1
    Last Post: 28 Jul 2009, 12:02 AM
  3. How to send a normal request to the server with parameters from Ext?
    By biot023 in forum Ext 1.x: Help & Discussion
    Replies: 2
    Last Post: 26 Jul 2007, 12:30 PM

Thread Participants: 2