PDA

View Full Version : Add another record in a dataStore after first load



Nheil
22 Mar 2011, 9:09 AM
Hi everyone,

i want to add a record in a dataStore.




var stoTicketsActionPublique = new Ext.data.Store({
storeId: 'stoTicketsActionPublique',
url: 'data/incidents/getActionsTicketSuivi.php',
remoteSort: true,
autoLoad: true,
method: 'POST',
baseParams: {
numAppel: numAppel,
typeAction: 1
},
reader:
new Ext.data.JsonReader({
totalProperty: 'total',
root: 'ticket'
},
new Ext.data.Record.create([
{name: 'ComPublic'},
{name: 'DAction'},
{name: 'TypeAction'}


])
),

});



This dataStore is load in a GridPanel.




var grdActionsTickets = new Ext.grid.GridPanel({
id: 'grdActionsTickets',
renderTo: document.getElementById('divcontentProblemeHtml' + numAppel),
ds: stoTicketsActionPublique,
title: 'Action sur votre ticket',
iconCls: 'linkBreak',
loadMask: {showMask: true, msg: 'Chargement en cours...'},
width: 800,
height: 500,
sm: new Ext.grid.RowSelectionModel({ singleSelect: true }),
cm: new Ext.grid.ColumnModel([
{header: "Date de l'Action", dataIndex: 'DAction', width: 100, sortable: true},
{header: "Type de l'Action ", dataIndex: 'TypeAction', width: 148, sortable: true},
{header: 'Commentaire', dataIndex: 'ComPublic', width: 542, sortable: true}
]),
viewConfig: {
// Return CSS class to apply to rows depending upon data values
getRowClass: function(record, index) {
var c = record.get('TypeAction');
if (c == "Mise \u00e0 jour") {
return 'expense-high';
} else{
return 'expense-low';
}
}
}
});



For add another record i use




var Person = Ext.data.Record.create([{
name: 'ComPublic'
}, {
name: 'TypeAction'
}]);
stoTicketsActionPublique.add(new Person({
ComPublic: 'Ned',
TypeAction: 'Flanders'
}));


But this add is loading before the gridPanel store load, and he is overwritted by my dataStore.

fay
22 Mar 2011, 9:29 AM
Add a load event handler to your store (http://dev.sencha.com/deploy/dev/docs/?class=Ext.data.Store) and then do your add:



stoTicketsActionPublique.on('load', function(store, records, options)
{
});

Nheil
23 Mar 2011, 12:04 AM
I make some try about this load, but it doesn't work.
Can you explain explain me how to use it?

Nheil
23 Mar 2011, 12:17 AM
It's ok thanks !!