Add Ext.Button to ExtJS columnmodel - extjs

I'm creating an Ext.grid.GridPanel. I am trying to add column with xtype: button to the column model. I am not sure, if I can do that though. Below is my code and also this is a link to jsfiddle http://jsfiddle.net/bXUtQ/
I am using extjs 3.4
Ext.onReady(function () {
var myData = [[ 'Lisa', "lisa#simpsons.com", "555-111-1224"],
[ 'Bart', "bart#simpsons.com", "555-222-1234"],
[ 'Homer', "home#simpsons.com", "555-222-1244"],
[ 'Marge', "marge#simpsons.com", "555-222-1254"]];
var store = new Ext.data.ArrayStore({
fields:[ {
name: 'name'
},
{
name: 'email'
},
{
name: 'phone'
}],
data: myData
});
var grid = new Ext.grid.GridPanel({
renderTo: 'grid-container',
columns:[ {
header: 'Name',
dataIndex: 'name'
},
{
header: 'Email',
dataIndex: 'email'
},
{
header: 'Phone',
dataIndex: 'phone'
},
{
header: 'action',
xtype: 'actioncolumn',
iconCls: 'delete-icon'
text: 'Delete',
name: 'deleteBtn',
handler: function(grid, rowIndex, colIndex, item, e) {
alert('deleted');
}
},
//////////////////////////////
//I cannot add this column
{
header: 'action',
xtype: 'button',
text: 'update',
name: 'btnSubmit'
}
],
store: store,
frame: true,
height: 240,
width: 500,
title: 'Framed with Row Selection',
iconCls: 'icon-grid',
sm: new Ext.grid.RowSelectionModel({
singleSelect: true
})
});
});

You can't use a button as a column just like that. We're using the following UX to achieve just what you're asking. Unfortunately this is for ExtJS 4.1:
http://www.sencha.com/forum/showthread.php?148064-Component-Column-Components-in-Grid-Cells

You can try to Grid RowActions.

Will you try this as your actioncolumn
{
xtype: 'actioncolumn',
width: 50,
items:
[
{
icon: 'app/resources/images/cog_edit.png', // Use a URL in the icon config
tooltip: 'Edit',
handler: function (grid, rowIndex, colIndex) {
var rec = grid.getStore().getAt(rowIndex);
alert("Edit " + rec.get('name'));
}
},
{
icon: 'app/resources/images/delete.png',
tooltip: 'Delete',
handler: function (grid, rowIndex, colIndex) {
var rec = grid.getStore().getAt(rowIndex);
alert("Terminate " + rec.get('name'));
}
}
]
}
Or You can try this Plugin for actioncolumnbutton

Related

How to hide and show the buttons located inside a grid in Ext JS?

I have a grid looking something like this:
Ext.create('Ext.grid.Grid', {
title: 'myGrid',
store: 'myStore',
columns: [
{ text: 'Name', dataIndex: 'name'},
{ text: 'Running', dataIndex: 'running' },
{
xtype: 'actioncolumn',
text:'play or stop',
items:[
{
iconCls: 'x-fa fa-play-circle',
handler:function(grid, rowIndex, colIndex){ play(); }
}, {
iconCls: 'x-fa fa-stop-circle',
handler:function(grid, rowIndex, colIndex){ stop(); }
}
]
}
]
});
It works fine. In the third column there are two buttons: a "play button" and a "stop button". Now they are always visible but I want the play button to be visible only when running==false, and the stop button to be visible only when running==true. How can I achieve that?
You can use the getClass config, which can be specified for the actioncolumn itself or for child items of the actioncolumn. docs
Then you can just do something like this:
Ext.create('Ext.grid.Grid', {
title: 'myGrid',
store: 'myStore',
columns: [
{text: 'Name', dataIndex: 'name'},
{text: 'Running', dataIndex: 'running'},
{
xtype: 'actioncolumn',
text: 'play or stop',
items: [
{
getClass: function (value, metadata, record) {
return record.data.running ? '' : 'x-fa fa-play-circle';
},
handler: function (grid, rowIndex, colIndex) {
play();
}
}, {
getClass: function (value, metadata, record) {
return record.data.running ? 'x-fa fa-stop-circle' : '';
},
handler: function (grid, rowIndex, colIndex) {
stop();
}
}
]
}
]
});
This worked:
Ext.create('Ext.grid.Grid', {
title: 'myGrid',
store: 'myStore',
columns: [
{text: 'Name', dataIndex: 'name'},
{text: 'Running', dataIndex: 'running'},
{
xtype: 'actioncolumn',
text: 'play or stop',
items: [
{
getClass: function (value, metadata, record) {
return record.data.running ? 'x-fa fa-stop-circle' : 'x-fa fa-play-circle';
},
handler: function (grid, rowIndex, colIndex) {
playOrStop();
}
},
]
}
]
});

