PDA

View Full Version : grid panel keypress event



gurunath
5 Jul 2012, 2:29 AM
I am working on grid panel,

If user presses insert key a new record will insert
and if delete pressed selected row is deleted

but i am unable to find key pressed event and which key is pressed

Farish
5 Jul 2012, 2:39 AM
you can create a keymap:


var keyMap = Ext.create('Ext.util.KeyMap', Ext.getBody(), [
{
key: Ext.EventObject.DELETE,
shift: false,
ctrl: false,
fn: function() {
alert('Delete');
}
},
{
key: Ext.EventObject.INSERT,
shift: false,
ctrl: false,
fn: function() {
alert('Insert');
}
}
]);


Instead of Ext.getBody(), you should use the HTML element of your grid panel. You can set the shift and ctrl configs to true if you want the action to occur on Ctrl + Del or Shift + Del.

sword-it
5 Jul 2012, 3:09 AM
Hi gurunath,

You can use "itemkeydown" event of Ext.grid.View class. For example


Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
viewConfig:{
listeners:{
itemkeydown:function(view, record, item, index, e){
alert('The press key is' + e.getKey());
}
}
},
store: yourStore
columns: [
{
header: 'Name',
dataIndex: 'name'},
{
header: 'Email',
dataIndex: 'email',
flex: 1},
{
header: 'Phone',
dataIndex: 'phone'}
],
height: 200,
width: 400,
renderTo: Ext.getBody()
});



For more information see http://docs.sencha.com/ext-js/4-1/#!/api/Ext.grid.View-event-itemkeydown

gurunath
5 Jul 2012, 6:33 AM
@Farish (http://www.sencha.com/forum/member.php?277826-Farish) Thanks man its working

:)~o)

Farish
5 Jul 2012, 6:42 AM
welcome. please mark the thread as answered so that it saves time for others.

Rashmi.Gadgil
18 Mar 2014, 7:50 AM
I have to implement ctrl+c , ctrl+v for my grid.
This should work even when the grid is empty or has any records.
below is my code.
The events are not triggering . What am I doing wrong ? Any advice is appreciated.
Thanks.

containerclick : function(grid,e){

var keyMap = Ext.create('Ext.util.KeyMap', grid.getEl(),
[
{
key: Ext.EventObject.V,
ctrl: true,
fn: function(e) {
var controller = AllMDNs.getController('AllMdnsController');
controller.handleMdnsPaste(e);
}
},
{
key: Ext.EventObject.C,
ctrl: true,
fn: function(e) {
var controller = AllMDNs.getController('AllMdnsController');
controller.handleMdnsCopy(e);
}
}
]);

}