Results 1 to 6 of 6

Thread: Accessing Viewcontroller from within renderer of grid

  1. #1
    Sencha Premium Member
    Join Date
    Mar 2012
    Posts
    85
    Vote Rating
    3
      0  

    Default Accessing Viewcontroller from within renderer of grid

    I'm having difficulty accessing my Viewcontroller within the renderer of a grid column.

    I have a basic border panel, with a center and north region. In the north region is a grid which is bound to a store that's created from my viewmodel, this all works flawlessly.

    I can access functions within my Viewcontroller just fine if I use listeners/handlers of any of my components/buttons/panels etc, but I can't seem to reference it from within the renderer function of a grid cell.

    I essentially have some math calculations that are performed and the result is returned to a variable which then displays in the grid.

    In the old days, I could just run a MyApp.app.getController('controllername').function() and all was well, but I can't seem to figure out the equivalent for that on a viewcontroller.

    Any ideas on how I can reference my viewcontroller from within the view it's bound to, on a grid renderer function?

  2. #2
    Sencha - Community Support Team jsakalos's Avatar
    Join Date
    Apr 2007
    Location
    Slovakia
    Posts
    27,664
    Answers
    512
    Vote Rating
    403
      0  

    Default

    I wouldn't put these calculations in the controller but in a mixin. Then I'd mix in the mixin into the grid to make the calculation available as the grid's method. Also, mixin can be then used in any grid (or even other components) if required.
    Jozef Sakalos, aka Saki

    Education, extensions and services for developers at new http://extjs.eu
    News: Grid MultiSearch Plugin, Grid MultiSort Plugin, Configuring ViewModel Hierarchy


  3. #3
    Sencha Premium Member
    Join Date
    Mar 2012
    Posts
    85
    Vote Rating
    3
      0  

    Default

    Do you have an example of how to do that? I've never done it that way. I have several chained functions in my controller I use throughout the app. For simplicity, I'd like to keep it the way it is for now.But if the mixin method can call stores, models, and other functions I could migrate everything that way, but again, I'd need an example to wrap my head around it.

  4. #4
    Sencha Premium Member
    Join Date
    Mar 2012
    Posts
    85
    Vote Rating
    3
      0  

    Default

    I ended up just calling the function directly via the renderer config value like so:


    Before: (Not working)
    Code:
               xtype: 'gridcolumn',
               renderer: function(value, metaData, record, rowIndex, colIndex, store, view) {
                     var newval = this.getStatus();
                    metaData.tdAttr = 'data-qtip="' + newval + '"';
                    return newval;
                },
                width: 70,
                text: 'Status'

    To this: (working)
    Code:
               xtype: 'gridcolumn',
                renderer: 'getStatus',
                width: 70,
                text: 'Status'

    It makes sense, but I'd still like to know how to call the Viewcontroller directly should I ever need to, as MyApp.app.getController does not seem to get me to any of my Viewcontrollers.

  5. #5
    Sencha - Community Support Team jsakalos's Avatar
    Join Date
    Apr 2007
    Location
    Slovakia
    Posts
    27,664
    Answers
    512
    Vote Rating
    403
      0  

    Default

    Not a ready made example (yet) but consider mixin as a repository of methods you can add to the grid. These methods then become the grid's methods so you can use this.getStore() or any other grid's methods and properties.
    Jozef Sakalos, aka Saki

    Education, extensions and services for developers at new http://extjs.eu
    News: Grid MultiSearch Plugin, Grid MultiSort Plugin, Configuring ViewModel Hierarchy


  6. #6

    Join Date
    Mar 2017
    Location
    Lisbon
    Posts
    9
    Vote Rating
    0
      0  

    Default

    Hi.

    I'm trying to do the same thing. Start in renderer function call a function in ViewController, just because I defined a formatCurrency function in the ViewController and now I want to reuse that function.
    Do you understand how to do? You are using Sencha Architect 4? I do not understand how to do using Sencha Architect.

    Regards,
    AB

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •