Created
February 3, 2011 18:01
-
-
Save cmilfont/809879 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var instrutor = function(json, record) { | |
var nome = ""; | |
record.instrutores.forEach(function(inst){ nome += (inst.nome + ", ") }); | |
return nome; | |
} | |
var CursoFactory = Ext.data.Record.create(["id", "nome", "descricao", | |
{name:"instrutores", convert: instrutor}]); | |
var store = new Ext.data.Store({ | |
url: "/cursos.json", | |
reader: new Ext.data.JsonReader({ | |
id: "id", root: "results", total: "total" | |
}, CursoFactory) | |
}) | |
store.load(); | |
var grid = new Ext.grid.GridPanel({ | |
store: store | |
, colModel: new Ext.grid.ColumnModel({ | |
columns: [ | |
{id:"id", header: "Id", width: 20, sortable: true, dataIndex: "id"} | |
, {header: "Nome", width: 200, sortable: true, dataIndex: "nome"} | |
, {header: "Descrição", width: 200, sortable: true, dataIndex: "descricao"} | |
, {header: "Instrutores", width: 200, sortable: true, dataIndex: "instrutores"} | |
] | |
}) | |
, sm: new Ext.grid.RowSelectionModel() | |
, title: "Cursos", width: 600, height: 300, frame: true | |
, listeners: { | |
rowdblclick : function( grid, rowIndex, event ) { | |
var json = grid.getSelectionModel().getSelected().json; | |
var win = new Ext.Window({ | |
modal:true, title: "Curso", width: 300, height: 200 | |
}); | |
win.show(); | |
} | |
} | |
, style: "margin: auto;" | |
}); | |
grid.render("treinamento"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
var json = {
id:5,
nome:"Sencha Avançado",
descricao: "Introdução ao Framework de propósito geral Sencha",
justificativa: "Linguagem mais usada no mundo e exclusivo no client-side",
instrutores: [{id: 2, nome: "Christiano Martins"}],
ementa: [
{
id:9,
topico: "Ext-core",
topicos: [{id: 10, topico: "Variáveis"}]
},
{
id: 11,
topico: "Extjs",
topicos: [{id: 12, topico: "Fluxos de repetição"}]
}
]
};
var curso = new CursoFactory(json);
store.add(curso);
//store.save()