how to send value from grid (pop up) to form panel in extjs

how to show data in form panel after click one of data in pop up in grid view, I have try another way but always wrong,
this is my grid panel :
var tt = Ext.define('Rendering.view.beli.dataSupplier', {
extend: 'Ext.form.Panel',
//extend: 'Ext.window.Window',
// xtype: 'beligrid',
alias : 'widget.contatoform',
frame: true,
// id: 'detailPanelis',
title: 'Company data',
bodyPadding: 5,
layout: 'column',
requires: [
'Ext.grid.*',
'Ext.form.*',
'Ext.layout.container.Column'
],
initComponent: function() {
this.items = [
{
columnWidth: 0.65,
xtype: 'gridpanel',
reference: 'customerGrid',
store: 'BeliStore',
columns : [{
text: 'Nama',
dataIndex: 'namaSupplier',
flex: 1
}, {
text: 'Alamat',
dataIndex: 'address',
flex: 1
}],
listeners: {
scope: this,
selectionchange: 'onSelectionChanges'
}
}];
//];
// });
this.callParent(arguments);
},
onSelectionChanges: function(model, records) {
//alert('yuhuuuu');
var editt = Ext.create('Rendering.view.beli.bg_beli');
var c = editt.onSelectionChange(model, records);
}
});
the function for to send data to form panel is
listeners: {
scope: this,
selectionchange: 'onSelectionChanges'
}
this is function of onSelectionChanges :
onSelectionChanges: function(model, records) {
//alert('yuhuuuu');
var editt = Ext.create('Rendering.view.beli.bg_beli');
var c = editt.onSelectionChange(model, records);
}
and form panel :
var tt = Ext.define('Rendering.view.beli.bg_beli', {
extend: 'Ext.form.Panel',
xtype: 'beligrid',
controller: 'binding-dynamic',
frame: true,
title: 'Company data',
bodyPadding: 5,
layout: 'column',
requires: [
'Ext.grid.*',
'Ext.form.*',
'Ext.layout.container.Column'
],
// In this example, configuration is applied at initComponent time
// because it depends on profileInfo object that is generated for the
// FormGrid instance.
initComponent: function() {
//Ext.apply(this, {
this.items = [
{
columnWidth: 0.65,
xtype: 'gridpanel',
store: 'BeliStore',
columns : [{
text: 'Nama',
dataIndex: 'namaSupplier',
flex: 1
}, {
text: 'Alamat',
dataIndex: 'address',
flex: 1
}],
listeners: {
scope: this,
selectionchange: 'onSelectionChange'
}
},{
columnWidth: 0.35,
margin: '20 0 0 10',
xtype: 'form',
title:'Company detailsss',
layout: 'anchor',
defaultType: 'textfield',
items: [
{
name : 'id_supplier',
fieldLabel: 'id',
hidden:true
},{
fieldLabel: 'Nama Supplier',
name: 'namaSupplier'
},{
fieldLabel: 'email',
name: 'email'
},{
fieldLabel: 'alamat',
name: 'address'
},{
xtype: 'button',
text: 'YUY',
action: 'add'
}]
}];
//];
// });
this.callParent(arguments);
},
onSelectionChange: function(model, records) {
alert('asdasd');
console.log(records);
var rec = records[0];
console.log(rec);
if (rec) {
var c = this.getForm().loadRecord(rec);
// this.getBeliStoreStore().load();
console.log(this.getForm().loadRecord(rec));
}
}
});
I send data from grid to form panel, and the function that accepted data in form panel is :
onSelectionChange: function(model, records) {
alert('asdasd');
console.log(records);
var rec = records[0];
console.log(rec);
if (rec) {
var c = this.getForm().loadRecord(rec);
// this.getBeliStoreStore().load();
console.log(this.getForm().loadRecord(rec));
}
}
please help, I have looking for to any reference but I don't get answer yet, thanks before
My suggestion is modify the call for event this.onSelectionChange or like that this.on('selectionchange',this.onSelectionChange) it is another way for call events in extjs
initComponent: function() {
var me = this ;
this.items = [
{
columnWidth: 0.65,
xtype: 'gridpanel',
reference: 'customerGrid',
store: 'BeliStore',
columns : [{
text: 'Nama',
dataIndex: 'namaSupplier',
flex: 1
}, {
text: 'Alamat',
dataIndex: 'address',
flex: 1
}],
listeners: {
scope: this,
selectionchange: me.onSelectionChanges
}
}];
//];
// });
this.callParent(arguments);
}
OR
initComponent: function() {
var me = this ;
var grid = Ext.create('Ext.grid.Panel', {
reference: 'customerGrid',
store: 'BeliStore',
columns : [{
text: 'Nama',
dataIndex: 'namaSupplier',
flex: 1
}, {
text: 'Alamat',
dataIndex: 'address',
flex: 1
}
]});
me.items = [
{
columnWidth: 0.65,
grid
}];
grid.on('selectionchange',me.onSelectionChange)
this.callParent(arguments);
}
http://docs.sencha.com/extjs/4.2.5/#!/example/build/KitchenSink/ext-theme-neptune/#form-grid

