Skip to content

Instantly share code, notes, and snippets.

@cmilfont
Created February 4, 2011 22:34
Show Gist options
  • Save cmilfont/811915 to your computer and use it in GitHub Desktop.
Save cmilfont/811915 to your computer and use it in GitHub Desktop.
var FactoryForm = function() {
var form = new Ext.form.FormPanel({
width: 400, height: 150, frame: true
, defaults : {
margins: {top:15, right:0, bottom:0, left:5}
}
, defaultType: "textfield"
, items: [
{name:"nome", fieldLabel : "Nome"}
, {name:"descricao", fieldLabel : "Descrição"}
, {xtype: "datefield", name:"created_at", fieldLabel : "Data Criação"}
, {xtype: "hidden", name: "id"}
]
});
return form;
};
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 rec = grid.getSelectionModel().getSelected();
var win = new Ext.Window({
modal:true, title: "Curso", width: 300, height: 177,
items:[new FactoryForm()]
});
win.show();
win.items.get(0).getForm().loadRecord(rec);
}
}
, style: "margin: auto;"
});
grid.render("treinamento");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment