sunmoonone
28 Jan 2010, 7:09 PM
Ext version tested:
Ext 3.1.0 (rev 5770-119)
Adapter used:
ext
Browser versions tested against:
FF3 (firebug 1.3.0.10 installed)
Operating System:
ubuntu linux 9.04
Description:
I use the save method of store to save changes in a
grid(create,update,destroy). And If the save is successful in the
server I want to pop up a message box to show the number of records
saved for the corresponding actions. I find the 'write' event can meet
this requirement.
But the length of the 5th param rs always is 0 when more than one rows has been saved(created updated or destroyed).
Here is the doc of the 'write' event:
* @event write
* Fires if the server returns 200 after an Ext.data.Api.actions CRUD action.
* Success of the action is determined in the result['successProperty']property (NOTE for RESTful stores,
* a simple 20x response is sufficient for the actions
"destroy" and "update". The "create" action should should return 200
along with a database pk).
* @param {Ext.data.Store} store
* @param {String} action [Ext.data.Api.actions.create|update|destroy]
* @param {Object} result The 'data' picked-out out of the response for convenience.
* @param {Ext.Direct.Transaction} res
* @param {Record/Record[]} rs Store's records, the subject(s) of the write-action
*/
'write',
""" @param {Record/Record[]} rs Store's records, the subject(s) of the write-action""".
I think it means when 5 rows's been destroyed then rs.length should be 5, but I always got 0 instead.
I think it is a bug!!
Test Case:
Ext.ns("Eos.ux");
/**
* @class Eos.ux.SimpleStore
* @extends Ext.data.Store
* Simple store class
*
* @cfg {Object} api containing urls for CRUD( read,create,update,destroy)
* <pre>eg:
* api:{C:'/create/',R:'/read/'}
* </pre>
* @cfg {Array} fields
* @cfg {String} totalProperty default is 'total'
* @cfg {String} root default is 'data'
* @cfg {String} id default is 'id'
*/
Eos.ux.EditableStore=Ext.extend(Ext.data.Store,{
listeners:{
write:function(s,action,ret_data,response,rs){
title='save';
if (action=='update')
title='update';
if (action=='destroy')
title='delete';
Ext.Msg.alert(title,rs.length||1+" records");
}
},
constructor:function(config){
config.proxy = new Ext.data.HttpProxy({
api:{
read:api.R,
create:api.C,
update:api.U,
destroy:api.D
},
listeners:{
exception:function(){
}
}
});
config.reader = new Ext.data.JsonReader({
totalProperty :'total',
root :'data',
id : 'id'
}, config.fields);
delete config.fields;
Eos.ux.SimpleStore.superclass.constructor.call(this, config);
}
});
var sm = new Ext.grid.CheckboxSelectionModel({
singleSelect : false,
checkOnly : true
});
var cm = [new Ext.grid.RowNumberer(), sm, {
header : "id",
hidden : true,
sortable : false,
dataIndex : "id",
width : 80
},{
header : "name",
editor : new Ext.form.TextField({
width : 200,
allowBlank : false,
maxLength : 255
}),
sortable : false,
dataIndex : "name",
width : 200
}, {
header : "type",
editor : new Ext.form.TextField({
width:90
}),
sortable : false,
dataIndex : "type_",
width : 80
}, {
header : "start",
editor : new Ext.form.DateField({
width : 180,
allowBlank : false,
value:new Date(),
format:'Y-m-d'
}),
sortable : false,
dataIndex : "start",
width : 180
}, {
header : "end",
editor : new Ext.form.DateField({
width : 180,
allowBlank : false,
value:new Date(),
format:'Y-m-d'
}),
sortable : false,
dataIndex : "end",
width : 180
}, {
header : "top",
sortable : false,
dataIndex : "top",
width : 80,
editor : new Ext.form.TextField({
width : 80,
allowBlank : true
})
}, {
header : "online",
sortable : false,
dataIndex : "online",
width : 80,
editor : new Ext.form.TextField({
width : 80,
allowBlank : true
})
}, {
header : "create time",
sortable : false,
dataIndex : "cTime",
width : 180
}];
var store = new Eos.ux.EditableStore({
writer : new Ext.data.JsonWriter({
encode : true
}),
sortInfo : {
field : "cTime",
direction : "DESC"
},
fields : [{
name : "end",
allowBlank : false
}, {
name : "name",
allowBlank : false
}, {
name : "top"
}, {
name : "start",
allowBlank : false
}, {
name : "type_",
allowBlank : false
}, {
name : "online"
}, {
name : "id"
}, {
name : "cTime"
}],
baseParams : {
table : "ManualProgram"
},
batch : true,
autoSave : false,
api : {
C : "/url_for_creat/",
R : "/url_for_query/",
U : "/url_for_update/",
D : "/url_for_destroy/"
},
restful : false
});
var grid = new Ext.grid.EditorGridPanel({
clicksToEdit : 1,
stripeRows : true,
store : store,
sm : sm,
autoScroll : true,
loadMask : true,
columns : cm
});
//this is the main window
var main_pane = new Ext.Panel({
tbar : [{
text : "add",
handler : function() {
try {
var row_index = -1;
var grid = this._grid;
var RecCls = grid.getStore().recordType;
var p = new RecCls({
top : false,
online : false
// cTime : Eos.common.now()
});
grid.stopEditing();
// store.insert(0, p);
store.add(p);
row_index++;
grid.startEditing(row_index, 1);
} catch (err) {
alert('adding error ' + error);
}
}
}, {
text : "delete",
handler : function(store) {
grid.stopEditing();
var recs = grid.getSelectionModel().getSelections();
if (!recs || recs.length < 1)
Ext.Msg.alert('info', 'select row(s) to delete');
else {
for (var i = 0; i < recs.length; i++) {
store.remove(recs[i]);
}
}
}
}, "-", {
text : "save",
handler : function(store) {
try {
var r = store.save();
if (r == -1) {
if (store.getModifiedRecords().length)
Ext.Msg.alert('warning', 'some input is invalid');
else if (!store.removed.length)
Eos.Msg.alert('info', 'no need for saving');
}
} catch (err) {
alert('save error: ' + err);
}
}
}],
autoScroll : true,
items : grid,
layout : "fit"
});
Steps to reproduce the problem:
CUD more than ones rows then click the 'save' button
The result that was expected:
if action is "create": a message box popup with message:create {number} records
if action is "update": a message box popup with message:update {number} records
if action is "destroy": a message box popup with message:delete {number} records
The result that occurs instead:
number in {number} is 1 all the time
Ext 3.1.0 (rev 5770-119)
Adapter used:
ext
Browser versions tested against:
FF3 (firebug 1.3.0.10 installed)
Operating System:
ubuntu linux 9.04
Description:
I use the save method of store to save changes in a
grid(create,update,destroy). And If the save is successful in the
server I want to pop up a message box to show the number of records
saved for the corresponding actions. I find the 'write' event can meet
this requirement.
But the length of the 5th param rs always is 0 when more than one rows has been saved(created updated or destroyed).
Here is the doc of the 'write' event:
* @event write
* Fires if the server returns 200 after an Ext.data.Api.actions CRUD action.
* Success of the action is determined in the result['successProperty']property (NOTE for RESTful stores,
* a simple 20x response is sufficient for the actions
"destroy" and "update". The "create" action should should return 200
along with a database pk).
* @param {Ext.data.Store} store
* @param {String} action [Ext.data.Api.actions.create|update|destroy]
* @param {Object} result The 'data' picked-out out of the response for convenience.
* @param {Ext.Direct.Transaction} res
* @param {Record/Record[]} rs Store's records, the subject(s) of the write-action
*/
'write',
""" @param {Record/Record[]} rs Store's records, the subject(s) of the write-action""".
I think it means when 5 rows's been destroyed then rs.length should be 5, but I always got 0 instead.
I think it is a bug!!
Test Case:
Ext.ns("Eos.ux");
/**
* @class Eos.ux.SimpleStore
* @extends Ext.data.Store
* Simple store class
*
* @cfg {Object} api containing urls for CRUD( read,create,update,destroy)
* <pre>eg:
* api:{C:'/create/',R:'/read/'}
* </pre>
* @cfg {Array} fields
* @cfg {String} totalProperty default is 'total'
* @cfg {String} root default is 'data'
* @cfg {String} id default is 'id'
*/
Eos.ux.EditableStore=Ext.extend(Ext.data.Store,{
listeners:{
write:function(s,action,ret_data,response,rs){
title='save';
if (action=='update')
title='update';
if (action=='destroy')
title='delete';
Ext.Msg.alert(title,rs.length||1+" records");
}
},
constructor:function(config){
config.proxy = new Ext.data.HttpProxy({
api:{
read:api.R,
create:api.C,
update:api.U,
destroy:api.D
},
listeners:{
exception:function(){
}
}
});
config.reader = new Ext.data.JsonReader({
totalProperty :'total',
root :'data',
id : 'id'
}, config.fields);
delete config.fields;
Eos.ux.SimpleStore.superclass.constructor.call(this, config);
}
});
var sm = new Ext.grid.CheckboxSelectionModel({
singleSelect : false,
checkOnly : true
});
var cm = [new Ext.grid.RowNumberer(), sm, {
header : "id",
hidden : true,
sortable : false,
dataIndex : "id",
width : 80
},{
header : "name",
editor : new Ext.form.TextField({
width : 200,
allowBlank : false,
maxLength : 255
}),
sortable : false,
dataIndex : "name",
width : 200
}, {
header : "type",
editor : new Ext.form.TextField({
width:90
}),
sortable : false,
dataIndex : "type_",
width : 80
}, {
header : "start",
editor : new Ext.form.DateField({
width : 180,
allowBlank : false,
value:new Date(),
format:'Y-m-d'
}),
sortable : false,
dataIndex : "start",
width : 180
}, {
header : "end",
editor : new Ext.form.DateField({
width : 180,
allowBlank : false,
value:new Date(),
format:'Y-m-d'
}),
sortable : false,
dataIndex : "end",
width : 180
}, {
header : "top",
sortable : false,
dataIndex : "top",
width : 80,
editor : new Ext.form.TextField({
width : 80,
allowBlank : true
})
}, {
header : "online",
sortable : false,
dataIndex : "online",
width : 80,
editor : new Ext.form.TextField({
width : 80,
allowBlank : true
})
}, {
header : "create time",
sortable : false,
dataIndex : "cTime",
width : 180
}];
var store = new Eos.ux.EditableStore({
writer : new Ext.data.JsonWriter({
encode : true
}),
sortInfo : {
field : "cTime",
direction : "DESC"
},
fields : [{
name : "end",
allowBlank : false
}, {
name : "name",
allowBlank : false
}, {
name : "top"
}, {
name : "start",
allowBlank : false
}, {
name : "type_",
allowBlank : false
}, {
name : "online"
}, {
name : "id"
}, {
name : "cTime"
}],
baseParams : {
table : "ManualProgram"
},
batch : true,
autoSave : false,
api : {
C : "/url_for_creat/",
R : "/url_for_query/",
U : "/url_for_update/",
D : "/url_for_destroy/"
},
restful : false
});
var grid = new Ext.grid.EditorGridPanel({
clicksToEdit : 1,
stripeRows : true,
store : store,
sm : sm,
autoScroll : true,
loadMask : true,
columns : cm
});
//this is the main window
var main_pane = new Ext.Panel({
tbar : [{
text : "add",
handler : function() {
try {
var row_index = -1;
var grid = this._grid;
var RecCls = grid.getStore().recordType;
var p = new RecCls({
top : false,
online : false
// cTime : Eos.common.now()
});
grid.stopEditing();
// store.insert(0, p);
store.add(p);
row_index++;
grid.startEditing(row_index, 1);
} catch (err) {
alert('adding error ' + error);
}
}
}, {
text : "delete",
handler : function(store) {
grid.stopEditing();
var recs = grid.getSelectionModel().getSelections();
if (!recs || recs.length < 1)
Ext.Msg.alert('info', 'select row(s) to delete');
else {
for (var i = 0; i < recs.length; i++) {
store.remove(recs[i]);
}
}
}
}, "-", {
text : "save",
handler : function(store) {
try {
var r = store.save();
if (r == -1) {
if (store.getModifiedRecords().length)
Ext.Msg.alert('warning', 'some input is invalid');
else if (!store.removed.length)
Eos.Msg.alert('info', 'no need for saving');
}
} catch (err) {
alert('save error: ' + err);
}
}
}],
autoScroll : true,
items : grid,
layout : "fit"
});
Steps to reproduce the problem:
CUD more than ones rows then click the 'save' button
The result that was expected:
if action is "create": a message box popup with message:create {number} records
if action is "update": a message box popup with message:update {number} records
if action is "destroy": a message box popup with message:delete {number} records
The result that occurs instead:
number in {number} is 1 all the time