PDA

View Full Version : problem dynamically configuring a grid



perin.massimo
7 Jun 2012, 9:07 AM
I'm trying to dynamically configure a grid from a servlet using ExtJs 4.1.

This is the json that i generate:


{
"results": [
{
"id": 1,
"des_elemento": "Potenzialitą frigorifera (kW)",
"col1": "32",
"col2": "36.4",
"col3": "44.1",
"col4": "51.5",
"col5": "61.5",
"col6": "73.9",
"col7": "89.7",
"col8": "106.1"
},
{
"id": 2,
"des_elemento": "Potenzialitą sensibile (kW)",
"col1": "21",
"col2": "24.4",
"col3": "29",
"col4": "34.4",
"col5": "41.8",
"col6": "44.7",
"col7": "60.8",
"col8": "72.3"
},
{
"id": 3,
"des_elemento": "Potenza assorbita compressori (kW)",
"col1": "8.9",
"col2": "10.5",
"col3": "12.6",
"col4": "14",
"col5": "16.9",
"col6": "18.6",
"col7": "22.3",
"col8": "23.8"
},
{
"id": 6,
"des_elemento": "EER",
"col1": "3.57",
"col2": "3.46",
"col3": "3.49",
"col4": "3.68",
"col5": "3.64",
"col6": "3.97",
"col7": "4.02",
"col8": "4.46"
},
{
"id": 7,
"des_elemento": "Potenzialitą termica (kW)",
"col1": "35.4",
"col2": "40.6",
"col3": "50.4",
"col4": "58.2",
"col5": "70.5",
"col6": "82.5",
"col7": "98.8",
"col8": "112.7"
},
{
"id": 8,
"des_elemento": "Potenza assorbita compressori (kW)",
"col1": "6.7",
"col2": "7.8",
"col3": "9.2",
"col4": "10.9",
"col5": "12.2",
"col6": "14.3",
"col7": "16.5",
"col8": "18.2"
},
{
"id": 10,
"des_elemento": "COP",
"col1": "5.28",
"col2": "5.19",
"col3": "5.5",
"col4": "5.36",
"col5": "5.78",
"col6": "5.78",
"col7": "6",
"col8": "6.2"
},
{
"id": 11,
"des_elemento": "Tipo compressori",
"col1": "Scroll",
"col2": "Scroll",
"col3": "Scroll",
"col4": "Scroll",
"col5": "Scroll",
"col6": "Scroll",
"col7": "Scroll",
"col8": "Scroll"
},
{
"id": 12,
"des_elemento": "N° compressori",
"col1": "2",
"col2": "2",
"col3": "2",
"col4": "2",
"col5": "2",
"col6": "2",
"col7": "2",
"col8": "2"
},
{
"id": 15,
"des_elemento": "Gradini capacitą Std",
"col1": "3",
"col2": "3",
"col3": "2",
"col4": "3",
"col5": "3",
"col6": "3",
"col7": "3",
"col8": "2"
},
{
"id": 20,
"des_elemento": "Carica refrigerante (C1) (kg)",
"col1": "10.5",
"col2": "10",
"col3": "16",
"col4": "16",
"col5": "19",
"col6": "20",
"col7": "26",
"col8": "30"
},
{
"id": 21,
"des_elemento": "Circuiti refrigeranti",
"col1": "1",
"col2": "1",
"col3": "1",
"col4": "1",
"col5": "1",
"col6": "1",
"col7": "1",
"col8": "1"
},
{
"id": 35,
"des_elemento": "Tipo ventilatore mandata",
"col1": "RAD",
"col2": "RAD",
"col3": "RAD",
"col4": "RAD",
"col5": "RAD",
"col6": "RAD",
"col7": "RAD",
"col8": "RAD"
},
{
"id": 36,
"des_elemento": "Numero ventilatori Mandata",
"col1": "1",
"col2": "1",
"col3": "1",
"col4": "1",
"col5": "1",
"col6": "1",
"col7": "2",
"col8": "2"
},
{
"id": 38,
"des_elemento": "Diametro ventilatori (mm)",
"col1": "450",
"col2": "500",
"col3": "500",
"col4": "500",
"col5": "560",
"col6": "630",
"col7": "500",
"col8": "500"
},
{
"id": 42,
"des_elemento": "Portata aria mandata (l/s)",
"col1": "1250",
"col2": "1444",
"col3": "1667",
"col4": "1944",
"col5": "2500",
"col6": "3056",
"col7": "3611",
"col8": "4444"
},
{
"id": 43,
"des_elemento": "Potenza unitaria installata (kW)",
"col1": "1",
"col2": "2.7",
"col3": "2.7",
"col4": "2.7",
"col5": "3.1",
"col6": "3.2",
"col7": "2.7",
"col8": "2.7"
},
{
"id": 44,
"des_elemento": "Max pressione statica mandata (Pa)",
"col1": "400",
"col2": "670",
"col3": "650",
"col4": "610",
"col5": "580",
"col6": "480",
"col7": "670",
"col8": "490"
},
{
"id": 87,
"des_elemento": "Scarico condensa",
"col1": "1\" Gas",
"col2": "1\" Gas",
"col3": "1\" Gas",
"col4": "1\" Gas",
"col5": "1\" Gas",
"col6": "1\" Gas",
"col7": "1\" Gas",
"col8": "1\" Gas"
},
{
"id": 202,
"des_elemento": "Alimentazione standard (V)",
"col1": "400/3~/50",
"col2": "400/3~/50",
"col3": "400/3~/50",
"col4": "400/3~/50",
"col5": "400/3~/50",
"col6": "400/3~/50",
"col7": "400/3~/50",
"col8": "400/3~/50"
},
{
"id": 685,
"des_elemento": "attacchi batteria ad acqua",
"col1": "1\" 1/2",
"col2": "1\" 1/2",
"col3": "1\" 1/2",
"col4": "1\" 1/2",
"col5": "2\"",
"col6": "2\"",
"col7": "2\"",
"col8": "2\""
},
{
"id": 1022,
"des_elemento": "Tipo ventilatore espulsione",
"col1": "RAD",
"col2": "RAD",
"col3": "RAD",
"col4": "RAD",
"col5": "RAD",
"col6": "RAD",
"col7": "RAD",
"col8": "RAD"
},
{
"id": 1023,
"des_elemento": "Numero ventilatori espulsione",
"col1": "1",
"col2": "1",
"col3": "1",
"col4": "1",
"col5": "1",
"col6": "1",
"col7": "1",
"col8": "2"
},
{
"id": 1025,
"des_elemento": "Diametro ventilatori (mm)",
"col1": "450",
"col2": "450",
"col3": "500",
"col4": "500",
"col5": "560",
"col6": "560",
"col7": "630",
"col8": "500"
},
{
"id": 1029,
"des_elemento": "Portata aria espulsa (l/s)",
"col1": "1189",
"col2": "1372",
"col3": "1583",
"col4": "1847",
"col5": "2375",
"col6": "2902",
"col7": "3430",
"col8": "4222"
},
{
"id": 1030,
"des_elemento": "Potenza unitaria installata (kW)",
"col1": "1",
"col2": "1",
"col3": "2.7",
"col4": "2.7",
"col5": "3.1",
"col6": "3.1",
"col7": "3.2",
"col8": "2.7"
},
{
"id": 1031,
"des_elemento": "Max pressione statica espulsione (Pa)",
"col1": "380",
"col2": "300",
"col3": "610",
"col4": "600",
"col5": "580",
"col6": "390",
"col7": "350",
"col8": "490"
},
{
"id": 4147,
"des_elemento": "Schema elettrico",
"col1": "5F2402 R7",
"col2": "5F2402 R7",
"col3": "5F2402 R7",
"col4": "5F2402 R7",
"col5": "5F2402 R7",
"col6": "5F2402 R7",
"col7": "5F2402 R7",
"col8": "5F2402 R7"
},
{
"id": 4176,
"des_elemento": "Pressione Massima (HP) (MPa)",
"col1": "4.05",
"col2": "4.05",
"col3": "4.05",
"col4": "4.05",
"col5": "4.05",
"col6": "4.05",
"col7": "4.05",
"col8": "4.05"
},
{
"id": 4177,
"des_elemento": "Pressione Massima (LP) (MPa)",
"col1": "-",
"col2": "-",
"col3": "-",
"col4": "3",
"col5": "3",
"col6": "3",
"col7": "3",
"col8": "3"
},
{
"id": 4180,
"des_elemento": "Temperatura Minima di Stock (°C)",
"col1": "-10",
"col2": "-10",
"col3": "-10",
"col4": "-10",
"col5": "-10",
"col6": "-10",
"col7": "-10",
"col8": "-10"
},
{
"id": 4181,
"des_elemento": "Temperatura Massima di Stock (°C)",
"col1": "50",
"col2": "50",
"col3": "50",
"col4": "50",
"col5": "50",
"col6": "50",
"col7": "50",
"col8": "50"
},
{
"id": 4182,
"des_elemento": "Pressione (HP) (MPa)",
"col1": "4.5",
"col2": "4.5",
"col3": "4.5",
"col4": "4.5",
"col5": "4.5",
"col6": "4.5",
"col7": "4.5",
"col8": "4.5"
},
{
"id": 4183,
"des_elemento": "categoria",
"col1": "2",
"col2": "2",
"col3": "2",
"col4": "2",
"col5": "2",
"col6": "2",
"col7": "2",
"col8": "2"
},
{
"id": 26096,
"des_elemento": "Codice Scambiatore Designer",
"col1": "BW5F4003",
"col2": "BW5F4003",
"col3": "BW5F4002",
"col4": "BW5F4002",
"col5": "BW5F4000",
"col6": "BW5F4000",
"col7": "BW5F4001",
"col8": "BW5F4001"
}
],
"metaData": {
"fields": [
{
"name": "id",
"type": "int",
"persist": false
},
{
"name": "des_elemento",
"type": "string",
"persist": false
},
{
"name": "col1",
"type": "string",
"persist": false
},
{
"name": "col2",
"type": "string",
"persist": false
},
{
"name": "col3",
"type": "string",
"persist": false
},
{
"name": "col4",
"type": "string",
"persist": false
},
{
"name": "col5",
"type": "string",
"persist": false
},
{
"name": "col6",
"type": "string",
"persist": false
},
{
"name": "col7",
"type": "string",
"persist": false
},
{
"name": "col8",
"type": "string",
"persist": false
}
],
"columns": [
{
"sortable": false,
"draggable": false,
"hideable": false,
"hidden": true,
"groupable": false,
"menuDisabled": true,
"text": "ID",
"dataIndex": "id",
"width": 10
},
{
"sortable": false,
"draggable": false,
"hideable": false,
"hidden": false,
"groupable": false,
"menuDisabled": true,
"text": "Elementi",
"dataIndex": "des_elemento",
"width": 200
},
{
"sortable": false,
"draggable": false,
"hideable": false,
"hidden": false,
"groupable": false,
"menuDisabled": true,
"text": "45",
"dataIndex": "col1",
"width": 50
},
{
"sortable": false,
"draggable": false,
"hideable": false,
"hidden": false,
"groupable": false,
"menuDisabled": true,
"text": "52",
"dataIndex": "col2",
"width": 50
},
{
"sortable": false,
"draggable": false,
"hideable": false,
"hidden": false,
"groupable": false,
"menuDisabled": true,
"text": "60",
"dataIndex": "col3",
"width": 50
},
{
"sortable": false,
"draggable": false,
"hideable": false,
"hidden": false,
"groupable": false,
"menuDisabled": true,
"text": "70",
"dataIndex": "col4",
"width": 50
},
{
"sortable": false,
"draggable": false,
"hideable": false,
"hidden": false,
"groupable": false,
"menuDisabled": true,
"text": "90",
"dataIndex": "col5",
"width": 50
},
{
"sortable": false,
"draggable": false,
"hideable": false,
"hidden": false,
"groupable": false,
"menuDisabled": true,
"text": "110",
"dataIndex": "col6",
"width": 50
},
{
"sortable": false,
"draggable": false,
"hideable": false,
"hidden": false,
"groupable": false,
"menuDisabled": true,
"text": "130",
"dataIndex": "col7",
"width": 50
},
{
"sortable": false,
"draggable": false,
"hideable": false,
"hidden": false,
"groupable": false,
"menuDisabled": true,
"text": "160",
"dataIndex": "col8",
"width": 50
}
],
"columnsId": [
1779,
214,
2253,
2266,
2339,
2340,
2341,
2342
],
"totalProperty": "total",
"successProperty": "success",
"root": "results",
"messageProperty": "message",
"idProperty": "id",
"gridTitle": "dati tecnici"
},
"total": 35,
"success": true
}

