1. #1
    Sencha Premium Member
    Join Date
    Mar 2011
    Posts
    2
    Vote Rating
    0
    dotbombjoe is on a distinguished road

      0  

    Default RowExpander plugin and reliance on 'data'

    RowExpander plugin and reliance on 'data'


    I stumbled across the limitation of the rowexpander plugin not having access to data contained in associations.

    It makes me wonder why is it so common to pass raw 'data' to templates instead of a model directly? I know raw data can be easier to work with and a bit cleaner to look at in the code, but it feels like a break of encapsulation and an unnecessary limitation on what the template can do.

    Concrete Example:
    Consider a model of a Person model which includes a hasMany association to the Vehicle model. The vehicle model is known to have various 'types' (car, truck, bus...) and the model has a helper method to retrieve the records in the store of a given type. For a particular view, we'd like a list of all the people (in a grid) and, when a person is expanded, the list of all the cars (not trucks or buses...) with which they are associated are displayed in a template under the row.

    Seems like a great fit for rowexpander likely a reasonably common use-case.

    Currently, the rowexpander doesn't provide access to the vehicles at all because only the direct properties of person are available. Even if it did provide the data for the entire model (which could be easily accomplished by passing record.getData(true) instead of just 'data'), the template would still need logic to loop over the collection and only display the 'cars'. If instead, the model was passed in directly, the template could simply loop over the results from a call to the helper method responsible for returning the collection of cars.

    Pros and cons of every approach I suppose; with the effort to introduce an MVC architecture I'd hope the framework (and plugins!) would try to leverage the model more directly.

    I can address the issue easily enough by overriding getRowBodyFeatureData() and passing record instead of data...but is this something Sencha could/would address at some point?

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,087
    Vote Rating
    855
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Passing a Model instance is too heavy, XTemplate is setup to use a flat object/array/etc not a class.

    But you can always create an extension to handle associations, I did.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha Premium Member
    Join Date
    Mar 2011
    Posts
    2
    Vote Rating
    0
    dotbombjoe is on a distinguished road

      0  

    Default


    Ok. What is it about XTemplates that make it unsuitable for a class? You mention a model is too heavy -- does that mean there are performance problems or something of that nature when passing a model to an XTemplate?

    And when you say "extension to handle associations" do you mean you implemented a generic alteration that provides the data of the associations as part of the data package...like an xtemplate compiler extension? Or were you referring to some other technique of accomplishing the goal?

    We were thinking about something like:

    Code:
    Ext.define('Ext.ux.XTemplateCompiler', {
        extend: 'Ext.XTemplateCompiler',
     
        doFor: function (action, actions) {
            this.callParent(arguments);
     
            this.body.push('if (values.modelName && values.getData) { values=values.getData(true); }');
        }
    });
    But I'm still curious what makes a model too "heavy"/inappropriate as an input to an XTemplate. It appears to "work" (ie, if you pass a model you can interact with it the way you'd expect...).

Thread Participants: 1