PDA

View Full Version : getSelectedRecords... dataview



danielbertini
5 Aug 2009, 10:34 AM
When i need get ID from tree i use this:


var sm = tree.getSelectionModel();
var node = sm.getSelectedNode();


The question is how to get the id of an image that was selected in a DataView?
The code is:


var xd = Ext.data;

var store = new Ext.data.JsonStore({
url:'blogdiretorio/gridfiles',
root:'results',
totalProperty:'totalCount',
remoteSort:false,
fields:[{name:'id'},{name:'arquivo'},{name:'arquivo_thumb'}]
});


var tpl = new Ext.XTemplate(
'<tpl for=".">',
'<div class="thumb-wrap" id="{id}">',
'<div class="thumb"><img src="uploads/blog/{arquivo_thumb}" title="{arquivo}"></div>',
'<span class="x-editable">{shortName}</span></div>',
'</tpl>',
'<div class="x-clear"></div>'
);

var arquivos = new Ext.Panel({
id:'images-view',
title:'Imagens (Nenhuma selecionada)',
region:'center',
autoScroll:true,
split:true,
collapsible:false,
margins:'5 5 5 0',
cmargins:'5 5 5 5',
tbar:[
{text:'Adicionar', id:'blogimagensarquivo-enviar', disabled:true, iconCls:'icon-add', handler: function(){ addArquivo(); }}, '-',
{text:'Renomear', id:'blogimagensarquivo-renomear', disabled:true, iconCls:'icon-edit', handler: function(){ editArquivo(); }}, '-',
{text:'Remover', id:'blogimagensarquivo-remover', disabled:true, iconCls:'icon-remove', handler:function(){ removeArquivo(); }}
],
items:new Ext.DataView({
id:'blogimageview',
store:store,
tpl:tpl,
autoHeight:true,
multiSelect:true,
overClass:'x-view-over',
itemSelector:'div.thumb-wrap',
prepareData:function(data){
data.shortName = Ext.util.Format.ellipsis(data.arquivo, 12);
return data;
},
listeners:{
selectionchange:{
fn:function(dv,nodes){
var l = nodes.length;
var s = l > 1 ? 's' : '';
var arenomear = Ext.getCmp('blogimagensarquivo-renomear');
var aremover = Ext.getCmp('blogimagensarquivo-remover');
if(l==1){
arquivos.setTitle('Imagens ('+l+' selecionada'+s+')');
arenomear.enable();
}
else{
arquivos.setTitle('Imagens (Nenhuma selecionada)');
arenomear.disable();
}
if(l>=1){
arquivos.setTitle('Imagens ('+l+' selecionada'+s+')');
aremover.enable();
}
else{
arquivos.setTitle('Imagens (Nenhuma selecionada)');
aremover.disable();
}
}
}
}
})
});

function editArquivo(){
// I am trying to...
var record = arquivos.getSelectedNodes();
alert(record.get('id'));
}


How function editArquivo() get the ID of selected image in Dataview?
I am starting with Ext right now, trying to follow the documentation and search the forum...
Thanks for help...

moegal
15 Sep 2009, 9:46 AM
did you ever get an answer for this? here is what I do.



store.getAt(Ext.getCmp('blogimageview').getSelectedIndexes()).get('id')


Marty