Results 1 to 8 of 8

Thread: Colored Numbers in cells (PivotGrid)

  1. #1
    Ext User
    Join Date
    Oct 2008
    Location
    Berlin (Germany)
    Posts
    6

    Default Colored Numbers in cells (PivotGrid)

    Hello,

    i need a little help!
    How can i set different color for the value in a cell (PivotGrid)?
    I get the value and the color (for example "red") from server. I want set the style (color: red) of the cell.

    Greeting
    Mario

  2. #2

    Default

    There is an example of cell coloring for PivotGrid, but not with a separate color value:
    http://dev.sencha.com/deploy/dev/exa...countries.html

    If you want to change the color in a GridPanel based on a separate color value, you could use a renderer function: (see http://dev.sencha.com/deploy/dev/doc...ember=renderer)
    PHP Code:
    {
        
    header'My colored col',
        
    dataIndex'value',
        
    renderer: function(valmetarec) {
            
    meta.attr =  'style="color:'rec.get('color') +';"';
            return 
    Ext.util.Format.htmlEncode(val);
        }

    I think this doesn't work for a PivotGrid though, because the renderers only given argument is the value of the cell.
    Last edited by JanVenekamp; 15 Nov 2010 at 10:24 AM. Reason: typo

  3. #3
    Ext User
    Join Date
    Oct 2008
    Location
    Berlin (Germany)
    Posts
    6

    Default

    Hello,

    thanks for your help.

    First, my idea was it to use the renderer method of the PivotGrid. Unfortunately you get only the value...
    Hmmmm.... I look further to solve the problem... Or have somebody a tip for me?

    Greetings
    Mario

  4. #4
    Sencha User laurentParis's Avatar
    Join Date
    Aug 2010
    Location
    paris
    Posts
    246

    Default

    like JanVenekamp explain to you, parameter "rec" (alias records) contain all data sending by your server !!!

  5. #5
    Ext User
    Join Date
    Oct 2008
    Location
    Berlin (Germany)
    Posts
    6

    Default

    Hi,

    i understand. But the renderer method of the PivotGrid only given the value as argument. Or i cant see what you mean???

  6. #6
    Sencha User laurentParis's Avatar
    Join Date
    Aug 2010
    Location
    paris
    Posts
    246

    Default

    PivotGrid extend GridPanel ?

  7. #7

    Default

    @laurentParis PivotGrid uses another renderer under the bonnet, so the call to your custom renderer is different. (not in the docs though)

    A solution to your problem might be to write your own aggregator function (http://dev.sencha.com/deploy/dev/doc...ber=aggregator) that returns the value and the color as the 'value'. And a custom renderer that takes the value out of the 'value' and a getCellCls function that sets the right class based on the color.

    If you don't want to define classes for each color you have to override the renderRows function such that the renderer has the meta argument. Then you can set the style attribute as in my above example:

    PHP Code:
    Ext.override(Ext.grid.PivotGridView, {
        
    /**
         * @private
         * Renders rows between start and end indexes
         * @param {Number} startRow Index of the first row to render
         * @param {Number} endRow Index of the last row to render
         */
        
    renderRows : function(startRowendRow) {
            var 
    grid          this.grid,
                
    rows          grid.extractData(),
                
    rowCount      rows.length,
                
    templates     this.templates,
                
    renderer      grid.renderer,
                
    hasRenderer   typeof renderer == 'function',
                
    getCellCls    this.getCellCls,
                
    hasGetCellCls typeof getCellCls == 'function',
                
    cellTemplate  templates.cell,
                
    rowTemplate   templates.row,
                
    rowBuffer     = [],
                
    meta          = {},
                
    tstyle        'width:' this.getGridInnerWidth() + 'px;',
                
    colBuffercolumni;
            
            
    startRow startRow || 0;
            
    endRow   Ext.isDefined(endRow) ? endRow rowCount 1;
            
            for (
    0rowCounti++) {
                
    row rows[i];
                
    colCount  row.length;
                
    colBuffer = [];
                
                
    rowIndex startRow i;

                
    //build up each column's HTML
                
    for (0colCountj++) {
                    
    cell row[j];

                    
    meta.css   === 'x-grid3-cell-first ' : (== (colCount 1) ? 'x-grid3-cell-last ' '');
                    
    meta.attr  meta.cellAttr '';
                    
    meta.value cell;

                    if (
    Ext.isEmpty(meta.value)) {
                        
    meta.value ' ';
                    }
                    
                    if (
    hasRenderer) {
                        
    meta.value renderer(meta.valuemeta);
                    }
                    
                    if (
    hasGetCellCls) {
                        
    meta.css += getCellCls(meta.value) + ' ';
                    }

                    
    colBuffer[colBuffer.length] = cellTemplate.apply(meta);
                }
                
                
    rowBuffer[rowBuffer.length] = rowTemplate.apply({
                    
    tstyletstyle,
                    
    cols  colCount,
                    
    cells colBuffer.join(""),
                    
    alt   ''
                
    });
            }
            
            return 
    rowBuffer.join("");
        }
    }); 

  8. #8
    Ext User
    Join Date
    Oct 2008
    Location
    Berlin (Germany)
    Posts
    6

    Default

    Hello JanVenekamp,

    i solved the problem with an aggregator function. Thank you very much for your help!!

Similar Threads

  1. Colored grid columns
    By elbino in forum Ext 3.x: Help & Discussion
    Replies: 29
    Last Post: 15 Sep 2010, 1:04 AM
  2. Colored text box
    By lijojoy_hai in forum Ext 3.x: Help & Discussion
    Replies: 1
    Last Post: 30 Nov 2009, 7:15 AM
  3. Horizontal Colored Bar
    By ext_fan in forum Ext 2.x: Help & Discussion
    Replies: 1
    Last Post: 16 Jun 2008, 12:39 AM
  4. Colored comboBox
    By Nox Noctis in forum Ext 2.x: Help & Discussion
    Replies: 6
    Last Post: 10 Mar 2008, 1:11 AM

Tags for this Thread

Posting Permissions

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