ExtJS Grid gets selected data-hwq1987 's column-Blog channel-csdn.net
Grid data source is the store, we sometimes need to do click on an item to trigger certain events, in this process, we inevitably need to get the click of the item, how to get the corresponding data?
First, take a look at how to write trigger events. Assuming that the variable _grid is a gridpanel handle (or reference), we want to trigger an event when we double-click an item in the Gridpanel. Then we just need to
_grid.addlistener (' Celldblclick ', function (grid, RowIndex, ColumnIndex, e) {
Todo Something Here
});
For the meaning of the 4 parameters in
function, let's refer to the following document.
Celldblclick: (Grid This, number RowIndex, number columnindex, Ext.eventobject e)
Fires when a cell is double clicked
(if you want to click, you can change Celldblclick to Cellclick)
We can already get the column index and row index for the item clicked, The next thing to do is to rely on these two important indexes to help find the data you want. We assume that the record field is [' pid ', ' Name ', ' gender ', ' birthday '].
then we get the store first, using the Gridpanel GetStore () method. The
Method prototype is: GetStore (): DataSource the DataSource here is actually Ext.data.Store.
Then we use getAt (number index): Ext.data.Record method to get the record of the Click Trigger event (record),
What to do after the record has been recorded? Note that the usage of the record here is not directly using attributes to fetch values like JSON.
Instead, you need to use the method get (String name): object
at this time, although the return is an Object, it is already a String, you can directly alert or do other processing.
_grid.addlistener (' Celldblclick ', function (grid, RowIndex, ColumnIndex, e) {
var s=grid.getstore ();
var x=s.getat (RowIndex);
Alert (x.get (' pid '));
});
From for notes (Wiz)
ExtJS Grid to get the selected item data