this is the code that handle the regeneration of the grid:


Ext.ns("clivet.gct.metagrid");

Ext.define('clivet.gct.metagrid.model', {
extend: 'Ext.data.Model',
fields: []
});

clivet.gct.metagrid.store = null;
clivet.gct.metagrid.grid = null;
clivet.gct.metagrid.ids = [];

clivet.gct.metagrid.createGrid = function(gridTitle) {

clivet.gct.metagrid.store = new Ext.data.JsonStore({
autoLoad: false,
autoSync: false,
model: "clivet.gct.metagrid.model",
proxy: {
timeout: 180000,
type: 'ajax',
api: {
read: 'grid/read',
create: 'grid/create',
update: 'grid/update',
destroy:'grid/delete'
},
reader: {
type: 'json',
root: 'results',
totalProperty: 'total'
},
listeners: {
'metachange': function(store, meta) {
clivet.gct.metagrid.grid.setTitle(meta.gridTitle);
clivet.gct.metagrid.ids = meta.columnsId;
clivet.gct.metagrid.grid.reconfigure(store, meta.columns);
}
}
}
});

clivet.gct.metagrid.grid = Ext.create('Ext.grid.Panel', {
autoRender: true,
title: gridTitle,
store: clivet.gct.metagrid.store,
region: 'center',
columnLines: true,
columns: [],
layout: 'fit',
viewConfig: {
stripeRows: true
}
});

return clivet.gct.metagrid.grid;
};

In the metachange event when i try to call reconfigure i get always an "Cannot call method 'substring' of undefined" exception!

Anyone could help me please?

perin.massimo
7 Jun 2012, 11:48 PM
+1.
I need at least a clue to detect where is the error please. :s

perin.massimo
27 Jun 2012, 1:52 AM
Solved by mineself >:)