How to create a Form for each row in a grid panel:extjs

How do i create a different form for each row in the Grid...
i have a grid like ..
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()
});
Your question doesn't explain your problem very well. Please update your topic and question. As I understood from your question, yes, you can. There are couple of ways. One of them is putting a form into a grid cell using grid column renderer. Another way is using editor in grid column. The second way is easy, but it's not proper way. If you want the second way also, I can add it. So, I'll add an efficient one. Please check the code below and fiddle:
https://fiddle.sencha.com/#fiddle/11i5
Ext.define('UploadForm', {
extend: 'Ext.form.Panel',
width: 200,
frame: true,
items: [{
xtype: 'filefield',
name: 'photo',
msgTarget: 'side',
allowBlank: false,
buttonText: 'Select'
}],
buttons: [{
text: 'Upload',
handler: function() {
var form = this.up('form').getForm();
if(form.isValid()){
form.submit({
url: 'photo-upload.php',
waitMsg: 'Uploading your photo...',
success: function(fp, o) {
Ext.Msg.alert('Success', 'Your photo "' + o.result.file + '" has been uploaded.');
}
});
}
}
}],
initComponent: function () {
if (this.delayedRenderTo) {
this.delayRender();
}
this.callParent();
},
delayRender: function () {
Ext.TaskManager.start({
scope: this,
interval: 200,
run: function () {
var container = Ext.fly(this.delayedRenderTo);
if (container) {
this.render(container);
return false;
} else {
return true;
}
}
});
}
});
var store = Ext.create('Ext.data.Store', {
fields: ['Name', 'Phone', 'Email', 'filePath'],
data: [{
Name: 'Rick',
Phone: '23122123',
Email: 'something#mail.com',
filePath: '/home'
}, {
Name: 'Jane',
Phone: '32132183',
Email: 'some#thing.com',
filePath: '/home'
}]
});
var renderTree = function(value, meta, record) {
var me = this;
var container_id = Ext.id(),
container = '<div id="' + container_id + '"></div>';
Ext.create('UploadForm', {
delayedRenderTo: container_id
});
return container;
}
Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: store,
columns: [
{ text: 'Name', dataIndex: 'Name' },
{ text: 'Email', dataIndex: 'Email' },
{ text: 'Phone', dataIndex: 'Phone' },
{ text: 'Upload',
dataIndex: 'filePath',
width: 300,
renderer: renderTree
}
],
renderTo: Ext.getBody()
});
P.s. Its based from Render dynamic components in ExtJS 4 GridPanel Column with Ext.create

Drag and drop from tree to cell of editor grid in extjs 4

