PDA

View Full Version : [ask] how to change url of data store when a button was clicked



yehezqiel
13 Sep 2010, 6:56 PM
please somebody help me..
how to change url of data store when a button was clicked..

my code for the grid is like this :


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

var ds_model = Ext.data.Record.create
([
'no',
'message',
'status'
]);

var store = new Ext.data.Store
({
url: 'doData?no=1',
reader: new Ext.data.JsonReader
(
{
root:'rows',
id: 'no'
},
[
'no',
'message',
'status'
]
)
});
store.load();

var grid = new Ext.grid.EditorGridPanel
({
renderTo: 'editor-grid',
frame:true,
title: '<div align="center">Message Detail</div>',
height:500,
width:900,
autoWidth:true,
store: store,
clickstoEdit: 1,
columns:
[
{header: "No.", dataIndex: 'no', width:70},
{header: "Message", dataIndex: 'message', sortable:true, autoWidth:true, width: 700},
{header: "Status", dataIndex: 'status', sortable:true, autoWidth:true, width:100}
]
});
}
that's only show 1 row in the grid.
and then i want if the user click the button, then the grid should show all records in the database..
so i must change the url of data store, but i can't find how to do it..


function addRow()
{
grid.getStore().url = 'doData'; // it doesn't work
grid.getStore().load(); // the store was loaded with first url defined when create data store
}

var btnAdd = new Ext.Button
({
applyTo: 'btnAdd',
text: 'Add Row'
}) ;
btnAdd.addListener('click',addRow);
thx b4..

Condor
14 Sep 2010, 12:22 AM
1. Why do you want to change the url. Most people that ask how to do this actually should do something different.
2. You can change the url by using:

grid.getStore().proxy.setUrl('newurl', true);

yehezqiel
14 Sep 2010, 1:11 AM
1. Why do you want to change the url. Most people that ask how to do this actually should do something different.
2. You can change the url by using:

grid.getStore().proxy.setUrl('newurl', true);

thx.. but i've changed the code, not to change the url but change the params.. :)

and i want to ask, about how to change a value in a grid..
for example, when a button was clicked then value of a specific record was changed..?

Condor
14 Sep 2010, 1:16 AM
I don't understand the question...

yehezqiel
14 Sep 2010, 1:24 AM
I don't understand the question...

ohh i see..

hhmm for example there is a grid and a button..
the grid have 3 columns : a, b ,c and several records..

then if i click the button, value of column c in specific record should change into 'bla bla bla'..

Condor
14 Sep 2010, 1:33 AM
handler: function(){
var record = grid.getSelectionModel().getSelected();
record.set('name-of-field-in-third-column', 'bla bla bla');
}

yehezqiel
14 Sep 2010, 1:39 AM
handler: function(){
var record = grid.getSelectionModel().getSelected();
record.set('name-of-field-in-third-column', 'bla bla bla');
}

thx for ur help..
i'll try it..