ExtJS newly discovered 04_grid Click Event

Source: Internet
Author: User

In extjs grid, click the row and cell to obtain the row or cell content (data)
Js Code
Grid. addListener ('cellclick', cellclick );
 
Function cellclick (grid, rowIndex, columnIndex, e ){
Var record = grid. getStore (). getAt (rowIndex); // Get the Record
Var fieldName = grid. getColumnModel (). getDataIndex (columnIndex); // Get field name
Var data = record. get (fieldName );
Ext. MessageBox. alert ('show', 'currently selected data is '+ data );
}


------------------------------------------------------------------------------
Js Code
Grid. on ('mouseover', function (e) {// Add a mouseover event
Var index = grid. getView (). findRowIndex (e. getTarget (); // you can obtain the column position based on the target of the mouse.
If (index! = False) {// when the correct column is obtained (because false is returned if the input target column is not obtained)
Var record = store. getAt (index); // obtain the record of this column
Var str = Ext. encode (record. data); // assemble a string. You need to complete it yourself. Here I serialize it.
Var rowEl = Ext. get (e. getTarget (); // converts target to an Ext. Element Object.
RowEl. set ({
'Ext: qtip ': str // you can specify its tip attribute.
}, False );

}
});

---------------------------------------------------------------------------------

Js Code
Listeners :{
'Cellclick': function (grid, rowIndex, columnIndex, e ){}
}
 
// This event is triggered when a grid cell is clicked.


Js Code
Grid. getView (). getCell (rowIndex, columnIndex). style. background-color = "# FF6600 ";
Grid. getView (). getCell (rowIndex, columnIndex). style. color = "# FF6600"; www.2cto.com
I want to change the entire background color, not the color of words. How can I restore the color of the cell at the last vertex to the original when I click a cell ???
Refresh the table to restore the color changed by the previous click, grid. getView (). refresh (), and then change the color of the cell that you clicked this time.
Js Code
Grid. getView (). refresh ();
Grid. getView (). getCell (rowIndex, columnIndex). style. backgroundColor = "# FF9999 ";

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.