I want to drag a leaf node from the tree and drop it in the editor grid cell , so that the cell will have the text of the leaf as data.
I am using the editor grid where i add the rows dynamically.
below is my code
Ext.define('Field_model', {<br>
extend: 'Ext.data.Model',<br>
fields: [<br>
{name: 'select_field'},
{name: 'select_function'},
{name: 'symbolic_name'}
]
});<br>
`var cellEditing_field = Ext.create('Ext.grid.plugin.CellEditing', {clicksToEdit: 1});`
`var field_store = Ext.create('Ext.data.JsonStore', {
model: 'Field_model',
data:[
{
"select_field":"click toedit...",
"select_function":"click to select...",
"symbolic_name":"click to edit..."
}
]
});`
var Field_grid = Ext.create('ListGrid', {<br>
store: field_store,<br>
columns: [{<br>
header: 'Add/Delete',<br>
xtype: 'actioncolumn',<br>
width:130,<br>
sortable: false,<br>
items: [{<br>
icon: 'add.png',<br>
tooltip: 'Add',<br>
handler : function(){<br>
var r = Ext.create('Field_model', {<br>
select_field: 'click to edit...',<br>
select_function: 'click to select...',<br>
symbolic_name: 'click to edit...'<br>
});<br> field_store.insert(0, r);<br>
cellEditing_field.startEditByPosition({row: 0, column: 0});<br>
}<br>
},{<br>
icon: 'delete.png',<br>
tooltip: 'Delete',<br>
handler: function(grid, rowIndex, colIndex) {<br>
if(grid.getStore().data.length==1)<br>
{<br>
alert('cannot delete this record');<br>
}
else<br>
{<br>
field_store.removeAt(rowIndex);<br>
}<br>
}<br>
}]<br>
},{<br>
header: 'Select Field',<br>
dataIndex: 'select_field',<br>
width:130,<br>
editor: {<br>
xtype:'textfield'<br>
}
}, {
header: 'Function',
dataIndex: 'select_function',
width: 130,
editor: {
xtype:'combobox',
triggerAction:'all',
mode:'local',
store: ['Distinct','Sum','Count']
}
}, {
header: 'Symbolic Name',
dataIndex: 'symbolic_name',
width: 130,
editor: {
xtype:'textfield'
}
}],
selModel: {
selType: 'cellmodel'
},
plugins: [cellEditing_field]
});
the above is the grid i am using
thanks in advance

how do i create a tab in a tabpanel onclick?

