0

I try to set a field value to a value which is type of array, but the grid can't display the row. my test codes shows below:

Ext.onReady(function()
{
    new Ext.grid.property.Grid(
    {
        customRenderers:{Test:function(v)
        {
            return Ext.Array.sum(v);
        }},
        source:{Test:[1,2,3]},
        renderTo:Ext.getBody()
    });
});

But if the field value is other type, the row is shown.

Ext.onReady(function()
{
    new Ext.grid.property.Grid(
    {
        customRenderers:{Test:function(v)
        {
            return Ext.Array.sum(v);
        }},
        source:{Test:6},
        renderTo:Ext.getBody()
    });
});

Can prroperty grid custom render an array value?

Thank you for any help in advance!

Sharp Kid
  • 135
  • 1
  • 4
  • 14

1 Answers1

0

You could just do it in a function ahead of time:

Ext.onReady(function()
{
    new Ext.grid.property.Grid(
        {
            customRenderers:{Test:function(v)
            {
                return Ext.Array.sum(v);
            }},
            source: sumArraysInObject({Test:[1,2,3]}),
            renderTo:Ext.getBody()
        });
});

function sumArraysInObject(obj) {
    for (var key in obj) {
        if (obj.hasOwnProperty(key) && Object.prototype.toString.call(obj[key]) === "[object Array]") {
            var sum = 0;
            for (var i = 0, l = obj[key].length; i < l; i++) {
                sum = sum + obj[key][i];
            }
            obj[key] = sum;
        }
    }
    return obj;
}
Stephen Tremaine
  • 934
  • 6
  • 15
  • Indeed, I want to display the value by a "Ext.form.field.Trigger" and edit the value by clicking the "trigger". so if the source is getten by a function, the value will be unable to edit. – Sharp Kid Oct 26 '12 at 02:11