PDA

View Full Version : Getting the selected value of grid



maecy
16 Oct 2013, 3:01 AM
I have a grid (ShowImages) grid, How do I get the selected value?


Ext.ns('dlti.view.widget');
User Maintenance grid


Ext.define('dlti.view.widget.ShowImages' ,{
extend: 'Ext.grid.Panel',
id: 'dlti-grid-images',
alias: 'widget.ShowImages',
forceFit: true,
stripeRows: true,
selType: 'checkboxmodel',
multiSelect: true,
autosync: true,
height: 250,
width: 470,



store: new dlti.store.UploadStore(),




columns: [
{
text: 'Images',
dataIndex: 'imagepath',
renderer: function renderIcon(val) {
return '<img src="' + val + '"width="100px" height="100px" align="middle">';

},

},
{
text: 'Filename',
dataIndex: 'filename',
renderer: function renderDescTarget(val, p, record) {
var desc = '';
desc = '<p style="color:#000;font-size:12px;">' + val + '</p>';
return desc;
}
}



]
});

Farish
16 Oct 2013, 4:15 AM
if you want to get the selected record(s), you can use the following code:


var srecords = grid.getSelectionModel().getSelection();

this will give you the record(s) which are currently selected on the grid.

maecy
16 Oct 2013, 12:05 PM
I can't get the records. I'm trying to get the records with a methods.. here's my methods:


createPlaylist: function(record){
var scope = this;
var srecords = getShowImages.getSelectionModel().getSelection();
console.log(srecords);

}

Farish
17 Oct 2013, 12:57 AM
is getShowImages your grid panel? are you getting any error message? what do you see in the console?

maecy
17 Oct 2013, 7:21 AM
I was able to get the value of the selected cell with this:


var sel = scope.getShowImages().getSelectionModel().getSelection();
var filename = sel[0].data.filename;


But since my grid is multiselect, I also want to get the other values of the selected cells.

Farish
17 Oct 2013, 7:38 AM
I was able to get the value of the selected cell with this:


But since my grid is multiselect, I also want to get the other values of the selected cells.

with getSelection() you will get an array of all selected records. you can loop through it:


for(var i=0; i<sel.length; i++)
{
console.log(sel[i].get('filename'));
}

maecy
17 Oct 2013, 7:52 AM
EDIT

It's working fine now because of your code. Thank you!!