PDA

View Full Version : list panel , pb on dataChange



tonin10
26 Feb 2011, 5:13 AM
Hello,
i have a curious thing with listPanel

when i add data with a form, my list is updated but no sort( when i load my app, all work fine, data is sort by date DESC) like i want and when you scroll, the header in blue goes below the one above?
do you have a idear of the pb ?

i try to refresh, destroy and render but nothing works :-?


template_route = new Ext.XTemplate(

'<strong>{date} / </strong>{depart} - {arrivee} : {distance} km'

);



historiquePanel = new Ext.List({
iconCls: 'bookmarks',
id:"historique_panel",
title: 'Historique',
store: dataRoute,
itemTpl : '<strong>{date} / </strong>{depart} - {arrivee} : {distance} km' ,
grouped:true ,
scroll:'vertical',
listeners: {
beforeshow :{
fn: function(){ console.log('BEFORESHOW');

}

}
}



});


and data


Ext.regModel('trajet',{
fields : [{name : 'id', type : 'int'},
{name : 'date', type : 'string'},
{name : 'depart', type : 'string'},
{name : 'arrivee', type : 'string'},
{name : 'distance', type : 'number'},
{name : 'note', type : 'string'}
],
proxy: {
type: 'localstorage',
id : 'bdd_route'
}
});


dataRoute = new Ext.data.Store({
model: 'trajet',
autoLoad:true,
//storeId: 'routeData' ,
sorters: [{property : 'date',
direction: 'DESC'}],
getGroupString : function(record) {
var mois = record.get('date').substr(0,7);
var distance = getTotalDistance(mois);
return mois +' total : '+distance +' km';
}


});


insertDataRoute = function(data)
{
dt = data.date;
data.date = data.date.format('Y-m-d');
dataRoute.create(data);
dataRoute.sync();

}


getTotalDistance =function(mois)
{
var amount = 0;
var search = new RegExp(mois);
dataRoute.each(function(record){
var value = record.get('date');
if(value.match(search)){
amount += record.get('distance');
}
});

return amount
}

dataRoute.load();


thanks for your helps

tonin10
27 Feb 2011, 1:03 AM
Hello
Ok, i found why i have this bug. It s my function to calcul distance in getGRoupString. If i delete it, all works fine. but how to solve the problem, the mystery remains unsolved.......:)
Thank you for your help

tonin10
27 Feb 2011, 2:13 AM
oups no, it's not that. I try again, and the curious things, when i add my first data, its work, and on the second, nothing work.... i try to find what i do wrong

tonin10
28 Feb 2011, 5:05 AM
hello,
nobody have see this problem? i search but don't find. Destroy list and render etc... nothing works :-?

tonin10
28 Feb 2011, 6:13 AM
i've got it !
with my data


insertDataRoute = function(data)
{
dt = data.date;
data.date = data.date.format('Y-m-d');
dataRoute.add(data);
dataRoute.sync();
var panel = Ext.getCmp("historique_panel")

appRoute.setActiveItem(3);
dataRoute.sort();
panel.refresh();
}


it's strange because i try in the listener beforeshow to refresh the data and panel by without result and the same thing in the listener itemtap works/:)


made with twitter exemple (thanks for all share exemple, whitout i totaly lost)


itemtap:function(conteneur, index,item, e) {
activeCls = this.activeCls;
var store = this.store;

if (e.getTarget ('.' + activeCls + ' div.delete')) {
console.log("index:"+index)

selModel = this.getSelectionModel();
instance = store.getAt(index);
selected = selModel.isSelected(instance);
nearest = store.getAt(index + 1) || store.getAt(index - 1);

//if the item we are removing is currently selected, select the nearest item instead
if (selected && nearest) {
selModel.select(nearest);
}

store.removeAt(index);
store.sync();

//there were no other searches left so tell the user about that
if (!nearest) {
//Ext.redirect('searches/first');
}
} else {
this.deactivateAll();

//return twitter.views.Searches.superclass.onItemTap.apply(this, arguments);
}
}