I have an actioncolumn in a grid. I used to open a window after i clicked on this but now do we want to open a new tab in the tabpanel instead of the windows. This is the tab i want to generate when someone clicks on the actionpanel:
Ext.define('MyApp.view.MyTabPanel2', {
extend: 'Ext.tab.Panel',
alias: 'widget.mytabpanel2',
closable: true,
title: 'Report {name}',
activeTab: 1,
initComponent: function() {
var me = this;
Ext.applyIf(me, {
dockedItems: [
{
xtype: 'toolbar',
dock: 'top',
items: [
{
xtype: 'textfield',
fieldLabel: 'Reference',
labelAlign: 'top'
},
{
xtype: 'datefield',
fieldLabel: 'From',
labelAlign: 'top'
},
{
xtype: 'datefield',
fieldLabel: 'To',
labelAlign: 'top'
},
{
xtype: 'tbfill'
},
{
xtype: 'button',
text: 'Open report'
},
{
xtype: 'button',
text: 'Save report'
},
{
xtype: 'button',
text: 'Export report'
},
{
xtype: 'button',
text: 'Refresh data'
}
]
}
],
items: [
{
xtype: 'gridpanel',
title: 'Grid',
forceFit: true,
store: 'resultStore',
columns: [
{
xtype: 'gridcolumn',
dataIndex: 'ccuDesignation',
text: 'CCU Designation'
},
{
xtype: 'gridcolumn',
dataIndex: 'carrierName',
text: 'Carrier Name'
},
{
xtype: 'gridcolumn',
dataIndex: 'dataPackageName',
text: 'Data package name'
},
{
xtype: 'gridcolumn',
dataIndex: 'bytesRx',
text: 'bytesRX'
},
{
xtype: 'gridcolumn',
dataIndex: 'bytesTx',
text: 'bytesTX'
}
],
viewConfig: {
}
},
{
xtype: 'panel',
title: 'Chart',
dockedItems: [
{
xtype: 'chart',
height: 250,
animate: true,
insetPadding: 20,
store: 'resultStore',
dock: 'top',
axes: [
{
type: 'Category',
fields: [
'ccuDesignation'
],
position: 'bottom',
title: 'CCU Designation'
},
{
type: 'Numeric',
fields: [
'bytesTx'
],
position: 'left',
title: 'Bytes'
},
{
type: 'Numeric',
fields: [
'bytesRx'
],
position: 'left',
title: 'Bytes'
}
],
series: [
{
type: 'line',
xField: 'x',
yField: [
'bytesTx'
],
smooth: 3
},
{
type: 'line',
xField: 'x',
yField: [
'bytesRx'
],
smooth: 3
}
],
legend: {
}
}
]
}
]
});
me.callParent(arguments);
}
});
i have read this at sencha:
// tab generation code
var index = 0;
while(index < 3){
addTab(index % 2);
}
function addTab (closable) {
++index;
tabs.add({
title: 'New Tab ' + index,
iconCls: 'tabs',
html: 'Tab Body ' + index + '<br/><br/>' + Ext.example.bogusMarkup,
closable: !!closable
}).show();
}
Ext.createWidget('button', {
renderTo: 'addButtonCt',
text: 'Add Closable Tab',
handler: function () {
addTab(true);
},
iconCls:'new-tab'
});
Ext.createWidget('button', {
renderTo: 'addButtonCt',
text: 'Add Unclosable Tab',
handler: function () {
addTab(false);
},
iconCls:'new-tab',
style: 'margin-left: 8px;'
});
But i don't have the var tabs in my script. So how can i add the tab to this:
Ext.define('MyApp.view.MyViewport', {
extend: 'Ext.container.Viewport',
layout: {
type: 'border'
},
initComponent: function() {
var me = this;
Ext.applyIf(me, {
items: [
{
xtype: 'tabpanel',
id: 'tabs',
activeTab: 1,
region: 'center',
items: [
{
xtype: 'gridpanel',
title: 'Reports',
forceFit: true,
store: 'ReportsStore',
columns: [
{
xtype: 'gridcolumn',
dataIndex: 'Name',
text: 'Name'
},
{
xtype: 'gridcolumn',
dataIndex: 'Type',
text: 'Type'
},
{
xtype: 'gridcolumn',
dataIndex: 'Description',
text: 'Description'
},
{
xtype: 'actioncolumn',
dataIndex: 'queryFields',
items: [
{
handler: function(view, rowIndex, colIndex, item, e) {
addTab;
alert('clicked');
},
altText: 'Open report',
icon: 'img/report-arrow.png',
tooltip: 'Open report'
}
]
}
],
viewConfig: {
},
dockedItems: [
{
xtype: 'toolbar',
dock: 'bottom',
items: [
{
xtype: 'tbfill'
},
{
xtype: 'button',
iconCls: 'addReport',
text: 'Add report',
listeners: {
click: {
fn: me.onButtonClick,
scope: me
}
}
}
]
}
]
}
]
}
]
});
me.callParent(arguments);
},
onButtonClick: function(button, e, options) {
Ext.create('MyApp.view.addReport').show();
}
});
var tabs = Ext.getCmp('tabs');
function addTab (closable) {
alert('yes');
tabs.add(Ext.create('MyApp.view.MyTabPanel2'));
}
How can i do this? I work with extjs designer 2
In that first view you've shown above, you are creating another tabpanel not an individual tab. If you tried to insert that into the tabpanel that you defined in your viewport you would have a tabpanel inside of another tabpanel. I don't think that is what you are trying to do.
You could create that first view above as an Ext.tab.Tab which contains the gridpanel or just create it as the gridpanel itself and include the tab config options in your add method call. To answer your question about referencing the tabpanel when you don't have it defined as a variable: you should just give it an id config (e.g. id: 'tabs') and then you can use Ext.getCmp('tabs'). For example:
// a piece of your viewport config
Ext.applyIf(me, {
items: [
{
xtype: 'tabpanel',
activeTab: 1,
region: 'center',
id: 'tabs', // <-- include this config
// other configs...
Adding the tab could then be done like this:
// get a reference to the tab panel
var tabs = Ext.getCmp('tabs');
// if you create the view as a gridpanel you could do it like this
tabs.add({
title: sometitle,
iconCls: someicon,
closable: yayOrNay,
items: [Ext.create('MyApp.view.MyGridPanel')]
});
// OR if you create the view as an Ext.tab.Tab which already contains the gridpanel
tabs.add(Ext.create('MyApp.view.MyTab'));
Read And Use Following Code:
function allExpenseTypeReport(){
var reportByExpenseType=Ext.getCmp("reportByExpenseType");
if(reportByExpenseType==null){
reportByExpenseType = new Ext.tm.reports.ExpenseTypeReport({
title:WtfGlobal.getLocaleText("ec.reportbyexpensetype"),
layout:'fit' ,
closable: true,
iconCls:'pwnd tabreportsWrap',
id:"reportByExpenseType"
});
Ext.getCmp('as').add(reportByExpenseType);
}
Ext.getCmp("as").setActiveTab(Wtf.getCmp("reportByExpenseType"));
reportByExpenseType.doLayout();
}
Define Here:
Ext.tm.reports.ExpenseTypeReport = function(config){
Ext.apply(this, config);
Ext.tm.reports.ExpenseTypeReport.superclass.constructor.call(this, config);
Define your Code Here:
};

Resources