I gave it a try but it did not worked.
I am having two grids and a button. Initially the second grid will remain empty and the first grid will have some records.. When I select a few records in the first grid and click on the button, then the second grid should get populated with the only the selected rows of first grid.
Here is my code:
Ext.QuickTips.init();
var getLocalStore = function() {
return Ext.create('Ext.data.ArrayStore', {
model: 'Company',
data: Ext.grid.dummyData
});
};
var getSelectedStore = function() {
return Ext.create('Ext.data.ArrayStore', {
model: 'Company'
});
};
var sm = Ext.create('Ext.selection.CheckboxModel');
var grid1 = Ext.create('Ext.grid.Panel', {
id: 'grid1',
store: getSelectedStore(),
columns: [
{text: "Company", width: 200, dataIndex: 'company'},
{text: "Price", renderer: Ext.util.Format.usMoney, dataIndex: 'price'},
{text: "Change", dataIndex: 'change'},
{text: "% Change", dataIndex: 'pctChange'},
{text: "Last Updated", width: 135, renderer: Ext.util.Format.dateRenderer('m/d/Y'), dataIndex: 'lastChange'}
],
columnLines: true,
width: 600,
height: 300,
frame: true,
title: 'Framed with Checkbox Selection and Horizontal Scrolling',
iconCls: 'icon-grid',
renderTo: 'grid1'
});
var grid2 = Ext.create('Ext.grid.Panel', {
id: 'grid2',
store: getLocalStore(),
selModel: sm,
columns: [
{text: "Company", width: 200, dataIndex: 'company'},
{text: "Price", renderer: Ext.util.Format.usMoney, dataIndex: 'price'},
{text: "Change", dataIndex: 'change'},
{text: "% Change", dataIndex: 'pctChange'},
{text: "Last Updated", width: 135, renderer: Ext.util.Format.dateRenderer('m/d/Y'), dataIndex: 'lastChange'}
],
columnLines: true,
width: 600,
height: 300,
frame: true,
title: 'Framed with Checkbox Selection and Horizontal Scrolling',
iconCls: 'icon-grid',
renderTo: 'grid'
});
Ext.widget('button', {
text: 'Click Me',
renderTo: 'btn',
listeners: {
click: function(this1, evnt, eOpts ){
var records = sm.getSelection();
getSelectedStore().loadData(records,true);
grid1.getView().refresh();
/*Ext.each(records, function (record) {
alert(record.get('company'));
});*/
}
}
});
Please let me what's going wrong.
First, you are defining the functions getSelectedStore and getLocalStore which return new store instances when invoked. That way in your click handler you would be grabbing an empty store each time! Lose the function bit and just set variables like this:
var storeToSelectFrom = Ext.create('Ext.data.ArrayStore', {
model: 'Company',
data: someDataToChooseFrom
});
var storeToPutTo = Ext.create('Ext.data.ArrayStore', {
model: 'Company'
});
Then, define your grids using those variables as the stores:
var grid1 = Ext.create('Ext.grid.Panel',{
store: storeToSelectFrom,
selType: 'checkboxmodel'
// rest of your configs
});
var grid2 = Ext.create('Ext.grid.Panel',{
store: storeToPutTo
// rest of your configs
});
Then, create the button with a click handler:
Ext.widget('button', {
handler: function (button, event) {
var selected = grid1.getSelectionModel().getSelection();
grid2.getStore().add(selected);
}
// rest of your configs
});
Related
I have a Problem to open a popup window on cellclick.
When i click on the cell everything overlaid grey, but the window is not displayed.
The code is in the follow. Any idea why the new Window is not displayed?
Thanks and Regards.
var win = Ext.widget('window', {
title: 'Contact Us',
closeAction: 'hide',
width: 400,
height: 400,
minHeight: 400,
layout: 'fit',
resizable: true,
modal: true,
//items: form
});
Ext.define('File',{
extend: 'Ext.data.Model',
fields: [
{name: 'file_id'},
{name: 'file_input_filename'},
{name: 'file_type'},
{name: 'lc_status'},
{name: 'file_input_date'}
]
});
// create the Data Store
var overviewStore = Ext.create('Ext.data.Store', {
model: 'File',
autoLoad: true,
proxy: {
type: 'ajax',
url: 'FileOverview',
reader: {
type: 'xml',
// records will have an "Item" tag
record: 'Row',
idProperty: 'file_id',
totalRecords: '#total'
}
}
});
// create the grid
var gridOverview = Ext.create('Ext.grid.Panel', {
store: overviewStore,
id: 'OverviewGridPanelId',
columns: [
{text: "ID", flex: 1, dataIndex: 'file_id', sortable: true},
{text: "Filename", width: 180, dataIndex: 'file_input_filename', sortable: true},
{text: "Filetyp", width: 180, dataIndex: 'file_type', sortable: true},
{text: "Status", width: 180, dataIndex: 'lc_status', sortable: true},
{text: "Imported", width: 115, dataIndex: 'file_input_date', sortable: true}
],
renderTo:'binding-example',
width: 1200,
height: 650,
});
gridOverview.on('cellclick', function(table, td, cellIndex, record, tr, rowIndex, e, eOpts) {
var masterIndex = rowIndex;
//openDialog(record.get('file_id'));
Ext.Msg.alert('locked grid click');
win.show();
});
}
I am on ExtJs3.2.
There is a gridpanel with a column having a textField as an editor.
On change of value in the textfield - i need the corresponding row to be highlighted.
How do I get the 'owning' row index of the text field?
columns: [
...........
{header: 'Revenues',dataIndex: 'percentage',
editor: new Ext.form.TextField({
listeners: {
'change' : function (field, newValue, oldValue) {
if(oldValue!=newValue){
.......
//How do I get the row index?
Ext.fly(grid.getView().getRow(row)).addClass('yellow-row');
}
}
}
Is there any other way to achieve this?
Could you please try below?
var grid = Ext.grid.GridPanel({
store: yourStore,
id: 'myGrid',
colModel: new Ext.grid.ColumnModel({
defaults: {
width: 120,
sortable: true
},
columns: [
{id: 'Company', header: 'Company', width: 120, sortable: true, dataIndex: 'company'},
{header: 'Change', dataIndex: 'change'},
{
header: 'Revenue',
dataIndex: 'percentage',
editor: new Ext.form.TextField({
listeners: {
'change': function(field, newValue, oldValue) {
if (oldValue != newValue) {
var sel = Ext.getCmp('myGrid').getSelectionModel().getSelected();
// if you select more than one record use getSelections instead of getSelected
console.log(sel);
}
}
}
})
}
]
}),
sm: new Ext.grid.RowSelectionModel({singleSelect: true}),
width: 500,
height: 300,
frame: true,
title: 'My Grid'
});
I have an ExtJS grid with a toolbar button to save the date. The save works and the data is stored. But the grid is not refreshed. How do I reload the grid data after the save?
Ext.define('MyLodge.view.content.MemberGrid', {
extend: 'Ext.grid.Panel',
alias: 'widget.membergrid',
initComponent: function(){
var rowEditing = Ext.create('Ext.grid.plugin.RowEditing');
var store = Ext.create('MyLodge.store.Members');
Ext.apply(this, {
height: this.height,
plugins: [rowEditing],
store: store,
stripeRows: true,
columnLines: true,
columns: [{
id :'id',
text: 'ID',
width: 40,
sortable: true,
dataIndex: 'id'
},{
text : 'Name',
flex: 1,
sortable : true,
dataIndex: 'name',
field: {
xtype: 'textfield'
}
},{
text : 'E-Mail',
width : 150,
sortable : true,
dataIndex: 'email',
field: {
xtype: 'textfield'
}
},{
text : 'Href',
width : 200,
sortable : true,
dataIndex: 'href',
field: {
xtype: 'textfield'
}
}],
dockedItems: [{
xtype: 'toolbar',
items: [{
text: 'Add',
iconCls: 'icon-add',
handler: function(){
// empty record
store.insert(0, new MyLodge.model.Member());
rowEditing.startEdit(0, 0);
}
}, {
text: 'Delete',
iconCls: 'icon-delete',
handler: function(){
var selection = grid.getView().getSelectionModel().getSelection()[0];
if (selection) {
store.remove(selection);
}
}
},'-',{
text: 'Save',
iconCls: 'icon-save',
handler: function(){
store.sync();
}
}]
}]
});
this.callParent(arguments);
}
});
You can load store in callback of sync
store.sync({
success: function( response ) {
store.load();
}
});
You will probably want to call store.reload() in a callback from store.save() (what is store.save() anyway? it is not part of Ext.data.Store interface)
I'm trying to put a Grid (Ext.grid.GridPanel) object inside a Tab .
This is the code:
var grid = new Ext.grid.GridPanel({
store: new Ext.data.Store({
autoDestroy: true,
reader: reader,
data: xg.dummyData
}),
colModel: new Ext.grid.ColumnModel({
defaults: {
width: 120,
sortable: true
},
columns: [
{id: 'company', header: 'Company', width: 200, sortable: true, dataIndex: 'company'},
{header: 'Price', renderer: Ext.util.Format.usMoney, dataIndex: 'price'},
{header: 'Change', dataIndex: 'change'},
{header: '% Change', dataIndex: 'pctChange'},
// instead of specifying renderer: Ext.util.Format.dateRenderer('m/d/Y') use xtype
{
header: 'Last Updated', width: 135, dataIndex: 'lastChange',
xtype: 'datecolumn', format: 'M d, Y'
}
]
}),
sm: new Ext.grid.RowSelectionModel({singleSelect:true}),
width: 600,
height: 300,
frame: true,
title: 'Framed with Row Selection and Horizontal Scrolling',
iconCls: 'icon-grid'
});
this.tabs = new Ext.TabPanel({
fullscreen: true,
type: 'dark',
sortable: true,
dockedItems: [
{
xtype:'toolbar',
title:'Hello World'
}],
tabBar: {
ui: 'light',
layout: {
pack: 'left'
}
},
items: [
{
cls:'hello',
id:'tab1',
html : '<a>hello</a>',
title:'Monitor'
}, {
cls:'world',
id:'tab2',
xtype: 'map',
html : '<a>hello world</a>',
title:'Map'
}, {
cls:'world',
id:'tab3',
html : '<a>hello world</a>',
dockedItems:grid
}]
});
When I load the page there's no error, but the grid is not shown.
The grid is not a docked item (that's for toolbars and other things that should stick to one side of a container). If you want the grid to take up the entire tab, just add it directly as an item to the TabPanel and it will become the full tab:
items: [
{
cls:'hello',
id:'tab1',
html : '<a>hello</a>',
title:'Monitor'
}, {
cls:'world',
id:'tab2',
xtype: 'map',
html : '<a>hello world</a>',
title:'Map'
},
grid ]
<table cellspacing="0" cellpadding="0" border="0" class="x-btn-wrap x-btn x-btn-text-icon" id="ext-comp-1169" style="width: auto;">
Profile
In this code, how can we get the reference to the button element?
In this particular case, Ext.getCmp('ext-comp-1169') would do the trick.
However, you should manually assign more sensible id values to components by using the id config option - otherwise you get auto-assigned ids.
This is the code I am using now.
function renderLinkBtn(val, p, record) {
var contentId = Ext.id();
createLinkButton.defer(1, this, [val, contentId, record]);
return('<div id="' + contentId + '"></div>');
};
function createLinkButton(value, id, record) {
var actnBtn = new Ext.Toolbar.SplitButton({
text: 'Action',
icon: '../images/icon-btn-action.png',
menu: new Ext.menu.Menu({
items: [
{text: 'Item 1'},
{text: 'Item 2'}
]
})
}).render(document.body, id);
}
var grid1 = new xg.GridPanel({
store: new Ext.data.Store({
reader: reader,
data: xg.dummyData
}),
cm: new xg.ColumnModel({
defaults: {
width: 20,
sortable: false
},
columns: [
{id:'id', header: "Link", renderer:renderLinkBtn, width: 25, align:'center', dataIndex:'id'},
{id:'company',header: "Company", width: 40, dataIndex: 'company'},
{header: "Price", renderer: Ext.util.Format.usMoney, dataIndex: 'price'},
{header: "Change", dataIndex: 'change'},
{header: "% Change", dataIndex: 'pctChange'},
{header: "Last Updated", renderer: Ext.util.Format.dateRenderer('m/d/Y'), dataIndex: 'lastChange'}
]
}),
sm: new Ext.grid.RowSelectionModel({
singleSelect: false,
listeners: {
rowselect: function(sm, row, rec) {
//grid1.getView().refreshRow(rec)
/* var btnElement = Ext.getDom(contentIdArray[row].btnEl.id);
btnElement.disabled = true;
Ext.Msg.alert(btnElement);*/
},
rowdeselect:function(sm, row, rec) {
/* var btnElement = Ext.getDom(contentIdArray[row].btnEl.id);
btnElement.disabled = false;*/
}
}
}),
viewConfig: {
forceFit:true
},
width: 600,
height: 300,
animCollapse: false,
title: 'Grid Panel with Button Renderer',
iconCls: 'icon-grid',
renderTo: document.body
});
First you should get a reference to your button Component. This can be saved in your DOM structure somewhere or you can get a reference to it with Ext.getCmp('myId') if you know the ID of your component.
When you have the Component simply fetch it's Ext.Element and search down the dom tree for a element like this
var myButton = Ext.getCmp('ext-comp-1169');
var buttonElement = myButton.getEl().child('button');