1. #1
    Sencha User
    Join Date
    May 2012
    Posts
    3
    Vote Rating
    0
    Pipanni is on a distinguished road

      0  

    Default Reload store with new values

    Reload store with new values


    Hi


    I'm new to ExtJS and I've been assigned at work with a task that involves implementing a search button on an existing grid.


    I'm able to get the results from an ajax call to PHP but I cannot reload the store. No matter what I try nothing happens and no error messages appear. The grid just stays the same.


    Here's the relevant part of the code:


    File "Campaign.grid.js", where the search button is defined and the event is triggered:
    Code:
    buildTopBar : function () {        return new Ext.Toolbar({
                items:[
                    '->',
                    {
                        fieldLabel      : 'Campaign name',
                        xtype           : 'textfield',
                        name            : 'campaign_name',
                        ref             : 'campaign_name',
                        id                : 'campaign_name',
                        allowBlank      : false,
                        maxLength       : 255
                    },
                    {
                        text        : 'Search campaign',
                        cls         : 'x-standardButton',
                        id          : 'searchCampaign',
                        handler     : function(grid){
                                        Campaign.eventManager.fireEvent('searchcampaign');
                                      },
                        scope       : this,
                        disabled    : false
                    },

    File "application.js", where the event is defined:
    Code:
    Campaign.eventManager.on('searchcampaign', function() {
                Ext.Ajax.request({
                    noCache: true,
                    url     : '/campaign/index/searchcampaign/',
                    params  : {
                        campaignName : Ext.get("campaign_name").getValue()
                    },
                    success: function(response){
                        var grid = response.responseText;
                        campaignStore.loadData(grid);
                    },
                    failure: function(response){
                        alert('An error has ocurred.');
                    }
                });
            }, this);

    File "IndexController.php", which gets the new data:
    Code:
    public function searchcampaignAction()
        {
             $this->_useHtmlResponse = true;
             $this->_helper->layout()->disableLayout();
             $this->_helper->viewRenderer->setNoRender(true);
             
            $searchCampaign = $this->getRequest()->getParam('campaignName', null);
            $campaignModel = new Campaign_Model_Campaign();
            $res = $campaignModel->getCampaignsByName($searchCampaign);        
            
            echo json_encode($res);
        }

    File "Campaign.js", which contains the store definition:
    (I did not alter this file from the original)
    Code:
     constructor: function(config) {
    
    
            this.record = Ext.data.Record.create(this.recordDefinition);
    
    
            // set default config
            config = Ext.applyIf(config||{}, {
                
                baseParams  : {
                    start   : 0,
                    limit   : 25
                },
    
    
                sortInfo    : {
                    field       : 'start_time',
                    direction   : 'ASC'
                },
                
                reader : new Ext.data.JsonReader({
                    root            : 'records',
                    idProperty      : 'id_campaign',
                    totalProperty   : 'total',
                    successProperty : 'success',
                    messageProperty : 'message'
                }, this.record),
        
                writer : new Ext.data.JsonWriter({
                    encode          : true,
                    listful         : true,
                    writeAllFields  : true
                }),
        
                proxy : new Ext.data.HttpProxy({
                    api         : {
                        read    : '/campaign/index/get-campaigns',
                        create  : '/campaign/index/save-campaign',
                        update  : '/campaign/index/save-campaign',
                        destroy : '/campaign/index/delete-campaign'
                    },
                    listeners   : {                	
                        exception : function (proxy, type, action, options, response, arg ) {
                            if (type === 'remote' && response.raw.errors !== undefined) {
                                Campaign.eventManager.fireEvent('saveError', response.raw.errors);
                            }
                        }
                    }
                }),
                remoteSort  : true,
                autoLoad    : true,
                autoSave    : false
            });
        
            Campaign.Store.superclass.constructor.call(this, config);
    
    
            this.on('write', function(store, action, result) {
                Campaign.eventManager.fireEvent('save');
            });
        }

    The code that is returned by PHP is correct. If I do an alert on file "application.js" the variable "grid" contains the
    correct values from the search performed, but I cannot reload (or load?) the grid with the new values. On the file "application.js"
    above I've tried "bindStore", "load", "reload" and many others but they all produce the same result: nothing happens.


    Please help.

  2. #2
    Sencha User
    Join Date
    May 2012
    Posts
    3
    Vote Rating
    0
    Pipanni is on a distinguished road

      0  

    Default Solved it! :)

    Solved it! :)


    It turns out that the parameters being passed to the store were not formatted correctly. Too bad there was no error message to guide me. Anyway, it's solved at last.

  3. #3
    Sencha User
    Join Date
    Jan 2011
    Posts
    544
    Vote Rating
    52
    willigogs is a jewel in the rough willigogs is a jewel in the rough willigogs is a jewel in the rough

      0  

    Default


    I would recommend installing Firebug if haven't already. This tool is invaluable at debugging any JS based projects, and you would quickly eb able to check what params are being sent and received during all AJAX calls

    http://getfirebug.com/

  4. #4
    Sencha User
    Join Date
    May 2012
    Posts
    3
    Vote Rating
    0
    Pipanni is on a distinguished road

      0  

    Default


    Thanks willigogs, I was using Firebug, but there was no error message. The store behind the grid would accept the values I passed and then nothing would happen!

    Anyway, all is well now.

  5. #5
    Sencha User
    Join Date
    Jan 2011
    Posts
    544
    Vote Rating
    52
    willigogs is a jewel in the rough willigogs is a jewel in the rough willigogs is a jewel in the rough

      0  

    Default


    It is correct that you wouldn't receive any errors, since you were posting and successfully receiving a response from the server.

    However, Firebug logs all AJAX requests in the console, so you would've been able to quickly check which params were being sent, and what response was being returned from the server.

    console.log(variable) is an extremely valuable tool also...

Thread Participants: 1

Tags for this Thread

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi