View Full Version : not able to add row to the grid in a window

17 Oct 2012, 5:08 AM
hello everyone,

here i have created an Ext grid with the ArrayStore . at first i just display an empty grid. and on particular event i need to add the rows with data to the grid in Ext.window .

my code is like this
var myData = [];
var selectionStore = new Ext.data.ArrayStore({
fields: [
{name: 'srno', type: 'int'},
{name: 'selections', type: 'string'}
data: myData

myWindow = new Ext.Window({
height: 200,
width: 400,
title: 'Selections Window',
id: 'selection_window',
layout: 'fit',
bbar: {
items: [{
xtype: 'button',
text: 'Send',
handler: callSubmitSelected
}, {
xtype: 'button',
text: 'Remove',
handler: deleteRowSelected
}, {
xtype: 'button',
text: 'close',
handler: callCloseDialog
items: [{
xtype: 'grid',
title: 'selectionGrid',
id: 'window-grid',
store: selectionStore,
columns: [
header: '',
width: 40,
dataIndex: 'srno'
header: 'selections',
width: 360,
dataIndex: 'selections'

this code displays a window with an empty grid.

here onwards i have written following code on a particular event to add the row with a new data to the grid created above

var innerArray = [

the values of count and curId , i get dynamically

var store_new = Ext.getCmp('window-grid').getStore();

but this code doesn't add to the grid .. what am i missing ?

any help is appreciated...

17 Oct 2012, 6:00 AM
Hello waits4uonly,
I think you need to define new array in different way for the array type store. Review the following code:

var count = 23, curId = 'Testing';
var innerArray = [[count, curId]];
var store_new = Ext.getCmp('window-grid').getStore();
store_new.loadData(innerArray, true);

If you are adding any new record to the store, It will be automatically shown on the grid. If it is not shown on UI, you may refresh the view of the grid by calling the function -

var grid = Ext.getCmp('window-grid');

James Goddard
17 Oct 2012, 6:12 AM
You can't add a single "array record" to an array store. Basicly the add function does an isArray on the record being added and assumes, if it is true that you are adding more than one record, not a single array record.

You'll have to wrap your array in an array to make it work:


17 Oct 2012, 9:31 PM
hello Swort-it,

i have tried code snippet provided by you. it adds data to the grid for first time but on adding record second time the record doesn't get added to the grid.

17 Oct 2012, 9:34 PM
hello James Goddard (http://www.sencha.com/forum/member.php?96036-James-Goddard),

i have followed the change you suggested. but i am getting an error like

e.data is undefined and record doesn't get added to the grid.i need to add rows to the grid anytime on a particular event