Extjs 3 rowcontext destroy - extjs

I created two tab panels and each panel has a grid.
Listener for Grid A:
Ext.getCmp('AGrid').addListener("rowcontextmenu", function menus(grid, rowIndex, e) {
if (!grid.contextMenu) {
grid.contextMenu = new Ext.menu.Menu({
autoDestroy: false,
items: [{ id: 'view', text: 'View Content'}],
currentRowIndex: rowIndex,
listeners: {
itemclick: function (item) {
switch (item.id) {
case 'view':
viewEmailClick(grid.getStore().getAt(this.currentRowIndex).data);
break;
}
}
}
});
}
this.contextMenu.currentRowIndex = rowIndex;
e.stopEvent(); // this stops the browser context menu and allows the default grid
// show the row context menu here
this.contextMenu.showAt(e.xy);
});
Listener for Grid B:
Ext.getCmp('BGrid').addListener("rowcontextmenu", function menus(grid, rowIndex, e) {
if (!grid.contextMenu) {
grid.contextMenu = new Ext.menu.Menu({
autoDestroy: false,
items: [{ id: 'view', text: 'View Task'}],
currentRowIndex: rowIndex,
listeners: {
itemclick: function (item) {
switch (item.id) {
case 'view':
viewTicketClick(grid.getStore().getAt(this.currentRowIndex).data);
break;
}
}
}
});
}
this.contextMenu.currentRowIndex = rowIndex;
e.stopEvent(); // this stops the browser context menu and allows the default grid
// show the row context menu here
this.contextMenu.showAt(e.xy);
});
When I right click on it Grid A works fine, and then right click on Grid B rowcontext menu is not working (just shows small gray dot).
After I turn back to Grid A and right click, it shows two rowcontext menus on Grid A:
If I right click on B grid and A grid right click (nothing shows) after turn back to B grid
it show rowcontext menu which contains two lists (reverse order) on Grid B.
Why this kind of things happen?
How can I show properly each grid row context menu?

It seems you pass the same grid variable to both listeners.

This problem is caused by parameter grid or grid.contextmenu obviously.
I found the answer.
The problem is caused by the follwing line.
items: [{ id: 'view', text: 'View Task'}]
I used same context menu id 'view'.
After those name changed like the followings
items: [{ id: 'viewTask', text: 'View Task'}]
items: [{ id: 'viewContent', text: 'View Content'}]
it works perfect.

Related

How does an end user clear the sorting for a grid column?

I use ExtJs 6.6.0 Classic. The grid component supports multi-column sorting (I use remoteSort: true, remoteFilter: true). Whenever the user clicks on a column header, that column becomes the first column in the order by list. But I cannot find how an end user is supposed to clear the sorting for a column. The context menu available through the column header doesn't have a "Clear Sort" option.
See also this kitchensink example.
I feel like I am missing something. There is a sortClearText config for the column inherited from the header, but I could not find a place where it's used (I thought that perhaps there is some config I can use to add the Clear Sort menu item to the column context menu).
I could add a button to execute the action of clearing the sorting of the store, as a last resort, but I don't like it.
Is there a simple way to add a Clear Sort option for a grid column through the Extjs components configuration?
Thank you
I also did not find, but you can use the following override:
Ext.define('overrides.grid.header.Container', {
override: 'Ext.grid.header.Container',
getMenuItems: function() {
var me = this,
menuItems = [],
hideableColumns = me.enableColumnHide ? me.getColumnMenu(me) : null;
if (me.sortable) {
menuItems = [{
itemId: 'ascItem',
text: me.sortAscText,
iconCls: me.menuSortAscCls,
handler: me.onSortAscClick,
scope: me
}, {
itemId: 'descItem',
text: me.sortDescText,
iconCls: me.menuSortDescCls,
handler: me.onSortDescClick,
scope: me
}, {
itemId: 'dropSortItem',
text: me.sortClearText,
//iconCls: me.menuSortDescCls, // Your icon
handler: me.onSortClearClick,
scope: me
}];
}
if (hideableColumns && hideableColumns.length) {
if (me.sortable) {
menuItems.push({
itemId: 'columnItemSeparator',
xtype: 'menuseparator'
});
}
menuItems.push({
itemId: 'columnItem',
text: me.columnsText,
iconCls: me.menuColsIcon,
menu: hideableColumns,
hideOnClick: false
});
}
return menuItems;
},
onSortClearClick: function() {
var menu = this.getMenu(),
activeHeader = menu.activeHeader,
store = this.up('grid').getStore();
store.getSorters().each(function(sorter) {
if(sorter.initialConfig.property == activeHeader.dataIndex) {
store.getSorters().remove(sorter)
}
}, this);
}
});

Ext4 How to reconfigure the component "ftype:search"

First i create a gird panel with {store:store1, column:column1} ;
I add ftype: 'search' component to grid panel,
then i use grid.reconfigure(store2,column2) to change the store and column.
after that , i found when i click the search button , ext use the store1 to request,
so my question is how to reconfigure the search component like the xtype: 'pagingtoolbar''s method bindStore(store2)?
you should do that afterrender the view in controller
I added a button in my code here in pagingtoolbar
I have gridpanel called customerShippingAddressesFormGrid
so I add new button to it's pagingtoolbar
and I added a listener when i click on it to add new row to my gridpanel
customerShippingAddressesFormGrid.pagingToolbar.add(
new Ext.button.Button(
{
xtype: 'button',
itemId: 'addButton',
icon: 'Images/Lists_New.png',
text: this.addButtonText,
tooltip: this.addNewText,
scope: this,
listeners:
{
click: function ()
{
if (customerIDFormList.comboBox.getValue())
{
var customerShippingAddressStore = customerShippingAddressesFormGrid.getStore();
customerShippingAddressStore.add({});
}
}
}
}));

