PDA

View Full Version : Array Grid - How to reload



igor2000
6 Jul 2010, 9:45 AM
Hi, i am having troubles to reload the grid...

i am using grid.store.reload()

but it says 'this.proxy' is null or not an object

if I try to grid.render('grid') it duplicates the grid. giving 2x more grids every time (2,4,8,...)

Can someone help here?

my array variable is all good, i just dont know how to reload the data...

mankz
6 Jul 2010, 9:55 AM
To load new static data, just do another store.loadData(); What are you trying to achieve?

igor2000
6 Jul 2010, 10:12 AM
I have this function in a button, for example, and wants to reload the grid with another array when clicked. kindda simple

------------------------------------------------

tried to do so, it didnt work

should i use any other commands? i.e. render it again?

mankz
6 Jul 2010, 10:18 AM
Then just use loadData(), should be fine!

igor2000
6 Jul 2010, 10:23 AM
nothing happens... but the array variable is alright... i did a alert with it right after the loadData

mankz
6 Jul 2010, 10:25 AM
Please post your code (in CODE tags).

igor2000
6 Jul 2010, 10:28 AM
function depois(bReload)
{
Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
var array = [];
i = 0;
while (i < dados.length-1)
{
array.push(dados[i].split("##"));
i = i + 1;
}
var store = new Ext.data.ArrayStore({
fields: [
{name: 'Codigo', type: 'int', hidden: true },
{name: 'DocNum', type:'int'},
{name: 'DocAno', type: 'int'},
{name: 'Descricao', type: 'string'},
{name: 'DocData', type: 'string'},
{name: 'DocHora', type: 'string'},
{name: 'Hyperlink', type: 'string'},
{name: 'Obs', type: 'string' }

]
});

// manually load local data

store.loadData(array);alert(array); //array is the variable that changes on a click event of a button
if (bReload == true) {store.loadData(array); return ;}
// create the Grid
var grid = new Ext.grid.GridPanel({
store: store,
tbar: [{
ref: '../removeBtn',
iconCls: 'icon-user-delete',
text: 'Deletar ',
disabled: true,
handler: function(){
if (confirm('Voce tem certeza que quer excluir?'))
{
//editor.stopEditing();
var s = grid.getSelectionModel().getSelections();
alert(s[0]['data']['Codigo']);
for(var i = 0, r; r = s[i]; i++){
store.remove(r);
}
}
}
}],
columns: [
{header: '#', sortable: true, width: 50, dataIndex: 'Codigo', hidden: true },
{header: 'Num. Doc', sortable: true , width: 70, dataIndex: 'DocNum'},
{header: 'Ano', sortable: true, width: 40, dataIndex: 'DocAno'},
{header: 'Tipo Documento', sortable: true, width: 220, dataIndex: 'Descricao'},
{header: 'Data', sortable: true, width: 70, dataIndex: 'DocData'},
{header: 'Hora', sortable: true, width: 60, dataIndex: 'DocHora'},
{header: 'Hyperlink', sortable: true, width: 120, dataIndex: 'Hyperlink'},
{header: 'Observacoes', sortable: true, width: 220, dataIndex: 'Obs'}
],
stripeRows: true,
height: 150,
width: 600,
//title: 'Array Grid',
// config options for stateful behavior
stateful: true,
stateId: 'grid'
});

// render the grid to the specified div in the page
grid.render('grid');

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

igor2000
6 Jul 2010, 10:29 AM
function depois(bReload)
{
Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
var array = [];
i = 0;
while (i < dados.length-1)
{
array.push(dados[i].split("##"));
i = i + 1;
}
var store = new Ext.data.ArrayStore({
fields: [
{name: 'Codigo', type: 'int', hidden: true },
{name: 'DocNum', type:'int'},
{name: 'DocAno', type: 'int'},
{name: 'Descricao', type: 'string'},
{name: 'DocData', type: 'string'},
{name: 'DocHora', type: 'string'},
{name: 'Hyperlink', type: 'string'},
{name: 'Obs', type: 'string' }

]
});

// manually load local data

store.loadData(array);alert(array); // array is the variable that changes on a button click
if (bReload == true) {store.loadData(array); return ;}
// create the Grid
var grid = new Ext.grid.GridPanel({
store: store,
tbar: [{
ref: '../removeBtn',
iconCls: 'icon-user-delete',
text: 'Deletar ',
disabled: true,
handler: function(){
if (confirm('Voce tem certeza que quer excluir?'))
{
//editor.stopEditing();
var s = grid.getSelectionModel().getSelections();
alert(s[0]['data']['Codigo']);
for(var i = 0, r; r = s[i]; i++){
store.remove(r);
}
}
}
}],
columns: [
{header: '#', sortable: true, width: 50, dataIndex: 'Codigo', hidden: true },
{header: 'Num. Doc', sortable: true , width: 70, dataIndex: 'DocNum'},
{header: 'Ano', sortable: true, width: 40, dataIndex: 'DocAno'},
{header: 'Tipo Documento', sortable: true, width: 220, dataIndex: 'Descricao'},
{header: 'Data', sortable: true, width: 70, dataIndex: 'DocData'},
{header: 'Hora', sortable: true, width: 60, dataIndex: 'DocHora'},
{header: 'Hyperlink', sortable: true, width: 120, dataIndex: 'Hyperlink'},
{header: 'Observacoes', sortable: true, width: 220, dataIndex: 'Obs'}
],
stripeRows: true,
height: 150,
width: 600,
//title: 'Array Grid',
// config options for stateful behavior
stateful: true,
stateId: 'grid'
});

// render the grid to the specified div in the page
grid.render('grid');

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

igor2000
6 Jul 2010, 10:30 AM
i guess it needs moderator approval to post the code?

mankz
6 Jul 2010, 10:32 AM
Don't think so, but some posts are randomly moderated. :(

igor2000
6 Jul 2010, 10:35 AM
function depois(bReload)
{
Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
var array = [];
i = 0;
while (i < dados.length-1)
{
array.push(dados[i].split("##"));
i = i + 1;
}
var store = new Ext.data.ArrayStore({
fields: [
{name: 'Codigo', type: 'int', hidden: true },
{name: 'DocNum', type:'int'},
{name: 'DocAno', type: 'int'},
{name: 'Descricao', type: 'string'},
{name: 'DocData', type: 'string'},
{name: 'DocHora', type: 'string'},
{name: 'Hyperlink', type: 'string'},
{name: 'Obs', type: 'string' }

]
});

// manually load local data

store.loadData(array);alert(array); // array is the variable that changes on a button click
if (bReload == true) {store.loadData(array); return ;}
// create the Grid
var grid = new Ext.grid.GridPanel({
store: store,
tbar: [{
ref: '../removeBtn',
iconCls: 'icon-user-delete',
text: 'Deletar ',
disabled: true,
handler: function(){
if (confirm('Voce tem certeza que quer excluir?'))
{
//editor.stopEditing();
var s = grid.getSelectionModel().getSelections();
alert(s[0]['data']['Codigo']);
for(var i = 0, r; r = s[i]; i++){
store.remove(r);
}
}
}
}],
columns: [
{header: '#', sortable: true, width: 50, dataIndex: 'Codigo', hidden: true },
{header: 'Num. Doc', sortable: true , width: 70, dataIndex: 'DocNum'},
{header: 'Ano', sortable: true, width: 40, dataIndex: 'DocAno'},
{header: 'Tipo Documento', sortable: true, width: 220, dataIndex: 'Descricao'},
{header: 'Data', sortable: true, width: 70, dataIndex: 'DocData'},
{header: 'Hora', sortable: true, width: 60, dataIndex: 'DocHora'},
{header: 'Hyperlink', sortable: true, width: 120, dataIndex: 'Hyperlink'},
{header: 'Observacoes', sortable: true, width: 220, dataIndex: 'Obs'}
],
stripeRows: true,
height: 150,
width: 600,
//title: 'Array Grid',
// config options for stateful behavior
stateful: true,
stateId: 'grid'
});

// render the grid to the specified div in the page
grid.render('grid');

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

igor2000
6 Jul 2010, 10:38 AM
----------------

igor2000
6 Jul 2010, 10:38 AM
function depois(bReload)
{
Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
var array = [];
i = 0;
while (i < dados.length-1)
{
array.push(dados[i].split("##"));
i = i + 1;
}
var store = new Ext.data.ArrayStore({
fields: [
{name: 'Codigo', type: 'int', hidden: true },
{name: 'DocNum', type:'int'},
{name: 'DocAno', type: 'int'},
{name: 'Descricao', type: 'string'},
{name: 'DocData', type: 'string'},
{name: 'DocHora', type: 'string'},
{name: 'Hyperlink', type: 'string'},
{name: 'Obs', type: 'string' }

]
});

// manually load local data

store.loadData(array);alert(array);

igor2000
6 Jul 2010, 10:39 AM
function depois(bReload)
{
Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
var array = [];
i = 0;
while (i < dados.length-1)
{
array.push(dados[i].split("##"));
i = i + 1;
}
var store = new Ext.data.ArrayStore({
fields: [
{name: 'Codigo', type: 'int', hidden: true },
{name: 'DocNum', type:'int'},
{name: 'DocAno', type: 'int'},
{name: 'Descricao', type: 'string'},
{name: 'DocData', type: 'string'},
{name: 'DocHora', type: 'string'},
{name: 'Hyperlink', type: 'string'},
{name: 'Obs', type: 'string' }

]
});

// manually load local data

store.loadData(array);alert(array);
if (bReload == true) {store.loadData(array); return ;}
// create the Grid
var grid = new Ext.grid.GridPanel({
store: store,
tbar: [{
ref: '../removeBtn',
iconCls: 'icon-user-delete',
text: 'Deletar ',
disabled: true,
handler: function(){
if (confirm('Voce tem certeza que quer excluir?'))
{
//editor.stopEditing();
var s = grid.getSelectionModel().getSelections();
alert(s[0]['data']['Codigo']);
for(var i = 0, r; r = s[i]; i++){
store.remove(r);
}
}
}
}],
columns: [
{header: '#', sortable: true, width: 50, dataIndex: 'Codigo', hidden: true },
{header: 'Num. Doc', sortable: true , width: 70, dataIndex: 'DocNum'},
{header: 'Ano', sortable: true, width: 40, dataIndex: 'DocAno'},
{header: 'Tipo Documento', sortable: true, width: 220, dataIndex: 'Descricao'},
{header: 'Data', sortable: true, width: 70, dataIndex: 'DocData'},
{header: 'Hora', sortable: true, width: 60, dataIndex: 'DocHora'},
{header: 'Hyperlink', sortable: true, width: 120, dataIndex: 'Hyperlink'},
{header: 'Observacoes', sortable: true, width: 220, dataIndex: 'Obs'}
],
stripeRows: true,
height: 150,
width: 600,
//title: 'Array Grid',
// config options for stateful behavior
stateful: true,
stateId: 'grid'
});

// render the grid to the specified div in the page
grid.render('grid');

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

}

igor2000
6 Jul 2010, 10:41 AM
function depois(bReload)
{
Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
var array = [];
i = 0;
while (i < dados.length-1)
{
array.push(dados[i].split("##"));
i = i + 1;
}
var store = new Ext.data.ArrayStore({
fields: [
{name: 'Codigo', type: 'int', hidden: true },
{name: 'DocNum', type:'int'},
{name: 'DocAno', type: 'int'},
{name: 'Descricao', type: 'string'},
{name: 'DocData', type: 'string'},
{name: 'DocHora', type: 'string'},
{name: 'Hyperlink', type: 'string'},
{name: 'Obs', type: 'string' }

]
});
// manually load local data

store.loadData(array);alert(array); // this variable changes on a button click
if (bReload == true) {store.loadData(array); return ;}
// create the Grid
var grid = new Ext.grid.GridPanel({
store: store,
tbar: [{
ref: '../removeBtn',
iconCls: 'icon-user-delete',
text: 'Deletar ',
disabled: true,
handler: function(){
if (confirm('Voce tem certeza que quer excluir?'))
{
//editor.stopEditing();
var s = grid.getSelectionModel().getSelections();
alert(s[0]['data']['Codigo']);
for(var i = 0, r; r = s[i]; i++){
store.remove(r);
}
}
}
}],
columns: [
{header: '#', sortable: true, width: 50, dataIndex: 'Codigo', hidden: true },
{header: 'Num. Doc', sortable: true , width: 70, dataIndex: 'DocNum'},
{header: 'Ano', sortable: true, width: 40, dataIndex: 'DocAno'},
{header: 'Tipo Documento', sortable: true, width: 220, dataIndex: 'Descricao'},
{header: 'Data', sortable: true, width: 70, dataIndex: 'DocData'},
{header: 'Hora', sortable: true, width: 60, dataIndex: 'DocHora'},
{header: 'Hyperlink', sortable: true, width: 120, dataIndex: 'Hyperlink'},
{header: 'Observacoes', sortable: true, width: 220, dataIndex: 'Obs'}
],
stripeRows: true,
height: 150,
width: 600,
//title: 'Array Grid',
// config options for stateful behavior
stateful: true,
stateId: 'grid'
});
// render the grid to the specified div in the page
grid.render('grid');

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


and thats it

mankz
6 Jul 2010, 11:32 AM
Is depois called on your button click?

igor2000
6 Jul 2010, 11:44 AM
yep, and also array is changed before call depois

mankz
6 Jul 2010, 11:49 AM
Ok, sounds like a pretty bad idea since your depois function creates a new store and loads the new data into it. You should study the grid examples and structure your code differently.

igor2000
7 Jul 2010, 3:11 AM
alright, now you say it makes sense

mankz
7 Jul 2010, 3:11 AM
:)

igor2000
7 Jul 2010, 3:12 AM
hey, thanks for being so fast in helping

mankz
7 Jul 2010, 3:13 AM
You're most welcome!

igor2000
7 Jul 2010, 3:17 AM
i did a new function, but in there it cant see 'store' wich was declared in depois function, how do i declare it like global ?
---------------------------------------------------

igor2000
7 Jul 2010, 5:28 AM
never mind i just declared it outside everything, it worked! thx man

hey, one last question what
"Ext.state.Manager.setProvider(new Ext.state.CookieProvider());"

does??