ExtJS Grid to get the selected item data

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.