PDA

View Full Version : grid shows only 2 rows



mayurid
20 Jul 2010, 5:15 AM
hi all,

i got a strange problem,the load pulls all values from backend(in firebug i have seen)but it shows only two rows in grid...

Ext.onReady(function(){
Ext.QuickTips.init();

var names = [
['Product'],
['Service']
];
var mySimpleStore = new Ext.data.ArrayStore({
data : names,
fields : ['name']});
var SimpleStore = new Ext.data.ArrayStore({
data : names,
fields : ['name']});
var names = [
['Product'],
['Service']
];
function handleDelete(){
if(grid.selModel.getCount() == 1)
{
Ext.MessageBox.confirm('Confirmation','Do you want to delete?', deleteRow);
} else if(grid.selModel.getCount() > 1){
Ext.MessageBox.confirm('Confirmation','Delete Rows Selected?', deleteRow);
} else {
Ext.MessageBox.alert('Uh oh...','You can\'t really delete something you haven\'t selected huh?');
}
}
function deleteRow(btn){
if(btn=='yes'){
var selections = grid.selModel.getSelections();
var prez = [];
for(i = 0; i< grid.selModel.getCount(); i++){
prez.push(selections[i].json.id);
}
var encoded_array = Ext.encode(prez);
Ext.Ajax.request({
waitMsg: 'Please Wait',
url: 'gl_acc.php',
params: {
task: "delete",
ids: encoded_array
},
success: function(){
gl_account.load({params : {start : 0}});

},
failure: function(response){
var result=response.responseText;
Ext.MessageBox.alert('error','Could not connect to the database. Retry later');
}
});
}
}

var category = Ext.data.Record.create([ {

types: 'types',
type: 'string'
},{
category_name: 'category_name',
type: 'string'
}]);

var gl_account = new Ext.data.GroupingStore({
proxy: new Ext.data.ScriptTagProxy({
url:'gl_acc.php'
}),
baseParams:{task: "list"},
reader: new Ext.data.JsonReader({
root: 'results',
totalProperty: 'total',
id: 'types'
},
[{name:'types',type:'string'}, {name:'category_name',type: 'string'},{name:'id',type:'numeric'}

])
});


var editor = new Ext.ux.grid.RowEditor({
saveText: 'Save'});

editor.on('afteredit', function(rowEditor, changes, record, rowIndex){
var record = rowEditor.grid.getStore().getAt(rowIndex);
Ext.Ajax.request({
url:'gl_acc.php',
params: {
task: 'update',
field: 'category_name',
row: rowIndex,
id:record.get('id'),
types:record.get('types'),
value: changes['category_name']
},
success: function(response){
var result=eval(response.responseText);
switch(result){case 0:Ext.MessageBox.alert('alert','User name alreday used,try another');
break;
case 1:Ext.MessageBox.alert('alert','category Created');break;
case 2:Ext.MessageBox.alert('alert','category Updated');
}

}
});
});
var grid = new Ext.grid.GridPanel({
store: gl_account,
width: '100%',
region:'center',
plugins: [editor],
view: new Ext.grid.GroupingView({
markDirty: false
}),viewConfig:{ forceFit:true },
tbar: [{xtype:'label',text:'Type'},
{
xtype: 'combo',
fieldLabel: 'Type',
displayField: 'name',
mode: 'local',
id: 'product',
name: 'product',
typeAhead: false,
store: mySimpleStore,
triggerAction: 'all',
allowBlank: true,
width: 120,
listeners: {
select: function(combo, record, index){
var f = Ext.getCmp('search_field');
f.store.setBaseParam('types', record.get('name'));
f.store.setBaseParam('task', 'search'); //stor is the default store
f.clear();
}
}
}, {
xtype: 'label',
text: 'Category',
style: {
"margin-left": "20px"
}
}, new Ext.ux.form.SearchField({
width: 130,
store: gl_account,
id: 'search_field'
}),{xtype: 'box', id: 'loginMessage',style:{'color':'red','font-size':'25px'}},'->',
{

iconCls: 'icon-user-add',
text: 'Add ',
id:'add',
handler: function(){

var e = new category({
types: 'Product',
category_name:'category_name',
id:0

});

editor.stopEditing();
gl_account.insert(0, e);

grid.getView().refresh();
grid.getSelectionModel().selectRow(0);
var s= grid.getSelectionModel().getSelections();
editor.startEditing(0);
}
},{
ref: '../removeBtn',
iconCls: 'icon-user-delete',
text: 'Remove category',

handler:handleDelete

}],
columns: [{header:"ID",dataIndex:'id',width:25,hidden:true},{header:"type",dataIndex:'types',width:100, editor:{xtype:'combo',
displayField: 'name',
mode: 'local',
id: 'product1',
name: 'product1',
typeAhead: false,
store: SimpleStore,
triggerAction: 'all',
allowBlank: true,
width: 120}},
{
id: 'name',
header: 'Name',
dataIndex: 'category_name',
width:200,
sortable: true,
editor: {
xtype: 'textfield',
allowBlank: false
}
}
],bbar: new Ext.PagingToolbar
({
store:gl_account,


displayInfo: true,
displayMsg: 'Topics {0} - {1} of {2}',
emptyMsg: "No topics to display"

})
});
var layout = new Ext.Panel({
title: 'Categories',
layout: 'border',
layoutConfig: {
columns: 1
},
width:'100%',
height:500,



items: [grid]
});
layout.render(Ext.getBody());

grid.getSelectionModel().on('selectionchange', function(sm){
grid.removeBtn.setDisabled(sm.getCount() < 1);
});

gl_account.load();

});