Hello! I have little problem with deleting multiple rows from grid panel with checkbox selection model and paging toolbar. Here is code for delete button:
Code:
{
text: 'Delete',
iconCls: 'delete-icon',
handler: function(){
var store = Ext.getStore('ToDos'),
pagingTB = Ext.getCmp('toDoPagingTB'),
list = Ext.getCmp('toDoList'),
selections = list.getSelectionModel().getSelection();
if (selections) {
Ext.MessageBox.confirm('Confirm', 'Are you sure?', function(btn) {
if (btn == 'yes'){
for(var i in selections)
{
store.remove(selections[i]);
store.totalCount--;
}
pagingTB.updateInfo();
}
});
}
}
}
Here is server side code in PHP to retrieve json request and delete sent rows:
PHP Code:
public function actionDelete()
{
if(Yii::app()->request->isAjaxRequest) {
$data = $this->getRequestPayloadData();
$respond['success'] = (ToDo::model()->deleteByPk($data['id'])) ? true : false;
echo json_encode($respond);
}
}
Everything is ok when I want to delete one row. But problem appears when I want to delete more than one row. For example: I want to delete 2 rows so I'm checking two rows... pressing delete button and... only one row is deleted! 2 delete requests were sent with this JSON data:
First request:
{"id":"18","toDo":"Buy sweets","dueDate":"2012-04-25","createdAt":"2012-04-07"}
Response: {"success":true}
So we deleted first checked row... now second request for second row:
Second request:
[{"id":"18","toDo":"Buy sweets","dueDate":"2012-04-25","createdAt":"2012-04-07"},{"id":"17","toDo":"Play Battlefield","dueDate":"2012-04-18","createdAt":"2012-04-07"}]
Response: full of php errors - I know why but I dont know why second request contains deleted row from previous request. Could somebody explain me it? Is it possible to send only one request with all checked rows? Why deleted row is added to next request? Greetings.
Here is code for store:
Code:
Ext.define('ToDo.store.ToDos', {
extend: 'Ext.data.Store',
model: 'ToDo.model.ToDo',
autoSync: true,
pageSize: 25,
autoLoad: {start: 0, limit: this.pageSize},
proxy: {
type: 'ajax',
api: {
read: 'todo/read',
update: 'todo/update',
destroy: 'todo/delete',
create: 'todo/create'
},
reader: {
type: 'json',
root: 'todos',
totalProperty: 'total',
successProperty: 'success'
},
writer: {
type: 'json',
writeAllFields: true,
successProperty: 'success'
},
listeners: {
exception: function(proxy, response, operation){
Ext.MessageBox.show({
title: 'REMOTE EXCEPTION',
msg: 'Error: ' + response.status + '<br />Message: ' + response.statusText,
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.OK
});
}
}
}
});