I want to somehow save "current selected record" in my GridPanel, then i want to delete GridPanel, create it again and set "current selected record" back.
What is the best, or mon way to do this?
PS: or you can answer this, how to select record in GridPanel by record's "id" (for example)
I want to somehow save "current selected record" in my GridPanel, then i want to delete GridPanel, create it again and set "current selected record" back.
What is the best, or mon way to do this?
PS: or you can answer this, how to select record in GridPanel by record's "id" (for example)
Share Improve this question edited Apr 13, 2011 at 10:39 obenjiro asked Apr 13, 2011 at 10:01 obenjiroobenjiro 3,7607 gold badges49 silver badges83 bronze badges 3- why delete the entire gridPanel? Would it not be more effective to store the record in a variable, clear the store and then repopulate the gridStore with that single record? It would probably also require less code. – StevenMcD Commented Apr 13, 2011 at 10:35
- well.. it's just my app requre to do so... i want to delete grid in one place, then create it at another place... but when i do so, i losing my "current selected record".. – obenjiro Commented Apr 13, 2011 at 10:37
- so busicly my app requre to "move" gridPanel from one place to another.. – obenjiro Commented Apr 13, 2011 at 10:38
1 Answer
Reset to default 4The best method I can think of is storing the record in a variable by calling:
var record = gridPanel.getSelectionModel().getSelected();
Recreate your grid whenever it is needed then, assuming the new gridStore structure bound to the new grid is the same as the previous gridStore, you can call:
gridStore.add(record);
That should then add the record to your new store and thus to your new gridPanel. Hope it helps and I hope I understood your question correctly.
EDIT: You can also select the records by calling: gridPanel.store.getById("id");
EDIT2:
So to select a row in a gridPanel based on a record's ID you need to do 2 things.
1) Get the index of the record on the gridPanel:
var recordIndex = gridPanel.store.getIndexById("id");
2) Select the record on the gridPanel using the index:
gridPanel.getSelectionModel().selectRow(recordIndex);