[CLOSED] Pre-Selecting gridpanel checkbox nodes..

  1. #1

    [CLOSED] Pre-Selecting gridpanel checkbox nodes..

    Hi,

    I have a gridpanel on a page that is used to display the roles a user is attached to. I load the roles from Json set in the controller:


            
                            if (ViewBag.Roles != null)
                RolesStore.SetDataFromJson(ViewBag.Roles.ToString());
    What I want to do now is to select the rows that the user is attached to when the page opens. Is there a simple way to do this, perhaps something I can set on the json object? My grid panel and store are below. Thanks

        <ext:Store runat="server" ID="RolesStore" AutoLoad="false">
            <Reader>
               <ext:JsonReader IDProperty="RoleId">
                <Fields>
                    <ext:RecordField Name="RoleId" />
                    <ext:RecordField Name="Name" />
                    <ext:RecordField Name="Description" />
                </Fields>
               </ext:JsonReader>
            </Reader>
        </ext:Store>
    
    <ext:GridPanel 
            ID="RolesList" 
            runat="server" 
            StoreID="RolesStore"
            StripeRows="true"
            AutoExpandColumn="Description">
            <ColumnModel ID="ColumnModel1" runat="server">
                <Columns>
                    <ext:Column ColumnId="Name" Header="Profile" Width="160" DataIndex="Name" Resizable="true" MenuDisabled="true" Fixed="true" />
                    <ext:Column ColumnId="Description" Header="Description" DataIndex="Description" Resizable="true" MenuDisabled="true" Fixed="true" />
                </Columns>
            </ColumnModel>
            <SelectionModel>
                <ext:CheckboxSelectionModel ID="CheckboxSelectionModel1" runat="server" />
            </SelectionModel>
        </ext:GridPanel>
    Last edited by Daniil; Jun 12, 2012 at 9:51 AM. Reason: [CLOSED]
  2. #2
    Hi,

    You should populate the SelectionModel SelectedRows.
  3. #3
    Thanks for the pointer - I was wondering if there was a simpler way.

    For anyone else who wants code, it's pretty much as simple as this code, added to the Page_load:

        IEnumerable<int> userRoles = ViewBag.SelectedRoles;
        foreach (int userRole in userRoles)
        {
            CheckboxSelectionModel1.SelectedRows.Add(new SelectedRow(userRole.ToString()));
        }

Similar Threads

  1. [CLOSED] # Selecting TreePanel Nodes based on Store Values
    By webppl in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Apr 01, 2011, 1:12 PM
  2. TreePanel with Checkbox Enabled Nodes
    By original in forum 1.x Help
    Replies: 1
    Last Post: Nov 03, 2010, 8:26 PM
  3. [CLOSED] [1.0] ColumTree using Checkbox with nodes
    By tansu in forum 1.x Legacy Premium Help
    Replies: 7
    Last Post: Sep 21, 2010, 2:59 PM
  4. [CLOSED] Dynamically create checkbox with AjaxEvent nodes
    By hillscottc in forum 1.x Legacy Premium Help
    Replies: 12
    Last Post: May 14, 2010, 5:33 PM
  5. [CLOSED] pre-selecting gridpanel rows
    By LeeTheGreek in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jan 04, 2010, 7:42 AM

Posting Permissions