View Full Version : Want implement Delete button on DataView

7 Jul 2012, 8:02 AM
I want to make delete button, I have such handler:

var selection = Ext.getCmp('peopleView').getSelectionModel().getSelection();
var store = Ext.data.StoreManager.get("PeopleStore");
for (var i = 0; i < selection.length; i++) {
var record = selection[i];

If I select only one item it sends request to my delete page with the record as parameter.
But if i select n items, it sends n requests: first like above, second request contains two, third - three, fourth - four, and so on records as array in parameter, like:
I do not understand why...

7 Jul 2012, 9:02 AM
I do not understand why...

That is that you are telling it to do ... if you look at the 'selection' variable, you will see what is assigned.

getSelectionModel().getSelection()[0]; will select only 1 item .. but your loop then becomes useless.

What is your intent?


7 Jul 2012, 10:53 AM
I don't get why you think so? In my selection I have 3 items in my case:
Every item is a model instance:
But script generate strange requests:
1-st destroy request:
2-nd destroy request:
3-rd destroy request:
As you can see every next request contains all previous data.

7 Jul 2012, 11:26 AM
I understand now .. Since you are removing selected records from the server, why not send all the id's to the server at once and let the server handle the request instead of creating traffic for each remove?

var requests = [],
selRows = listForm.getSelectionModel().getSelection();

for (var i = 0, rec; rec = selRows[i]; i++){
requests.push({ id: selRows[i].data.id_request });

// ajax call to delete all id instead of multiple calls to store.remove
method: 'POST',
url: 'index.php/requests/delete_request/',
params : {
ids: Ext.encode(requests) // list of requests
success: function() {
failure: function() {
alert('AJAX FAILURE: Unable to delete selected requests');


7 Jul 2012, 12:06 PM
Maybe it is some kind of solution, but then why sencha team make api config of AjaxProxy? It is simplier to use unified technique (CRUD as I khow). Maybe I should response some data like {success:true} or destroyed record to destroy request?

7 Jul 2012, 4:06 PM
This is at your discretion. Each have their uses.

For instance your approach will work, but I find it to make better sense to send all the id's in 1 request and let the server do the work, instead of sending each id to the server and creating traffic for each and the server has to handle each as well.


7 Jul 2012, 10:07 PM
But even this did not work! You can see on screenshots.

8 Jul 2012, 10:14 AM
I will need more information .. what did not work? .. are you using you approach, or the alternate approach I provided?

The screenshots were provided before changed approach.

If you used the alternate approach, did you change your server to gather the ids?