PDA

View Full Version : [Solved] Data store records change after array population



paulyb263
15 Dec 2009, 4:04 AM
Hello all, I have tried to resist posting here for as long as possible, but I am now at a point where i feel I am getting nowhere with this problem. My situation is this:-

I have a grid that has a data store that has a JSON reader and gets its records from a .NET handler. Store has autoload set to true, all records load and grid renders fine. So far so good.

I also have a DatePickerPlus calendar which has some event dates set, these event dates come from dates in the data store, now to get these dates into the calendar object I populate an array with the dates from the store, then pass the array to setEventDates. This is where the problems start. Once I have populated the array with the dates from the store the store's records change from record objects to dates (if that makes sense). I have posted the code below and also attached 2 images, one of how the data store should be, another how it looks after population of array.

Any help would be greatly appreciated thanks.





var courseScheduleProx = new Ext.data.HttpProxy({
url: 'courseScheduleGridHandler.ashx' // File to connect to
,
method: 'POST'
})
var courseScheduleJsonReader = new Ext.data.JsonReader({
fields: [{
name: 'programmeID'
},
{
name: 'dateFrom',
convert: dotNetconvertDate,
dateFormat: 'd/m/Y'
},
{
name: 'dateTo',
convert: dotNetconvertDate,
dateFormat: 'd/m/Y'
},
{
name: 'tutor_lookup'
}

,
{
name: 'maxNo'
},
{
name: 'Hrs'
}],
id: 'programmeID',
totalProperty: 'recordCount',
root: 'courseScheduleList'
})
courseScheduleStore = new Ext.data.Store({
id: 'courseScheduleStore',
proxy: courseScheduleProx,
autoLoad: true,
baseParams: {
courseID: courseID,
parameter: 'blank',
pageSize: pageSize
},
description: 'This store contains values from tblCourseProgrammes',
reader: courseScheduleJsonReader,
sortInfo: {
field: 'dateFrom',
direction: 'ASC'
},
remoteSort: false

});

courseScheduleStore.on('load', function (e, o) {
var scheduleDatesArray = eval(courseScheduleStore.data.items)
for (i = 0; i < scheduleDatesArray.length; i++) {
scheduleDatesArray[i] = courseScheduleStore.data.items[i].data.dateFrom
}
courseScheduleCalendar.setEventDates(scheduleDatesArray);
});

NicoCipo
15 Dec 2009, 4:47 AM
Please try replacing



courseScheduleStore.on('load',function(e,o){
var scheduleDatesArray = eval(courseScheduleStore.data.items)
for(i=0; i < scheduleDatesArray.length ; i++)
{
scheduleDatesArray[i] = courseScheduleStore.data.items[i].data.dateFrom
}
courseScheduleCalendar.setEventDates(scheduleDatesArray);
});


with



courseScheduleStore.on('load',function(store, records){
var scheduleDatesArray = [];
store.each(function(record) {
scheduleDatesArray.push(record.get('dateFrom'));
});
courseScheduleCalendar.setEventDates(scheduleDatesArray);
});


Hope it works!

Regards,
Nicolás

paulyb263
15 Dec 2009, 5:11 AM
Excellent that worked a treat thanks! :)

I still dont really understand why my code was causing the data stores records to change like that.. maybe I should do a bit more reading up on the data store API.


P.S. I also just got it working with:-



courseScheduleStore.on('load',function(store,records){
var scheduleDatesArray = [];
var reader = this.reader;
var jsonData = reader.jsonData;
jsonData.each(function(courseScheduleList) {
scheduleDatesArray.push(courseScheduleList.get('dateFrom'));
});
courseScheduleCalendar.setEventDates(scheduleDatesArray);
{);


But yours looks neater :)


Please try replacing



courseScheduleStore.on('load',function(e,o){
var scheduleDatesArray = eval(courseScheduleStore.data.items)
for(i=0; i < scheduleDatesArray.length ; i++)
{
scheduleDatesArray[i] = courseScheduleStore.data.items[i].data.dateFrom
}
courseScheduleCalendar.setEventDates(scheduleDatesArray);
});


with



courseScheduleStore.on('load',function(store, records){
var scheduleDatesArray = [];
store.each(function(record) {
scheduleDatesArray.push(record.get('dateFrom'));
});
courseScheduleCalendar.setEventDates(scheduleDatesArray);
});


Hope it works!

Regards,
Nicolás