PDA

View Full Version : Grid. Need set ID for cells



Romantik
1 Sep 2009, 10:46 PM
Hi all,

I'm trying build a Grid with data for cells.
The JSON data of it:


"columns": [
{"header": "Cat", "dataIndex":"category"},
{"header": "Part1", "dataIndex":"part_1"},
{"header": "Part2", "dataIndex":"part_2"},
{"header": "Part3", "dataIndex":"part_3"}
],
"records": [
{
"category": "C1",
"pid[0]": "0", "part_1": "",
"pid[1]": "21", "part_2": "P1-2",
"pid[2]": "0", "part_3": ""
}, {
"category": "C2",
"pid[0]": "41", "part_1": "P2-1",
"pid[1]": "18", "part_2": "P2-2",
"pid[2]": "0", "part_3": ""
}
]

it will generates next Grid (sorry for this example)
----------------------------
Cat | Part1 | Part2 | Part3 | <-columns
----------------------------
C1__|_____ | P1-2 |_____|
C2__| P2-1 | P2-2 |_____|

then I need get array of Parts by keys like:


cellclick: function(grid, rowIndex, colIndex, e) {
var cell = grid.store.getAt(rowIndex).data.pid[colIndex]; // <-- how to make here correct?
Ext.getCmp('selected').setValue(cell);
}

sure, I know about this:


cellclick: function(grid, rowIndex, colIndex, e) {
var record = grid.getStore.getAt(rowIndex);
var fieldName = grid.getColumnModel.getDataIndex(colIndex);
var data = record.get(fieldName);
}

it returns name of Part, but need the pID of the Part

Condor
2 Sep 2009, 12:35 AM
Use:

cellclick: function(grid, rowIndex, colIndex, e) {
var fieldName = grid.getColumnModel.getDataIndex(colIndex);
if(fieldName.substr(0, 5) == 'part_'){
var partNo = parseInt(fieldName.substr(5), 10);
var otherFieldName = 'pid[' + (partNo - 1) + ']';
var record = grid.getStore.getAt(rowIndex);
var value = record.get(otherFieldName);
...
}
}

Romantik
2 Sep 2009, 12:57 AM
Big thanks, dear Condor!
it works, but the Grid doesn't show any row when using in JSON data "pid[0]"
when I changed as "pid_0" and


var otherFieldName = 'pid_' + (partNo - 1);

all is fine =)