tobiu
3 Jul 2007, 4:05 AM
hi together,
i hope someone will find this one useful.
when having multiple contentpanels / gridpanels, i like to switch them via the "left" and "right" arrow-butons (not sure how they are called in english).
first, we have to get a listener to the global-keypress-event:
Ext.EventManager.addListener(document, "keypress", LayoutClass.onKeypress);
then, we have to get the 2 needed buttons (function in the LayoutClass),
[update] + the esc-event. if you also have a basic dialog, remove the keylistener(27) there and use this one (because it also works when you click somewhere else and then press "esc" while die dialog is open). if you do not have a basic dialog, just use the else part of the esc-event.
onKeypress : function (e) {
var k = e.getKey();
if(k == e.LEFT) {
LayoutClass.focusPrevTab();
}
else if(k == e.RIGHT) {
LayoutClass.focusNextTab();
}
else if(k == e.ESC) {
if(LayoutClass.hideBasicDialog&& LayoutClass.hideBasicDialog.isVisible()) {
LayoutClass.hideBasicDialog();
} else {
LayoutClass.destroyActiveTab();
}
}
}
in my layout-class, i have add the following 2 functions too, [update] and 1 for the close-tab-event.
focusNextTab : function() {
var id = layout.getRegion('center').getTabs().getActiveTab().id;
for (var k=0; k < layout.getRegion('center').getTabs().getCount(); k++) {
if (k > 0 && layout.getRegion('center').getTabs().getTab(k-1).id == id) {
layout.getRegion('center').getTabs().getTab(k).activate();
break;
}
}
},
focusPrevTab : function() {
var id = layout.getRegion('center').getTabs().getActiveTab().id;
var count = layout.getRegion('center').getTabs().getCount() - 1;
for (var k = count; k >= 0; k--) {
if (k < count && layout.getRegion('center').getTabs().getTab(k+1).id == id) {
layout.getRegion('center').getTabs().getTab(k).activate();
break;
}
}
},
destroyActiveTab : function() {
if (layout.getRegion('center').getActivePanel()
&& layout.getRegion('center').getActivePanel().isClosable() == true) {
layout.getRegion('center').remove(layout.getRegion('center').getActivePanel());
}
}
this will change the next available tab, if it exists or close the panel, if you push "esc".
when using grids, here is another useful keypress-example:
var selModel = new Ext.grid.RowSelectionModel({singleSelect:false});
var grid = new Ext.grid.Grid(selModel: selModel,...);
grid.on('keypress', onKeypress, this);
then, we have to get the 2 needed buttons:
function onKeypress (e) {
var k = e.getKey();
if(e.getCharCode() == 97) { // button a
selModel.selectAll();
}
else if(e.getCharCode() == 113) { // button q
selModel.clearSelections();
}
}
this one selects all rows in a grid on "a" and deselects all rows on "q".
only working with single-select: false.
kind regards, tobiu
i hope someone will find this one useful.
when having multiple contentpanels / gridpanels, i like to switch them via the "left" and "right" arrow-butons (not sure how they are called in english).
first, we have to get a listener to the global-keypress-event:
Ext.EventManager.addListener(document, "keypress", LayoutClass.onKeypress);
then, we have to get the 2 needed buttons (function in the LayoutClass),
[update] + the esc-event. if you also have a basic dialog, remove the keylistener(27) there and use this one (because it also works when you click somewhere else and then press "esc" while die dialog is open). if you do not have a basic dialog, just use the else part of the esc-event.
onKeypress : function (e) {
var k = e.getKey();
if(k == e.LEFT) {
LayoutClass.focusPrevTab();
}
else if(k == e.RIGHT) {
LayoutClass.focusNextTab();
}
else if(k == e.ESC) {
if(LayoutClass.hideBasicDialog&& LayoutClass.hideBasicDialog.isVisible()) {
LayoutClass.hideBasicDialog();
} else {
LayoutClass.destroyActiveTab();
}
}
}
in my layout-class, i have add the following 2 functions too, [update] and 1 for the close-tab-event.
focusNextTab : function() {
var id = layout.getRegion('center').getTabs().getActiveTab().id;
for (var k=0; k < layout.getRegion('center').getTabs().getCount(); k++) {
if (k > 0 && layout.getRegion('center').getTabs().getTab(k-1).id == id) {
layout.getRegion('center').getTabs().getTab(k).activate();
break;
}
}
},
focusPrevTab : function() {
var id = layout.getRegion('center').getTabs().getActiveTab().id;
var count = layout.getRegion('center').getTabs().getCount() - 1;
for (var k = count; k >= 0; k--) {
if (k < count && layout.getRegion('center').getTabs().getTab(k+1).id == id) {
layout.getRegion('center').getTabs().getTab(k).activate();
break;
}
}
},
destroyActiveTab : function() {
if (layout.getRegion('center').getActivePanel()
&& layout.getRegion('center').getActivePanel().isClosable() == true) {
layout.getRegion('center').remove(layout.getRegion('center').getActivePanel());
}
}
this will change the next available tab, if it exists or close the panel, if you push "esc".
when using grids, here is another useful keypress-example:
var selModel = new Ext.grid.RowSelectionModel({singleSelect:false});
var grid = new Ext.grid.Grid(selModel: selModel,...);
grid.on('keypress', onKeypress, this);
then, we have to get the 2 needed buttons:
function onKeypress (e) {
var k = e.getKey();
if(e.getCharCode() == 97) { // button a
selModel.selectAll();
}
else if(e.getCharCode() == 113) { // button q
selModel.clearSelections();
}
}
this one selects all rows in a grid on "a" and deselects all rows on "q".
only working with single-select: false.
kind regards, tobiu