PDA

View Full Version : Changing "baseParams" doesn't change anything...



moonwhaler
16 Feb 2010, 3:00 AM
Hi there,

maybe it's my own fault (it usually is), but I don't get this: I try filtering my grid by changing the "baseParams". I "add" new content, which is passed on to my server-side PHP. This works very well, but only one (!) time. After that, and retrying to change the same data (variable in "baseParams") the same value I chose before will get transfered again (at least Firebug tells me so) even if I change the content of my input field (ComboBox). I even tried to "delete()" the parameter by hand, but nothing happened...

Here's some code, I'm stuck:


// Model datastore
var megaDataStoreModel = new Ext.data.Store({
id: 'megaDataStoreModel',
proxy: megaDataProxy,
reader: megaDataReader,

// Do not save changes as soon as they happen, but when requested
autoSave: false,
autoLoad: true,

baseParams: {
task: "MODELS",
ext: "js"
},

// First column to sort by
sortInfo: {
field: 'Model',
direction: "ASC"
}
});

// Main datastore
var megaDataStore = new Ext.data.Store({
id: 'megaDataStore',
proxy: megaDataProxy,
reader: megaDataReader,

// Do not save changes as soon as they happen, but when requested
autoSave: megaGridAutosave,

baseParams: {
task: "LISTING", // this parameter asks for listing (which is a function on the PHP server)
ext: "js"
},

autoLoad: {
params: {start: 0, limit: megaGridPageSize}
},

// Sort on the server, not the client
remoteSort: megaGridRemoteSort,

// First column to sort by
sortInfo: {
field: 'VehicleNumber',
direction: "ASC"
}
});

function displayMegaFilterWindow(){
// local vars
var searchFormPanel;
var searchWindow;

var SearchModelComboBox = new Ext.form.ComboBox({
fieldLabel: 'Model',
store: megaDataStoreModel,
displayField: 'Model',
valueField: 'Model',
triggerAction: 'all',
typeAhead: true,
selectOnFocus: true,
mode: 'remote'
});

var searchFormPanel = new Ext.form.FormPanel({
title: 'Search',
width: 300,
bodyStyle: 'padding: 10px;',
labelAlign: 'top',
border: false,

items:[SearchModelComboBox],

buttons: [
{
text: 'Search',
handler: function() {
listSearch();
}
},
{
text: 'Cancel',
handler: function() {
resetSearch();
}
},
]
});

searchWindow = new Ext.Window({
title: 'Cars filter',
closable: true,
width: 400,
height: 400,
plain: true,
layout: 'fit',
items: searchFormPanel
});

searchWindow.show();

function listSearch(){
// change the store parameters
delete(megaDataStore.baseParams['Model']);

megaDataStore.baseParams = {
task: 'SEARCH',
Model : SearchModelComboBox.getValue(),
};

megaDataStore.reload();
}

function resetSearch() {
delete(megaDataStore.baseParams['Model']);

megaDataStore.baseParams = {
task: 'SEARCH'
};

searchWindow.close();
}
}
Thank you for any help!

Eugen_
16 Feb 2010, 3:13 AM
Hi moonwhaler,

Use the setBaseParam method to change the baseParams property


yourStore.setBaseParam('name', value);

moonwhaler
16 Feb 2010, 8:10 AM
Thanks, but it didn't change anything... :(


megaDataStore.setBaseParam('task', 'SEARCH');
megaDataStore.setBaseParam('Model', SearchModelComboBox.getValue());Still Firebug insists that the "Model" I've chosen the first time (see the code above) is being transfered a second time, even when changing the value of the combobox and using "setBaseParam" this time around... :((

Maybe I'm using wrong store parameters or combobox settings? As a "plus" it sticks to "LISTING" as the "task" in my datastore. A value that it set up as baseParam when creating the object for the first time.

EDIT: Is there maybe a problem when accessing an object which was created outside a function(){ function(){}} (datastore)?

fay
16 Feb 2010, 8:32 AM
I'm not 100% certain, but I think it is because you are using reload:


Reloads the Record cache from the configured Proxy using the configured Reader and the options from the last load operation performed.

Try:


function listSearch()
{
var lastOptions = megaDataStore.lastOptions;
Ext.apply(lastOptions.params, {
task: 'SEARCH',
Model : SearchModelComboBox.getValue() // Note you had an extra comma here
});

megaDataStore.reload(lastOptions);
}

moonwhaler
16 Feb 2010, 8:44 AM
Yes! This works very well at least as long as I don't do any paging. In this case the "filter" options I selected are gone. Is there any way to permanently save those "filtering options" (to the datastore)?

Thanks a lot for your help!

goldledoigt
16 Feb 2010, 8:54 AM
you should maybe stop to use "reload" store methode. Just use the "load" one.
And for filters, play with params and baseParams.

moonwhaler
17 Feb 2010, 9:59 AM
Which did the trick. Thank you! I'm currently worrying about my "PagingToolbar" which seems to be a little confused by my changed datastore, but I hope to get that fixed soon.

Thanks again everybody!