PDA

View Full Version : Obtaining a Records id Within a Grid?



cluettr
11 Aug 2007, 10:22 AM
I am attempting to update my backend once a cell is edited. While I have the code down I do not have a unique value from the record (the id) to use as an identifier for the update. Yes, I do not know javascript. I'll only claim I do when I don't have to ask anymore questions here : ) BUT... anyways... Here is my code:

My assumption is that I can somehow pull it from the 'record' object. If so, what is the syntax?



grid.on('afteredit', saveCellValue);

function saveCellValue(cell)
{

alert('Field=' + cell.field + "=" + cell.value
+ " | Record =" + cell.record
+ " | Original Value =" + cell.originalValue
+ " | Row =" + cell.row
+ " | Column =" + cell.column
);

var conn = new Ext.data.Connection();
conn.request({
method: 'POST'
, url: 'rma/_scripts/save_grid_rma_details.php'
, params: { action: 'update', field: cell.field, value: cell.value}
});
conn.on('requestcomplete', function(sender, param)
{

});

}

kenITR
11 Aug 2007, 12:18 PM
I'm new to this so there may be a better way, but this works for me:

When you load your datasource, include the row ids from the database, maybe "thingyID", but don't show it in the datacolumn. So, now it won't show on the screen, but it will be in the datasource. Now, when you go to save the cell change, you know what row you are on and that row corresponds to the same row number in the data store where the row ids live.

So in my code that corresponds to your function saveCellValue(cell) I go:


var thingyID = myDatastore.getAt(cell.row).get("thingyID")


and I send the thingyID back to the database with the new value.

You call the object sent by afteredit the "cell" but I think it is actually an event (cbw), and the row is the row number on which the event occurs, so I call it "oGrid_event".

In another thread someone mentioned the issues of filtering and resorting. I don't know if the row number in the grid changes with those reorderings, and that would be something worth while finding out.

cluettr
11 Aug 2007, 4:35 PM
Thanks Ken, your code works. Only issue is I want the 'id' of the datastore rather than a dataIndex. I could add the id as a hidden column but I'm guessing there is an easier way. For example, the id of my XMLReader is below:



reader: new Ext.data.XmlReader({
record: 'Item',
totalRecords: 'TotalResults',
id: 'rma_line_id'
}, [
{name: 'rma_line_number'},
{name: 'rma_shipped_item'},
{name: 'rma_shipped_item_desc'},

kenITR
13 Aug 2007, 10:53 AM
Using the code I showed you are getting the id of the selected row from the datastore. Isn't that what you want?

Meanwhile, I did find that it was slightly easier to make the column hidden and then just go


var thingID = oGrid_event.record.get("thingID")

mystix
13 Aug 2007, 7:09 PM
@cluettr


var theIdYouNeed = yourRecordReference.id;