I have an ExtJS 6.2 modern app. What is the proper way to add a button to a grid cell?
I tried using the column renderer fn to return a button but I just see the HTML tags rendered, not the actual element. I also tried using the "widgetcell" component which does render the button but not the button text.
Fiddle.
Using your fiddle as an example, you can make a widget button like this
columns: [
//other columns
{
dataIndex: 'description',
flex: 1,
cell: {
xtype: "widgetcell",
widget: {
xtype: "button",
}
}
}
]
You can do it without widgetcell by:
{
text: "Button Widget ",
flex: 1,
cell: {
xtype: 'button',
text: 'CLICK ME'
}
}
Or with panel
{
text: "Button Widget ",
flex: 1,
cell: {
xtype: "widgetcell",
widget: {
xtype: 'panel',
header: false,
items: [{
xtype: 'button',
text: 'CLICK ME'
}]
}
}
}
I wanted to accomplish the same task but thought I would include a little more complete example. This was the first resource I came across so figured I should post here.
So for my problem I just wanted to pass the data and render a view utilizing that data.To do that I add a column to my grid and added a widgetcell inside that column. The grid column requires a dataIndex but my button wasn't associated with a specific column in my model, so I just added a non-existent column for the required value which worked.
After that you can specify a widget object as a cell config. You can add a handler key and access the record object from the grid like below.
{
xtype: 'gridcolumn',
flex: 1,
width: 80,
dataIndex: 'button',
text: 'Details',
cell: {
xtype: 'widgetcell',
widget: {
xtype: 'button',
text: 'View',
width: '100%',
handler: function(button,e){
let accountData = this.up().up()._record.data
console.log(accountData);}
}
}
}
Related
I have an application which has to be screen readable (for blind people) and I'm struggling to read a FontAwesome Icon. Right now I have this for example:
{
xtype: 'actioncolumn',
items: [
{
iconCls: 'x-fa fa-envelope',
}],
dataIndex: 'edit',
text: 'Send E-Mail'
}
And I use NVDA Screen reader -> https://www.nvaccess.org/download/
However it cannot read this text ("Send E-Mail") on mouse hover. I know that font-awesome has option to include aria-label="Send E-Mail" but how can I apply it to ExtJS item?
Have you tried this:
{
iconCls: 'x-fa fa-envelope',
tooltip: 'Send E-Mail',
}
I wasn't able to find a way to make the "actioncolumn" compliant, so I have converted them to a "widgetcolumn" and that works better. The downsides to this is that you cannot have multiple "widgets" in one column, so each of actions will get its own column and you have buttons in the columns instead of the more elegant icons. But, what can you do, Ext....
{
xtype: 'widgetcolumn',
text: 'Edit', //column header
align: 'center',
width: 60,
widget: {
xtype: 'button',
width: 40,
iconCls: 'x-fa fa-pencil',
ariaLabel: 'click to edit',
handler: 'edit'
}
}
For the handler, the arguments are a little different since it's now a button (this is specific to my case, using the record id):
edit: function(button) {
var grid = button.up('grid'),
store = grid.getStore(),
recordId = button.getWidgetRecord().getId(),
record = store.findRecord('id', recordId);
//and so on....
}
I have a widgetcolumn that contains a button:
xtype:'widgetcolumn',
dataIndex: 'canUpdateKey',
itemId:'updateKey',
width:120,
widget: {
xtype: 'button',
text: 'Update key',
hidden: '{!record.canUpdateKey}'
}
I only want to display the button where canUpdateKey is true on the record; but this does not work as indented. Relevant fiddle
From the widget config documentation:
The rendered component has a Ext.app.ViewModel injected which inherits
from any ViewModel that the grid is using, and contains two extra
properties: record and recordIndex
The widget configuration may contain a cfg-bind config which uses the
ViewModel's data.
So you should use bind instead, like this:
xtype:'widgetcolumn',
dataIndex: 'canUpdateKey',
itemId:'updateKey',
width:120,
widget: {
xtype: 'button',
text: 'Update key',
bind: {
hidden: '{!record.canUpdateKey}'
}
}
Fiddle: https://fiddle.sencha.com/#view/editor&fiddle/26ig
Inside your button widget, Try this:
listeners:{
render:function(btn){
if(!btn.getWidgetRecord().data.canUpdateKey)
btn.hide();
}
}
I'm trying to developp an Ext.grid.Panel using EXT JS.
My need is to have a column where the content is a button.
obviously some think like this will not work
this.columns = [
{
text : 'column1',
width : 120,
sortable : true,
flex: 1,
dataIndex: 'col1'
},{
xtype: 'button',
width : 120
}
//...
Also, I've tied some examples like this one but did not work for me.
Any leeds ?
Thanks in advance
Try using an actioncolumn (Extjs docs) like that:
{
xtype: 'actioncolumn',
width: 50,
items: [{
handler: function(grid) {
alert("works");
}
}]
}
I can add my own button to the built-in tools "Help" etc on the panel header:
tools:[
{
type:'help',
tooltip: 'Get Help',
handler: function(event, toolEl, panel){
// show help here
}
}],
header: {
layout: {
type: 'hbox',
align: 'right'
},
items: [{
xtype: 'button',
text: 'test'
}]
} ...
but button 'test' appears far left before the panel title ... header layout hbox right obviously not the way to do it :-). Button 'test' just a placeholder - I want to eventually add a menu button - so another css tool would not work - is there a simple way of doing this or do I need to use dom element positiong etc? tia.
If you're using ExtJS 4.2, you can use the titlePosition property to accomplish this. See http://jsfiddle.net/U8MSd/
tools: [{
type: 'help',
tooltip: 'Get Help',
handler: function (event, toolEl, panel) {
// show help here
}
}],
header: {
titlePosition: 0,
items: [{
xtype: 'button',
text: 'test'
}]
}
Can we add combo box in grid header in extjs ?
we have a special requirement here, if anybody has idea then please let me know.
Thanks
Deepak
If you want it in the grid column header (for example to implement custom filters), look at http://docs.sencha.com/extjs/4.2.1/extjs-build/examples/build/KitchenSink/ext-theme-neptune/#big-data-grid
Basically, you configure items in the column configuration and off you go:
Ext.define('KitchenSink.view.grid.BigData', {
extend: 'Ext.grid.Panel',
columns: [
{
xtype: 'gridcolumn',
dataIndex: 'status',
text: 'Item status'
items: [
{xtype: 'combobox'}
]
}
]
});
You can use extjs tbar to implement components to grid header:
tbar: [
{ xtype: 'button', text: 'Button 1' }
]
or:
dockedItems: [{
xtype: 'toolbar',
dock: 'top',
items: [
{ xtype: 'button', text: 'Button 1' }
]
}]
to implement combobox, best way is to define custom combobox component and provide alias for it, then in your grid tbar just say xtype: 'mygridcombo'
Here is a example.
This works for me well
{
text : 'Save Energy Mode',
dataIndex: 'fs',
items: [{
xtype: 'combobox',
padding: 2,
flex: 1
}]
}
or simply (if you do not need title text)
columns: { items: [{ xtype: 'combobox'}] }
If you can have it in the grid panel's toolbar, then Davor's suggestion is the way to go. If you actually need it in the grid's header (e.g., like for filtering on columns), you might check out the Grid Filtering example in the Ext JS docs: http://docs.sencha.com/extjs/4.2.1/#!/example/grid-filtering/grid-filter-local.html