Extjs 04_grid click event new discovery

Source: Internet
Author: User

In extjs grid, click the row and cell to obtain the row or cell content (data)
Js Code Copy codeThe Code is as follows: 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 );
}
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 CodeCopy codeCode: 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 );
}
});
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 CodeCopy codeThe Code is as follows: listeners :{
'Cellclick': function (grid, rowIndex, columnIndex, e ){}
}
// This event is triggered when a grid cell is clicked.
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 ";
Grid. getView (). getCell (rowIndex, columnIndex). style. background-color = "# FF6600 ";
Grid. getView (). getCell (rowIndex, columnIndex). style. color = "# FF6600 ";

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 CodeCopy codeThe Code is as follows: 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.