Hi,
I have to make a grid which refreshes data and column headers by buttons and date-picking.
For the date-picking part, function works fine, but for the button one, the headers don't refresh and the value in the field stays the same. Can somebody help me ? Here's the function on the button for the previous week :
Code:
onBtnSMoinsClick: function(button, e, options) {
var date = Ext.ComponentQuery.query('datefield[itemId="dateS"]')[0];
console.log(date.getValue());
date.setValue(new Date(date.value.getFullYear(), date.value.getMonth(), (parseInt(date.value.getDate(), 10) - 7)));
console.log(date.getValue());
date.fireEvent('select', date, date.getValue());
}
And here is the select event fired :
Code:
onDatefieldSelect: function(field, value, options) {
var headerL = field.up().up().down('gridcolumn[dataIndex="plateauxLundi"]'),
headerM = field.up().up().down('gridcolumn[dataIndex="plateauxMardi"]'),
headerMe = field.up().up().down('gridcolumn[dataIndex="plateauxMercredi"]'),
headerJ = field.up().up().down('gridcolumn[dataIndex="plateauxJeudi"]'),
headerV = field.up().up().down('gridcolumn[dataIndex="plateauxVendredi"]'),
headerS = field.up().up().down('gridcolumn[dataIndex="plateauxSamedi"]'),
headerD = field.up().up().down('gridcolumn[dataIndex="plateauxDimanche"]'),
head = [headerL, headerM, headerMe, headerJ, headerV, headerS, headerD],
jour,
mois,
dt = new Date(value);
// récupération du jour sélectionné (/mois)
var jourMois = dt.getDate();
// récupération de l'indice du jour dans la semaine
var jourSemaine = dt.getDay();
// création d'une date commençant au lundi de la semaine
if(jourSemaine === 0 || jourSemaine === '0') {
jour = jourMois - 7;
} else {
jour = jourMois - jourSemaine + 1;
}
// affectation des dates aux headers
for(var i = 0; i < 7; i++) {
var m = 1;
var d = jour + i;
if(dt.getMonth() === 1 || dt.getMonth() === '1') {
if(dt.isLeapYear() && d > 29) {
d = d - 29;
m = 2;
} else {
if(d > 28) {
d = d - 28;
m = 2;
}
}
} else {
if((dt.getMonth() === 3 || dt.getMonth() === '3' || dt.getMonth() === 5 || dt.getMonth() === '5' || dt.getMonth() === 8 || dt.getMonth() === '8' || dt.getMonth() === 10 || dt.getMonth() === '10') && d > 30) {
d = d - 30;
m = 2;
} else {
if(d > 31) {
d = d - 31;
m = 2;
}
}
}
if(dt.getMonth() + m > 12) {
mois = '01';
} else {
mois = (((dt.getMonth() + m) < 10) ? ('0' + (dt.getMonth() + m)) : (dt.getMonth() + m));
}
head[i].setText(head[i].text.split(' ')[0] + ' ' + d + '/' + mois);
}
Ext.ComponentQuery.query('gridpanel[itemId="grid"]')[0].store.filterBy(function(record) {
var date = record.get('date').split('/');
var semaine = new Date(date[2], (parseInt(date[1]) - 1), date[0]);
semaine = Ext.Date.format(semaine, 'W');
var s = field.getRawValue().split('/')[0];
if(semaine === s) return true;
});
}
The previous one works fine on every call I do, except for the button one.
Here's the beforerender event I use on the datefield, which also calls the function above :
Code:
onDatefieldBeforerender: function(abstractcomponent, options) {
abstractcomponent.setValue(new Date());
abstractcomponent.fireEvent('select', abstractcomponent, abstractcomponent.getValue());
}
Hope you'll understand why it doesn't work especially for the button... Thanks in advance.
[EDIT]
Moreover, it totally blocks me on my work as it is the last point I must get to-work before I can change of subject... So please, help me.