-
25 Mar 2011 8:43 AM #1
pre-selection grid checkbox
pre-selection grid checkbox
Hello,
I'm trying to pre-select some rows in a grid when it is rendered.
This is a simple GridPanel with a JsonStore an a local array data source.
No matter what I try, I can't pre-select rows.
Actually, I can set rows as selected in the CheckboxSelectionModel but the view isn't updated.
If I just trigger the view.refresh() method after a short while, then I see the right checked items.
So it's as if there where a synchronization problem, or I don't use the right event.
But until now, I'm stuck ...
Any hint is welcome.
Thanks.
-
25 Mar 2011 8:59 AM #2
can we see some code? Are you using the RowSelectionModel methods to select???
Can't help much till we see something------------------------------------------
Conor Armstrong
tw: @evathedog
web: rockstown.com
Ext.ux.form.AutoCombo
Ext.ux.SimpleIFrame
Ext.ux.form.ToolFieldSet
Knowledge is realising that the street is one-way, wisdom is looking both directions anyway.
-
27 Mar 2011 11:48 PM #3
Here's a piece of code showing the issue :
When the window opens, record 2 and 3 should be checked but no matter they are set as selected in the SelectionModel, they are not checked.Code:var MyGrid = Ext.extend(Ext.grid.GridPanel, { initComponent: function() { this.store = new Ext.data.JsonStore({ autoDestroy: true, storId: 'testStoreId', fields: ['id', 'name'] }); this.selModel = new Ext.grid.CheckboxSelectionModel(); this.colModel = new Ext.grid.ColumnModel({ defaults: { sortable: true }, columns : [{ header: 'id', dataIndex: 'id', hidden: true }, { header: 'Name', dataIndex: 'name', width: 100 }, this.selModel] }); this.viewConfig = { forceFit: true, scrollOffset: 18 }; this.buttons = [{ text : 'Force Refresh', handler: this.btnRefresh_click, scope: this }]; this.store.on('load', function(store, record){ // pre-select records this.getSelectionModel().selectRecords([store.getAt(1)], true); this.getSelectionModel().selectRecords([store.getAt(2)], true); this.getView().refresh(); }, this); MyGrid.superclass.initComponent.call(this); this.on('afterrender', function(){ this.store.loadData([{ id: '1', name: 'item 1' }, { id: '2', name: 'item 2' }, { id: '3', name: 'item 3' }, { id: '4', name: 'item 4' }, { id: '5', name: 'item 5' }]); }, this); }, btnRefresh_click: function(btn, evt) { this.getView().refresh(); } }); Ext.onReady(function(){ new Ext.Window({ title: 'testWindow', width: 350, height: 200, layout: 'fit', items: [{ xtype: 'tabpanel', activeItem: 0, items: [new MyGrid({ title: 'MyGrid Panel', layout: 'fit', width: 'auto' })] }] }).show(); });
If you click the button, it will just call refresh() on the view and the checked lines will turn on.
I would like that those lines would automatically be checked without this "refresh" button I added.Last edited by Ghurdyl; 28 Mar 2011 at 3:26 AM. Reason: spelling
-
30 Mar 2011 2:14 AM #4
-
30 Mar 2011 2:36 AM #5
I think you've got to put your logic into the grid's viewready event:
Code:this.on('viewready', function(grid){ this.getSelectionModel().selectRows([1,2], true); }
-
30 Mar 2011 3:21 AM #6
Similar Threads
-
How to use a checkbox in a grid? not for row selection
By zhenyuandeng in forum Ext 2.x: Help & DiscussionReplies: 4Last Post: 29 Jan 2010, 11:29 PM -
Grid+CheckBox -- Not for selection
By rvent in forum Ext 2.x: Help & DiscussionReplies: 5Last Post: 25 Jun 2008, 10:01 AM -
Checkbox Selection Grid help
By Amberite in forum Ext 2.x: Help & DiscussionReplies: 3Last Post: 24 Jun 2008, 4:35 PM


Reply With Quote
