1. #1
    Sencha User
    Join Date
    Oct 2011
    Posts
    54
    Vote Rating
    0
    DarekKay is on a distinguished road

      0  

    Default Unanswered: Grid row rendering?

    Unanswered: Grid row rendering?


    I have a standard grid containing some domain objects (which have String/Integer/Boolean values) with a PropertyAccess to load those values automatically. This works very good and all values are rendered by the corresponding object values.

    Now I want to format/render my row by the object's boolean value. Assuming it's true, all corresponding cells should be rendered as <b>value</b> - and normally otherwise. The only way I've found so far was to create my column:
    Code:
    ColumnConfig c = new  ColumnConfig(new IdentityValueProvider<MyObject>(), ....);
    and to define the Cell:
    Code:
    column.setCell(new AbstractCell<MyObject>()
            {
                @Override
                public void render(com.google.gwt.cell.client.Cell.Context context, MyObject value,
                        SafeHtmlBuilder sb)
                {
                    if (value.isActive())
                        sb.appendHtmlConstant("<b>" + value.getName() + "</b>");
                    else 
                        sb.appendEscaped(value.getName());
                }
            });
    Having several columns I need to implement a different cell for each of them, containing almost the same code except the value.getName() part - seems pretty redundant to me. Is there no other way to achieve this?

    Using Firebug, I just added style="font-weight: bold" to the <tr> (or <table>) element containing my desired row. Is there any way to step into the row rendering process and add my style depending on the underlying object's value?

  2. #2
    Software Architect
    Join Date
    Sep 2007
    Posts
    13,971
    Answers
    60
    Vote Rating
    132
    sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light

      0  

    Default


    Having several columns I need to implement a different cell for each of them, containing almost the same code except the value.getName() part - seems pretty redundant to me. Is there no other way to achieve this?
    You could create a base class that has all your logic. You also do not have to use a IdentityValueProvider and so you would not need different cells. Instead of using AbstractCell you can also use TextCell with a custom SafeHtmlRenderer

  3. #3
    Sencha User
    Join Date
    Oct 2011
    Posts
    54
    Vote Rating
    0
    DarekKay is on a distinguished road

      0  

    Default


    Thank you for your reply.

    The problem is: such a custom cell renderer has no knowledge about other cells or object values (which is understandable) - and that's the point: I want to set a different style/renderer depending on values from another column. Maybe that's what you mean by "create a base class that has all your logic" - but how exactly would that look like?

  4. #4
    Sencha User
    Join Date
    Jan 2012
    Posts
    21
    Vote Rating
    0
    robferguson is on a distinguished road

      0  

    Default


    Hi,

    You can access other columns in your custom render() method. Construct your grid as normal (with a store and column model).

    For example:

    Code:
      @Inject
      public AbstractAdministrationView() {
        super();
    
        this.setGrid(new ContextAreaGrid(new ContextAreaModelListStore(), getContextAreaColumModel()));
        this.grid.setSize(CONTEXT_AREA_WIDTH, CONTEXT_AREA_HEIGHT);
    
        // add the Grid to the View's layout container
        this.panel.add(this.grid, new VerticalLayoutData(1, 1)); 
    
        ...
    
      }
    Then access your model (row) in the render method:

    Code:
      public ColumnModel<ContextAreaModel> getContextAreaColumModel() {
    
        ...
    
        ColumnConfig<ContextAreaModel, String> column1DisplayNameColumnConfig = new ColumnConfig<ContextAreaModel, String>(property.column1DisplayName(),
                ContextAreaGrid.DISPLAY_NAME_COLUMN_WIDTH, "");
        column1DisplayNameColumnConfig.setCell(new AbstractSafeHtmlCell<String>(SimpleSafeHtmlRenderer.getInstance()) {
          @Override
          protected void render(Context context, SafeHtml data, SafeHtmlBuilder sb) {
    
            if (data == null) {
              return;
            }
    
            ContextAreaModel model = (ContextAreaModel) getGrid().getStore().get(context.getIndex());
    
            sb.appendHtmlConstant("<span>"  + "<b>" + data.asString() + "</b><br />" + model.getColumn1Description() + "</span>");
          }
        });
    
       ...
    
        List<ColumnConfig<ContextAreaModel, ?>> columnConfigList = new ArrayList<ColumnConfig<ContextAreaModel, ?>>();
        columnConfigList.add(column1IconColumnConfig);
        columnConfigList.add(column1DisplayNameColumnConfig);
        columnConfigList.add(column2IconColumnConfig);
        columnConfigList.add(column2DisplayNameColumnConfig);
    
        ColumnModel<ContextAreaModel> columnModel = new ColumnModel<ContextAreaModel>(columnConfigList);
    
        return columnModel;
      }
    The context passed to your render() method includes the index of the row (context.getIndex())

    Cheers
    Rob

    http://code.google.com/p/gwt-cx/

  5. #5
    Sencha User
    Join Date
    Oct 2011
    Posts
    54
    Vote Rating
    0
    DarekKay is on a distinguished road

      0  

    Default


    I think this is GXT 2 code, but nevertheless it led me to the solution

    Big Thanks!

Thread Participants: 2

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