PDA

View Full Version : Best way to handle removal of rows in a grid



omermx
17 Nov 2009, 3:55 AM
Hi, just wanted some advice/best practice to handle the follwing scenario:

I have a list of customers presented to the user in a grid, there is a button that allows the user to remove a customer from the list i.e. remove a record from the store and update the grid.

I've been playing around with HttpProxy and CRUD actions, it only seems to fire an update action when I change something in one of the rows. I would have expected removing a record from the store to trigger an update action but it doesn't.

In the end I need the user to be able to make any changes needed on the list e.g. remove a customer, then pass the updated list back to the server for processing.

So...

1. What is the best way to handle the store behind the grid? Can I let the user make changes to the store (via the grid UI) and then pass the store object to the server e.g. do a json_decode() at the server side in PHP?

2. Is there some way to make the removal of a record from the store and hence the grid, a CRUD action?

Any suggestions appreciated!!

jay@moduscreate.com
17 Nov 2009, 4:55 AM
store.removeAll()

omermx
17 Nov 2009, 5:31 AM
Hi, I tried store.removeAll(), but it does not trigger a CRUD action (i.e. request I can see in Firebug) if that's what you meant.

Some code snippets for clarity:

My proxy as configured as below, the read page supplies some dummy data to populate the store/grid, the others just return a JSON success response, I'm only interested in what's being sent to the server at the moment.



var proxy = new Ext.data.HttpProxy({
api: {
read:'test_read.php',
create: 'test_create.php',
update:'test_update.php',
destroy: 'test_destroy.php'
}


This is how my store is configured



var store = new Ext.data.JsonStore({
// store configs
autoDestroy: true,
autoSave:true,
proxy:proxy,
writer:writer,
storeId: 'myStore',
root: 'data',
totalProperty: 'totalCount',
idProperty: 'cust_id',
fields:[
{name: 'cust_id'},
{name: 'title'},
{name: 'forename'},
{name: 'surname'},
{name: 'address_1'},
...etc.
]
});

Mike Robinson
17 Nov 2009, 9:24 AM
If your JSONStore has a properly-configured JSONWriter associated with it, the Store will automagically generate CRUD requests to correspond with whatever changes have been made to the Store's record-set.

If a Writer object does not exist, only "R"ead requests will be issued.