I. Explications▲
Voici une fonction pour concaténer les valeurs d'un champ dans un store. Cette fonction est similaire à la fonction Store.sum();.
Ext.data.Store.override({
concat: function(field, grouped, separator){
if(typeof separator === 'undefined'){
separator = ', ';
}
if (grouped && this.isGrouped()) {
return this.aggregate(this.getConcat, this, true, [field, separator]);
} else {
return this.getConcat(this.data.items, field, separator);
}
},
getConcat: function(records, field, separator){
var result = [];
var i = 0;
var len = records.length;
for(; i < len; ++i){
result.push(records[i].get(field));
}
return result.join(separator);
}
});
Par exemple, si le store a le champ email et qu'il contient les valeurs 'a@b.ca' et 'b@c.com', alors store.concat('email') va retourner 'a@b.ca, b@c.com'.
II. Remerciements▲
Cet article a été publié avec l'aimable autorisation de Neil McGuigan. L'article original peut être lu sur le blog ExtJS TutorialsExtJS Tutorials : A function to concatenate field values in a storeA function to concatenate field values in a store.
Je remercie également ClaudeLELOUP pour sa relecture attentive.




