1. #1
    Ext GWT Premium Member icfantv's Avatar
    Join Date
    Sep 2011
    Location
    Superior, CO
    Posts
    411
    Vote Rating
    21
    icfantv will become famous soon enough icfantv will become famous soon enough

      0  

    Question [SOLVED] Composite grid columns and/or extra columns outside bean

    [SOLVED] Composite grid columns and/or extra columns outside bean


    Is there a way to use/modify a ColumnConfig such that the value is derived from two fields off a bean?

    Additionally, what if I want to add an extra column that is not on the bean at all? How do I provide a value for row entries in this column?

    Thanks.

    --adam

  2. #2
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,717
    Vote Rating
    88
    Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light

      0  

    Default


    To access two fields, I would give the column access to the row itself (using IdentityValueProvider), and write a custom cell to render as much or as little of that model as you want.

    To access data outside the model used for the row? This would depend on where you are getting the data from - if you can look up that data with a reference to the bean itself, then, as above, use IdentityValueProvider, and use the row to find the data you need, and a custom cell to render it. If from some other source, I would need more information, or what you have tried so far, to make a suggestion.

  3. #3
    Ext GWT Premium Member icfantv's Avatar
    Join Date
    Sep 2011
    Location
    Superior, CO
    Posts
    411
    Vote Rating
    21
    icfantv will become famous soon enough icfantv will become famous soon enough

      0  

    Question


    @Colin, the second question was a hypothetical, I don't think I actually have a use case for it yet, but may at some point and wanted it in my toolkit if the need arose.

    RE, the composite field, I figured IdentityValueProvider<T> was the way to go, I just wasn't sure how to actually use it since the rest of my columns were coming from properties on my model (via PropertyAccess<T>) whose methods returned ValueProvider<T, ...> and I couldn't find an example anywhere. Is it as simple as changing the return type on the interface? If so, how then do I tell the grid what to do/render when it hits that column?

    The other thought I had was to try and use setCell(...) on ColumnConfig but there was no implementation of Cell that looked right to use and I wasn't keen on extending AbstractCell. Additionally, I wasn't sure if I could (or should) pass null into the constructor for ColumnConfig for the value provider.

    Thanks.

  4. #4
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,717
    Vote Rating
    88
    Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light

      0  

    Default


    We're still working up better docs and examples now that we have the moving parts working, so thanks for your feedback.

    ValueProvider is just an interface, which tells things that use it that they can get access to some value, based on a starting value. The primary use case (and the one that PropertyAccess deals with most readily) is where you need access to a property, a pair of methods to get and set the value. But there is no reason you can't build your own implementation of this.

    IdentityValueProvider is one such implementation - it just provides the model itself, but offers no way to assign the 'property' - it would need to have access to all references to that model anywhere. But for getting access to it, and its sub properties, it is a perfect fit (and what it was intended for).

    When you make a new cell for your custom behavior, the recomended way is to extend AbstractCell<C>, and implement the render method. If you need events, you'll need to get a little more advanced, by passing those events into the constructor, and implementing the onBrowserEvent method. But for most cases, render should be enough - if using an IdentityValueProvider, you'll get a reference to the row itself, and will be able to build up the content to draw based on any of those properties.

    ColumnConfig cannot at this time take a null ValueProvider, as that would leave it without a way to get a value and pass it to the cell, or attempt to render it without the cell.

    Examples of using the IdentityValueProvider to render Cells with an entire row:
    http://www.sencha.com/examples-dev/#...vancedcombobox - an x-template is used to render content for the cell, so html can be strung together without any risk of injected html into the page, potentially causing security issues or broken components
    http://www.sencha.com/examples-dev/#...owexpandergrid - content is directly appended to the SafeHtmlBuilder, which is useful to quickly build something simple, though may be annoying if you have a more complex dom

    Neither of those deal directly with grid cells, but both show how a Cell instance can be given data from the IdentityValueProvider. A few examples need to be updated (there no longer is a need to implement setValue yourself), but I think they get the idea across.

  5. #5
    Ext GWT Premium Member icfantv's Avatar
    Join Date
    Sep 2011
    Location
    Superior, CO
    Posts
    411
    Vote Rating
    21
    icfantv will become famous soon enough icfantv will become famous soon enough

      0  

    Question


    I do basically understand. I saw what I'd need to do with setCell(...) but am still not sure how to get the model in there. I have to construct a ColumnConfig with a ValueProvider as the first parameter. Here's my PropertyAccess definition:
    Code:
      interface AlertProperties extends PropertyAccess<Alert> {
    
        @Editor.Path("alertId")
        ModelKeyProvider<Alert> key();
        ValueProvider<Alert, String> alertId();
        ValueProvider<Alert, String> pattern();
        ValueProvider<Alert, Integer> thresholdCount();
        ValueProvider<Alert, Integer> thresholdSeconds();
        ValueProvider<Alert, Integer> frequencyCount();
        ValueProvider<Alert, Integer> frequencySeconds();
      }
    Basically, the count/seconds properties get combined to form a human-readable string. When I construct my ColumnConfig for the column that I want to house the combined data, I'm not sure how to construct it because if I call AlertProperties.thresholdCount() it returns a ValueProvider for an Integer (and I need the entire Alert object as you said so I can also get the thresholdSeconds value). Do I just say:
    Code:
    ColumnConfig<Alert, Alert> cc = new ColumnConfig(new IdentityValueProvider<Alert>(), ...);
    And then:
    Code:
    cc.setCell(new AbstractCell<Alert>() {
    
      @Override
      public void render(Context context, Alert alert, SafeHtmlBuilder sb) {
        // do stuff with Alert...
      }
    });
    Or, do I only need one and not both? Still a little confused. Thanks for your help.
    Last edited by icfantv; 22 Jan 2012 at 8:35 PM. Reason: removing extraneous whitespace

  6. #6
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,717
    Vote Rating
    88
    Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light

      0  

    Default


    Looks like you've got it exactly.
    Code:
    ColumnConfig<Alert, Alert> cc = new ColumnConfig(new IdentityValueProvider<Alert>(), ...);
    cc.setCell(new AbstractCell<Alert>() {
      @Override
      public void render(Context context, Alert alert, SafeHtmlBuilder sb) {
        // do stuff with Alert...
      }
    });
    and then go on to add that column to the grid.

  7. #7
    Ext GWT Premium Member icfantv's Avatar
    Join Date
    Sep 2011
    Location
    Superior, CO
    Posts
    411
    Vote Rating
    21
    icfantv will become famous soon enough icfantv will become famous soon enough

      0  

    Wink


    Awesome! Thanks so much. Will try first thing in the AM.

  8. #8
    Ext GWT Premium Member icfantv's Avatar
    Join Date
    Sep 2011
    Location
    Superior, CO
    Posts
    411
    Vote Rating
    21
    icfantv will become famous soon enough icfantv will become famous soon enough

      0  

    Default


    This solution worked. Thanks.

  9. #9
    Sencha User
    Join Date
    Dec 2011
    Posts
    19
    Vote Rating
    0
    p33t is on a distinguished road

      0  

    Default I didn't need ColumnConfig.setCell()

    I didn't need ColumnConfig.setCell()


    For what it's worth, I was trying to set up an editable grid on a form and found implementing my own ValueProvider worked better as the field then shows up as a label when doing a Row Editable Grid. A custom Cell.render() & IdentityValueProvider caused an unacceptable 'toString()' output to appear.

    The tricky bit was skipping the PropertyAccess<T> interface for instantiating my custom ValueProvider. EG: My FinishProvider does not appear on my ChildAccess. It is instantiated and supplied to the ColumnConfig constructor explicitly.

    Cheers,
    Pete

  10. #10
    Ext GWT Premium Member icfantv's Avatar
    Join Date
    Sep 2011
    Location
    Superior, CO
    Posts
    411
    Vote Rating
    21
    icfantv will become famous soon enough icfantv will become famous soon enough

      0  

    Default


    Thanks Pete. We aren't using editable grids so we didn't have to worry about that. Custom cells typically require a custom cell renderer to get the look exactly right, so that's what we went with.

    Incidentally, take a look at XTemplates: http://sencha.com/examples-dev/#ExamplePlace:templates. They're REALLY powerful and are significantly more easy to use (IMHO) than CompositeCell if you require any type of specialized layout.

Thread Participants: 2

Tags for this Thread