Let's assume I have a window with a grid inside.
I code this via ExtJS, version 5.1.3.
This grid has four columns and the last one has the property flex:1.
Perfect, everything is aligned.
Now I have the possibility to hide the last column. As the other columns do not have the property flex, the grid is cut inside the window.
The window looks then similar to the last screenshot in this link.
Now my question: Is it somehow possible to define kind of a temporary flex property if no column with flex is available and then reset as soon as it is again?
You can specify forceFit : true configuration in grid object.
Ext.create('Ext.data.Store', {
storeId: 'simpsonsStore',
fields: ['name', 'email', 'phone'],
data: [{
name: 'Lisa',
email: 'lisa#simpsons.com',
phone: '555-111-1224'
}, {
name: 'Bart',
email: 'bart#simpsons.com',
phone: '555-222-1234'
}, {
name: 'Homer',
email: 'homer#simpsons.com',
phone: '555-222-1244'
}, {
name: 'Marge',
email: 'marge#simpsons.com',
phone: '555-222-1254'
}]
});
Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
forceFit : true,
store: Ext.data.StoreManager.lookup('simpsonsStore'),
columns: [{
text: 'Name',
dataIndex: 'name'
}, {
text: 'Email',
dataIndex: 'email',
flex: 1
}, {
text: 'Phone',
dataIndex: 'phone'
}],
height: 500,
width: 600,
renderTo: Ext.getBody()
});
Related
I'm still finding my way around Extjs, I'm currently displaying text data to a UI like so:
reference: 'agentLogGrid',
store: {
xclass: 'Ext.data.ChainedStore',
source: 'LogViewSource',
},
itemConfig: {
viewModel: true,
},
columns: [{
text: 'Timestamp',
xtype: 'templatecolumn',
tpl: '{timestamp}',
flex: 1,
}, {
text: 'Data',
xtype: 'templatecolumn',
tpl: '{data}',
flex: 1,
}],...
But the texts are not highlightable, that means I can't highlight them and copy, or select and copy. When I mouse over, the pointer sees it as a link, but I can't highlight or select. How do I make just the {data} highlightable?
In classic toolkit you can use enableTextSelection property. Something like this:
Ext.application({
name: 'Fiddle',
launch: function () {
Ext.create('Ext.data.Store', {
storeId: 'employeeStore',
fields: ['firstname', 'lastname', 'seniority', 'department'],
groupField: 'department',
data: [{
firstname: "Michael",
lastname: "Scott",
seniority: 7,
department: "Management"
}, {
firstname: "Dwight",
lastname: "Schrute",
seniority: 2,
department: "Sales"
}, {
firstname: "Jim",
lastname: "Halpert",
seniority: 3,
department: "Sales"
}, {
firstname: "Kevin",
lastname: "Malone",
seniority: 4,
department: "Accounting"
}, {
firstname: "Angela",
lastname: "Martin",
seniority: 5,
department: "Accounting"
}]
});
Ext.create('Ext.grid.Panel', {
title: 'Column Template Demo',
store: Ext.data.StoreManager.lookup('employeeStore'),
columns: [{
text: 'Full Name',
xtype: 'templatecolumn',
tpl: '{firstname} {lastname}',
flex: 1
}, {
text: 'Department (Yrs)',
xtype: 'templatecolumn',
tpl: '{department} ({seniority})'
}],
// USE viewConfig enableTextSelection property
viewConfig: {
enableTextSelection: true
},
height: 200,
width: 300,
renderTo: Ext.getBody()
});
}
});
Can I add a new unique property to gridcolumn in Ext JS? I want to use that property in some other place
{
xtype: 'gridcolumn',
dataIndex: 'startupPercent',
sortable: true,
'property': 'value', // so that i can access it later
text: 'StartUp%'
}
Can I add a new unique property to gridcolumn
Yes you can and you use that property other place.
In this FIDDLE, I have created a demo provide a custom config and get on header click. I hope this will help/guide you to achieve your requirement.
CODE SNIPPET
Ext.application({
name: 'Fiddle',
launch: function () {
Ext.create('Ext.grid.Panel', {
title: 'Demo',
store: {
data: [{
name: 'Lisa',
email: 'lisa#simpsons.com',
phone: '555-111-1224'
}, {
name: 'Bart',
email: 'bart#simpsons.com',
phone: '555-222-1234'
}, {
name: 'Homer',
email: 'homer#simpsons.com',
phone: '555-222-1244'
}, {
name: 'Marge',
email: 'marge#simpsons.com',
phone: '555-222-1254'
}]
},
columns: [{
text: 'Name',
dataIndex: 'name',
isName: true
}, {
text: 'Email',
dataIndex: 'email',
flex: 1
}, {
text: 'Phone',
dataIndex: 'phone'
}],
height: 200,
renderTo: Ext.getBody(),
listeners: {
headerclick: function (ct, column, e, t, eOpts) {
if (column.isName) {
console.log(column.isName);
}
}
}
});
}
});
I'm working on an ExtJS 6.2 project. I need to perform some operations when the columns in a grid a resized. I think the correct event to do so is columnresize. The problem is, since the columns are being loaded from a database dynamically, this event is fired every time a new column is added to the grid, and I would like to prevent it. I mean, I need this event to be fired only when every column is loaded.
I've tried to set a flag (named lFirstInit) that would be false once the columns are loaded form database, but the columnresize event keeps on being fired from the start.
How could I approach this, please? Thanks.
View:
Ext.define('App.view.TMainBrowseGrid', {
extend: 'Ext.grid.Panel',
alias: 'widget.TMainBrowseGrid',
requires: [
'App.view.TMainBrowseGridViewModel',
'App.view.override.TMainBrowseGrid',
'Ext.view.Table',
'Ext.grid.column.RowNumberer',
'App.view.TMainBrowseGridViewController'
],
controller: 'TMainBrowseGrid',
config: {
oParent: null,
cBrwName: '',
cCodForm: ''
},
viewModel: {
type: 'TMainBrowseGrid'
},
flex: 1,
columns: [
{
xtype: 'rownumberer',
itemId: 'oColRowNum'
}
],
listeners: {
columnresize: 'onGridpanelColumnResize',
}
});
Controller
Ext.define('App.view.TMainBrowseGridViewController', {
extend: 'Ext.app.ViewController',
alias: 'controller.TMainBrowseGrid',
onGridpanelColumnResize: function (component, column, width, eOpts) {
// THINGS TO DO...
}
});
We have finally discarded the 'columnresize' approach. We thought it is more reliable performing thos operations when clicking on a 'Close' button. However, I would like to thank you for your suggestions, especially the person who posted the answer below, and later removed it before I could mark it as the chosen answer. This was the code he/she posted:
Ext.create('Ext.data.Store', {
storeId: 'simpsonsStore',
fields: ['name', 'email', 'phone'],
data: [{
name: 'Lisa',
email: 'lisa#simpsons.com',
phone: '555-111-1224'
}, {
name: 'Bart',
email: 'bart#simpsons.com',
phone: '555-222-1234'
}, {
name: 'Homer',
email: 'homer#simpsons.com',
phone: '555-222-1244'
}, {
name: 'Marge',
email: 'marge#simpsons.com',
phone: '555-222-1254'
}]
});
Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
columns: [{
text: 'Name',
dataIndex: 'name'
}, {
text: 'Email',
dataIndex: 'email',
flex: 1
}, {
text: 'Phone',
dataIndex: 'phone'
}],
height: 200,
width: 400,
renderTo: Ext.getBody(),
listeners: {
columnresize: function(ct, column, width, eOpts){
if(ct.containsFocus){// It will true when we resize column.
alert('resize');
console.log(`${column.text} Column resized`);
}
}
}
});
So i have an usual grid, with some columns:
{
xtype : 'gridpanel',
mode : "MULTI",
region : 'center',
title : "grid",
id : 'datagridResult',
margin : '10 5 5 5',
columns : [
{
xtype : 'gridcolumn',
dataIndex: 'TEST',
flex : 0.25
},
{
xtype : 'gridcolumn',
dataIndex: 'Test2'
flex : 2
},
//...
What i want is to add 3 more columns which are radiobuttons (one button per column). I tried something like this:
{
xtype : 'gridcolumn',
text : "FOR"
dataIndex: 'for',
flex : 1,
editor: {
xtype : 'radiofield',
name : 'Regex',
inputValue: 'Checked'
},
}
And it doesn't work. So i am here to ask any sugestions.
And it doesn't work. So i am here to ask any sugestions
In ExtJS have xtype :'widgetcolumn'.
A widget column is configured with a widget config object which specifies an xtype to indicate which type of Widget or Component belongs in the cells of this column.
I have created an Sencha Fiddle demo. It will show how is working. Hope this will help you.
Ext.create('Ext.data.Store', {
storeId: 'simpsonsStore',
fields: ['name', 'email', 'phone', {
name: 'checked',
type: 'boolean',
defaultValue: true
}],
data: [{
name: 'Lisa',
email: 'lisa#simpsons.com',
phone: '555-111-1224'
}, {
name: 'Bart',
email: 'bart#simpsons.com',
phone: '555-222-1234'
}, {
name: 'Homer',
email: 'homer#simpsons.com',
phone: '555-222-1244'
}, {
name: 'Marge',
email: 'marge#simpsons.com',
phone: '555-222-1254'
}]
});
Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
columns: [{
text: 'Name',
dataIndex: 'name'
}, {
text: 'Email',
dataIndex: 'email',
flex: 1
}, {
text: 'Phone',
dataIndex: 'phone'
}, {
text: 'Status',
width: 150,
xtype: 'widgetcolumn',
dataIndex: 'checked',
onWidgetAttach: function (column, widget, record) {
widget.down(`[inputValue=${record.get('checked')}]`).setValue(true);
},
widget: {
xtype: 'radiogroup',
items: [{
boxLabel: 'Yes',
inputValue: true
}, {
boxLabel: 'No',
inputValue: false
}]
}
}],
height: 200,
width: 400,
renderTo: Ext.getBody()
});
The message window hides behind the panel when click Tab on Editable cell.
For example: double click the first phone cell, press TAB button. You can see the message box and then hide behind the grid window.
Ext.create('Ext.data.Store', {
storeId: 'simpsonsStore',
fields: ['name', 'email', 'phone'],
data: {
'items': [{
'name': 'Lisa',
"email": "lisa#simpsons.com",
"phone": "1224"
}, {
'name': 'Bart',
"email": "bart#simpsons.com",
"phone": "1234"
}, {
'name': 'Homer',
"email": "home#simpsons.com",
"phone": "1244"
}, {
'name': 'Marge',
"email": "marge#simpsons.com",
"phone": "1254"
}]
},
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'items'
}
}
});
var table = Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
columns: [{
text: 'Name',
dataIndex: 'name',
editor: {
xtype: 'textfield'
}
}, {
text: 'Email',
dataIndex: 'email',
flex: 1
}, {
text: 'Phone',
dataIndex: 'phone',
editor: {
xtype: 'numberfield',
hideTrigger: true,
validateOnChange: false
}
}],
height: 200,
width: 400,
plugins: [Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 2
})],
listeners: {
'validateedit': function () {
Ext.MessageBox.show({
icon: Ext.MessageBox.ERROR,
buttons: Ext.MessageBox.OK,
title: 'test',
msg: 'test'
});
}
}
});
tablePanel.add(table);
tablePanel.show();
});
Anyone met such problem before?
I got answer from sencha site:
I see it does not do this in 4.07, but in 4.1. I will talk with dev team.
For now, you can use defer:
Code:
listeners:{
'validateedit':function(){
Ext.MessageBox.show({
icon: Ext.MessageBox.ERROR,
buttons: Ext.MessageBox.OK,
title: 'test',
msg: 'test'
}).defer(100);
}
}