Skip to content

Instantly share code, notes, and snippets.

@norbajunior
Forked from cmilfont/cursos_grid.js
Created February 5, 2011 17:43
Show Gist options
  • Save norbajunior/812628 to your computer and use it in GitHub Desktop.
Save norbajunior/812628 to your computer and use it in GitHub Desktop.
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