PDA

View Full Version : Related gridPanel showing old data if the store reload data is empty



Sinredux
29 Mar 2013, 7:30 AM
I've got multiple cars in my database, these are shown in my main gridpanel. However, when I click on one of these rows I want to load related data into another gridpanel below. Everything is working fine if the related data exists.
When I click on car which doesn't have any related data, the gridpanel below shows the previously clicked car data instead of going empty. How do I solve this..? Would appreciate it if someone could push me into the right direction :))


My main gridPanel's RowSelectionModel


sm: new Ext.grid.RowSelectionModel(
{
singleSelect: true,
listeners: {
rowselect: function(sm, row, rec)
{
Ext.getCmp("algemeen-form").getForm().loadRecord(rec);
Ext.getCmp("pnlModel").setRawValue(rec.data.model);

if(rec.data.kleur == "Null")
{
Ext.getCmp("pnlKleur").setValue("");
}
if(rec.data.datum_afgifte == "0000-00-00")
{
Ext.getCmp("pnlDatum_afgifte").setValue();
}


var carID = rec.data.id;
var automerkID = rec.data.merkid;


dsGetModel.proxy.setUrl('./data/modules/carpark.php?sort=carpark&action=get-model&automerkid='+automerkID, true);
dsGetModel.load();


dsBestuurder.proxy.setUrl('./data/modules/carpark.php?sort=carpark&action=get-bestuurder&carid='+carID, true);
dsBestuurder.load();


dsSchade.proxy.setUrl('./data/modules/carpark.php?sort=carpark&action=get-schade&carid='+carID, true);
dsSchade.load();


dsAPK.proxy.setUrl('./data/modules/carpark.php?sort=carpark&action=get-apk&carid='+carID, true);
dsAPK.load();


dsOnderhoud.proxy.setUrl('./data/modules/carpark.php?sort=carpark&action=get-onderhoud&carid='+carID, true);
dsOnderhoud.load();


dsBekeuring.proxy.setUrl('./data/modules/carpark.php?sort=carpark&action=get-bekeuring&carid='+carID, true);
dsBekeuring.load();


}
}
}),


Datastore


var dsSchade = new Ext.data.Store(
{
proxy: new Ext.data.HttpProxy(
{
url: './data/modules/carpark.php?sort=carpark&action=get-schade'
}),
remoteSort: true,
autoLoad: true,
reader: new Ext.data.JsonReader(
{
id: 'id'
},
[
{name: 'id'},
{name: 'auto_id'},
{name: 'soort'},
{name: 'documenten'},
{name: 'schadeformulier'},
{name: 'datum'},
{name: 'schadebedrag'},
{name: 'eigen_risico'},
{name: 'notitie'}
])


});


Below's gridPanel


var gridBekeuring = new Ext.grid.GridPanel(
{
border: false,
region: 'center',
store: dsBekeuring,
id: 'bekeuringen',
listeners:
{
viewready: function(g) {
g.getSelectionModel().selectRow(0);
} // Allow rows to be rendered.
},
cm: new Ext.grid.ColumnModel([
{
header: "ID",
width: 45,
sortable: true,
renderer: 'id',
hideable: false,
hidden: true,
dataIndex: 'id'
},
{
header: "Bon nr",
width: 70,
sortable: true,
dataIndex: 'bon_nr',
},
{
header: "auto id",
width: 70,
sortable: true,
dataIndex: 'auto_id',
},
{
header: "Soort bekeuring",
width: 70,
sortable: true,
dataIndex: 'soort',
//name: 'soort_bekeuring'
},
{
header: "Pleegdatum",
width: 70,
sortable: true,
dataIndex: 'pleegdatum'
},
{
header: "Kosten",
width: 70,
sortable: true,
dataIndex: 'kosten'
},
{
header: "Notitie",
width: 70,
sortable: true,
dataIndex: 'notitie'
}
]),
sm: new Ext.grid.RowSelectionModel(
{
singleSelect: true,
listeners: {
rowselect: function(sm, row, rec)
{
//var automerkID = rec.data.merkid;
}
}
}),
viewConfig:
{
autoFill: true,
forceFit: true,
scrollOffset: 0
},
tbar: [
{
id: 'gridBekeuringBtnAdd',
text: 'Toevoegen',
tooltip: 'Toevoegen van een nieuwe bestuurder',
iconCls: 'new',
hidden: false,
disabled: false//,
//handler: carparkAdd
}]
});


Response from empty request: null
Array if there's data: [{"bon_nr":"1","auto_id":"110","auto_soortbekeuring_id":"1","pleegdatum":"2013-04-25","kosten":"300","notitie":"Door rood gereden","soort":"Incidenteel"}]

willigogs
29 Mar 2013, 7:54 AM
You would need to return an empty array instead of your null value :)

Alternatively, detect the null being received, then load an empty array into the store.

Sinredux
2 Apr 2013, 12:17 AM
Detecting if the array is equal to null, and sending an empty array instead did the trick.

Thanks a lot :)