Question

I have an issue to set fields of layer in dGrid.

store = new Memory({data: someData});
grid = new Grid({
    store: store
});

layout = {[label: 'ID', field: '@attributes', formatter: getId]};

grid.set('columns', layout);

the someData is an object with the following structure

someData = {
{@attributes: {
    id: someId
}},
{@attributes: {
    id: someId
}},
};

getId = function (value, rowId) {
return value.id;
};

well, it cannot get the Id or anything.

I appreciate any suggestion. Thanks in advance :)

Was it helpful?

Solution 2

The solution was pretty simple, as you guys would already know, to access an object with @ symbol you need bracket notation. Since dGrid supports formatter you can achieve the task by doing like this

layout = {[
    label: 'ID', field: '@attributes', formatter: function (value) {
        return value['@attributes'].id;}
]};

And that will display ID value in @attributes.

OTHER TIPS

You obviously can't access it using dot notation. You will have to use square bracket notation.

someData['@attributes'].id

It's unclear if getId is something you created or part of dgrid and you aren't able to change it. If the latter, you should rename the @attributes property after you've accessed it but before you send it to dgrid.

someData.attributes = someData['@attributes'];
delete someData['@attributes'];
// send it off to dgrid...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top