PDA

View Full Version : how can i access to information in Grid ?



masoud_tamizy
21 Jan 2012, 7:35 AM
how can i access a selected row of a Grid ? what method or property ?

vietits
21 Jan 2012, 7:44 AM
Use <grid>.getSelectionModel().getSelection(). This will return an array of selected rows (or records) on the grid.

skirtle
21 Jan 2012, 8:28 AM
Or if you only want a single row you could use getLastSelected.

masoud_tamizy
21 Jan 2012, 8:42 AM
Use <grid>.getSelectionModel().getSelection(). This will return an array of selected rows (or records) on the grid.
please explain for me more ... . how obtain a cell value ?

skirtle
21 Jan 2012, 9:30 AM
Once you have the record for the row you can grab the cell value using the get method:


record.get('myfield');

Here the field name is myfield and that would tie up with the dataIndex of the column for the cell you want.

masoud_tamizy
21 Jan 2012, 11:27 PM
tnx my friend , it fixes by this :
var rec = grid.getSelectionModel().getSelection()[0];
and
rec.get('last_name')

and a new question ???
now i needed it for update & delete operations instead of CRUD .
do you know how can i do CRUD as simple way with ajax ?
my code is in following post :
http://www.sencha.com/forum/showthread.php?175208-I-encounterde-this-error-on-loading-data-from-server-to-a-grid
(http://www.sencha.com/forum/showthread.php?175208-I-encounterde-this-error-on-loading-data-from-server-to-a-grid)but with some changes (will mention below):
api:{
read : 'prepare.php',
delete : 'delete.php'
}
but i don't know how can i do for delete or update operations !!!

skirtle
21 Jan 2012, 11:27 PM
Assuming you are using a row selection model the listeners would be:


select: function(rowModel, record) {
var code = record.get('national_code');
...
}

or:


selectionchange: function(rowModel, records) {
// records may contains multiple records, or even no records at all
var record = records[0];

if (record) {
var code = record.get('national_code');
...
}
}

These could be added to the grid or the selection model itself.

skirtle
21 Jan 2012, 11:47 PM
For anyone else reading this thread, it should be noted that my previous post was in response to another post that has subsequently been deleted.

I advise asking your new question as a separate thread. This is a Q&A forum, you can think of it like Stack Overflow. Once you get an answer you're happy with you should mark it as the best answer (there's a link on each post). Separate questions need to be asked as separate threads for this to work. You'll also find that more people read your question if you post it as a new thread.

masoud_tamizy
22 Jan 2012, 12:03 AM
For anyone else reading this thread, it should be noted that my previous post was in response to another post that has subsequently been deleted.

I advise asking your new question as a separate thread. This is a Q&A forum, you can think of it like Stack Overflow. Once you get an answer you're happy with you should mark it as the best answer (there's a link on each post). Separate questions need to be asked as separate threads for this to work. You'll also find that more people read your question if you post it as a new thread.
yes ok