1
votes

I am trying to change extraparams of a treestore at runtime. I have tried the following (works on a normal store not treestore):

 myshoporders_tree_store.getProxy().setExtraParam('order_no', order_no);
 myshoporders_tree_store.reload();

Since i could not get the above to do what i wanted, i found a solution like this:

 myshoporders_tree_store.reload({
    params:{ order_no:order_no } 
 });

The only problem with the solution is that the params are not persistent i.e. after the filter, the params get reset again on store reload, tho i wud like to maintain the params for other purposes. Or am I not doing it right? Pls help. Thnx.

My treestore:

 var myshoporders_tree_store = Ext.create('Ext.data.TreeStore', {
    autoload: false,
    model: 'myshop_order_model',
    proxy: {
        type: 'ajax',
        url: 'includes/order_cats.php',
        extraParams: {shop_id: '',cat: '',status: '',order_date: '',order_no: '',buyer_name: '',order_id: '',id: ''},
        reader: {
            root: 'orders',
            totalProperty  : 'totalCount'
        }
    },
    folderSort: false 
});

My model:

 Ext.define('myshop_order_model', {
    extend: 'Ext.data.Model',
    idProperty: 'id',
    fields: [
        { name: 'id', type: 'string' },
        { name: 'cat', type: 'string' },
        { name: 'shop_id', type: 'string' },
        { name: 'plid', type: 'string' },
        { name: 'invid', type: 'string' },
        { name: 'rectype', type: 'string' },
        { name: 'order_number', type: 'string' },
        { name: 'order_date', type: 'string' },
        { name: 'buyer_name', type: 'string' },
        { name: 'status', type: 'string' },
        { name: 'read', type: 'string' },
        { name: 'invoice_total', type: 'string' },
        { name: 'total', type: 'string' }

    ]
});

I have since tried the following example i got from sencha forum to try and isolate the problem:

 var store = Ext.create('Ext.data.TreeStore', {
  fields: ['foo'],
   proxy: {
    type: 'ajax',
    url: 'data/json.json',
    extraParams: {
        one: 'one'
    }
  }
 });


 Ext.widget('button', {
    renderTo: document.body,
    text: 'Load Store',
    handler: function () {
      store.load();
 }
 });


 Ext.widget('button', {
    renderTo: document.body,
    text: 'Set Params',
    handler: function () {
        store.getProxy().setExtraParam('one', 'two');
    }
 });


 Ext.widget('button', {
   renderTo: document.body,
   text: 'Reload Store',
   handler: function () {
       store.reload();
   }
 });

The only problem am getting is that the extraparam does not get assigned the first time i click 'load->set params-> reload' based on firebug output. The extraparam 'one' always has the value 'one'. No matter how many times i click on set params-> reload. I have to click load once again for the new values to be visible i.e. Load->set params->reload->Load Is this how it should behave really? The Reload alone should be able to show the new param values. I dont have to reclick load to see the new values. Pls help. Thnx.

2

2 Answers

2
votes

It's actually quite easy, just access the extraParams object in the proxy and change the attributes. Your example would be like this:

myshoporders_tree_store.getProxy().extraParams.order_no = order_no;
myshoporders_tree_store.reload();
-1
votes

Sorry, just found out my solution. I was using ext-debug-all.js which was causing all this. When i changed to ext-all, it seems all is ok now. Thanx for all who tried in helping.