ExtJS 4, how to multi-select grid row as well as single row is also clickable?

I am trying to create a grid using extjs 4.2.2. The grid contains several rows, if I click one row, then pops up another page which displays the detail info of that row.
The grid is in a panel, so the view code is:
Ext.define("Application.view.foo.Panel", {
extend: "Ext.panel.Panel",
cls: 'foo.panel'
...
items: [
{
itemId: "foo-bar",
xtype: "grid",
...
,selType: 'checkboxmodel'
,columns: [
xtype: 'templatecolumn'
and the code of listening row select event in controller is like:
"panel[cls~=foo.panel] #foo-bar": {
select: function(selectionModel, record, index) { .... }
Now, I am going to add check box for each row in order to mass edit, I added selType: 'checkboxmodel', but the problem is that I cannot click the check box: if I click the box, it goes the the detail page, not just being 'checked', cuz the code in controller listens that 'row click' event.
Is there any suggestions to implement it? Thanks in advance.
I would suggest to change your row click listener to view row details with action column.
{
xtype:'actioncolumn',
width:50,
items: [{
// Url is just for example (not working)
icon: 'extjs/examples/shared/icons/fam/showDetails.png', // Use a URL in the icon config
tooltip: 'Show details',
handler: function(grid, rowIndex, colIndex) {
var rec = grid.getStore().getAt(rowIndex);
// do your functionality here...
}
}
In every row will appear an icon, and then you will have possibility to multiselect rows and to look details of every row as well. Hope that helps.
Try to listen on cellclick event instead.
cellclick: function(view, td, cellIndex, record, tr, rowIndex, e, eOpts) {
if(cellIndex != your_checkbox_column) {
//do your info page stuff here
}
}

Extjs grid column header, add dropdown menu item to specific columns

I'm trying to add a button to the column header drop-down menus in my grid. However, I only want to add it to columns with certain itemId. So far I've got it working to add the button to all columns, see code below. I dont see where I could check each column's itemId though, it doesn't seem to iterate through the columns. Is there any workaround for this? Thank you!
items:[{
region:'center',
xtype:'grid',
columns:{
items: COLUMNS, //defined in index.php
},
store:'Items',
selType: 'checkboxmodel',
listeners: {
afterrender: function() {
var menu = Ext.ComponentQuery.query('grid')[0].headerCt.getMenu();
menu.add([{
text: 'edit',
handler: function() {
console.log("clicked button");
}
}]);
}
}
}],
The grid column menu exists in one instance which is shared for all columns. Because of this you can not add menu item only for one column.
However you can show/hide menu item in this menu for specific column. You can use menu beforeshow event and get information about column from menu.activeHeader property:
listeners: {
afterrender: function(c) {
var menu = c.headerCt.getMenu();
// add menu item into the menu and store its reference
var menuItem = menu.add({
text: 'edit',
handler: function() {
console.log("clicked button");
}
});
// add listener for beforeshow menu event
menu.on('beforeshow', function() {
// get data index of column for which menu will be displayed
var currentDataIndex = menu.activeHeader.dataIndex;
// show/hide menu item in the menu
if (currentDataIndex === 'name') {
menuItem.show();
} else {
menuItem.hide();
}
});
}
}
Fiddle with live example: https://fiddle.sencha.com/#fiddle/3fm

Switch from textfield to displayfield with ExtJS4

I have created a form that displays values in plain displayfields.
There is an "edit" button next to the form and once clicked by the user, the displayfields should switch to being textfields and will, therefore, make the data editable.
This, I am guessing, would be achieved by having two identical forms, one editable and one not and one or the other would be visible, based on the user having clicked the button. Another way, perhaps, is to have the xtype dynamically selected upon clicking the button.
Can anybody point me towards a certain direction in order to do this? I am a complete newbie to ExtJS and only just started learning ExtJS4.
Thank you in advance.
M.
Start by rendering all fields as input fields with disabled:true. Then use this for the Edit button handler:
...
form.getForm().getFields().each(function(field) {
field.setDisabled( false); //use this to enable/disable
// field.setVisible( true); use this to show/hide
}, form );//to use form in scope if needed
Ext.getCmp('yourfieldid').setFieldStyle('{color:black; border:0; background-color:yourcolor; background-image:none; padding-left:0}');
Ext.getCmp('yourfieldid').setReadOnly(true);
You can toggle based on a property isEditable. Then when you click the button you change the property and just remove and add the form. It makes it cleaner if you are switching back and forth.
Ext.define('E.view.profile.information.Form', {
extend: 'Ext.form.Panel',
xtype: 'form',
title: 'Form',
layout: 'fit',
initComponent: function () {
this.items = this.buildItems();
this.callParent();
},
buildItems: function () {
return [this.buildInvestmentPhilosophy()];
},
buildInvestmentPhilosophy: function () {
var field = {
name: 'investmentPhilosophy',
xtype: 'displayfield',
editableType: 'textarea',
grow: true,
maxLength: 6000,
value: '---',
renderer: E.Format.textFormatter
};
this.toggleEditingForForm(field);
return field;
},
toggleEditingForForm: function (form) {
if (this.isEditable) {
Ext.Array.each(form, this.configureFieldForEditing, this);
}
},
configureFieldForEditing: function (field) {
if (field.editableType) {
field.xtype = field.editableType;
}
}
});
You can also try to have two items : a displayfield and a textfield with the same data source and you could hide/show the right item with your button handler.
You should not have any CSS problems
(If you did not have CSS problems I would enjoy to see you code)

Resources