The Ext.NET team is thrilled to announce the official release of Ext.NET 4, including the new Spreadsheet Selection Model, Triton Theme and Advanced Color Picker!

[CLOSED] Disable checkbox for some items in gridpanel with selection model

  1. #1

    [CLOSED] Disable checkbox for some items in gridpanel with selection model

    I would like to disable selection for certain rows based on some condition on gridpanel with checkbox selection model. It will be great if you have both - clientside and serverside example.
    Last edited by Daniil; May 05, 2011 at 1:09 PM. Reason: [CLOSED]
  2. #2
    Hi,

    You can do this by returning false from SelectionModel's BeforeRowSelect listener to cancel selecting.
    Last edited by Daniil; May 04, 2011 at 5:11 PM.
    Daniil Veriga
    Developer & Support Expert
  3. #3
    Quote Originally Posted by Daniil View Post
    Hi,

    You can do this by returning false from SelectionModel's BeforeRowSelect listener to cancel selecting.
    I'm looking to disable it, not to deselect it
  4. #4
    Please investigate the sample.

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                Store store = this.GridPanel1.GetStore();
                store.DataSource = new object[] 
                { 
                    new object[] { "test11", "test12", "test13" },
                    new object[] { "test12", "test22", "test23" },
                    new object[] { "test13", "test32", "test33" }
                };
                store.DataBind();
            }
        }
    </script>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.Net Example</title>
    
        <script type="text/javascript">
            var getRowClass = function (record, index) {
                if (index === 0 || index === 2) {
                    return "my-disabled";
                }
            }
        </script>
    
        <style type="text/css">
            .my-disabled .x-grid3-row-checker {
                filter: alpha(opacity=60);
                opacity: 0.6;
            }
        </style>
    </head>
    <body>
        <form runat="server">
        <ext:ResourceManager runat="server" />
        <ext:GridPanel ID="GridPanel1" runat="server" AutoHeight="true">
            <Store>
                <ext:Store runat="server">
                    <Reader>
                        <ext:ArrayReader>
                            <Fields>
                                <ext:RecordField Name="test1" />
                                <ext:RecordField Name="test2" />
                                <ext:RecordField Name="test3" />
                            </Fields>
                        </ext:ArrayReader>
                    </Reader>
                </ext:Store>
            </Store>
            <ColumnModel runat="server">
                <Columns>
                    <ext:Column Header="Test1" DataIndex="test1" />
                    <ext:Column Header="Test2" DataIndex="test2" />
                    <ext:Column Header="Test3" DataIndex="test3" />
                </Columns>
            </ColumnModel>
            <View>
                <ext:GridView runat="server">
                    <GetRowClass Fn="getRowClass" />
                </ext:GridView>
            </View>
            <SelectionModel>
                <ext:CheckboxSelectionModel runat="server">
                    <Listeners>
                        <BeforeRowSelect Handler="return rowIndex !== 0 && rowIndex !== 2;" />
                    </Listeners>
                </ext:CheckboxSelectionModel>
            </SelectionModel>
        </ext:GridPanel>
        </form>
    </body>
    </html>
    Daniil Veriga
    Developer & Support Expert
  5. #5
    Thanks, it works
  6. #6
    Hi,

    I am searching for a similar solution to use in a Checkbox-Tree.

    The problems is that I do not have any Before-Event which fits to my needs and a View with a Tag like GetRowClass is also not available.

    Any ideas?


    Regards,
    Martin
  7. #7
    Hi,

    Please start a new thread with a link on this thread.
    Daniil Veriga
    Developer & Support Expert
  8. #8
    Here is the update example for v2 (tested with v2.5.1).

    Example
    <%@ Page Language="C#" %>
     
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
     
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                Store store = this.GridPanel1.GetStore();
                store.DataSource = new object[] 
                { 
                    new object[] { "test11", "test12", "test13" },
                    new object[] { "test12", "test22", "test23" },
                    new object[] { "test13", "test32", "test33" }
                };
            }
        }
    </script>
     
    <!DOCTYPE html>
    <html>
    <head runat="server">
        <title>Ext.Net Example</title>
     
        <script>
            var getRowClass = function (record, index) {
                if (index === 0 || index === 2) {
                    return "my-disabled";
                }
            }
        </script>
     
        <style>
            .my-disabled .x-grid-row-checker {
                filter: alpha(opacity=60);
                opacity: 0.6;
            }
        </style>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
    
            <ext:GridPanel ID="GridPanel1" runat="server">
                <Store>
                    <ext:Store runat="server">
                        <Model>
                            <ext:Model runat="server">
                                <Fields>
                                    <ext:ModelField Name="test1" />
                                    <ext:ModelField Name="test2" />
                                    <ext:ModelField Name="test3" />
                                </Fields>
                            </ext:Model>
                        </Model>
                    </ext:Store>
                </Store>
                <ColumnModel runat="server">
                    <Columns>
                        <ext:Column runat="server" Text="Test1" DataIndex="test1" />
                        <ext:Column runat="server" Text="Test2" DataIndex="test2" />
                        <ext:Column runat="server" Text="Test3" DataIndex="test3" />
                    </Columns>
                </ColumnModel>
                <View>
                    <ext:GridView runat="server">
                        <GetRowClass Fn="getRowClass" />
                    </ext:GridView>
                </View>
                <SelectionModel>
                    <ext:CheckboxSelectionModel runat="server">
                        <Listeners>
                            <BeforeSelect Handler="return index !== 0 && index !== 2;" />
                        </Listeners>
                    </ext:CheckboxSelectionModel>
                </SelectionModel>
            </ext:GridPanel>
        </form>
    </body>
    </html>
    Daniil Veriga
    Developer & Support Expert
  9. #9
    Here is a related thread.
    http://forums.ext.net/showthread.php?48961
    Daniil Veriga
    Developer & Support Expert

Similar Threads

  1. Question about Checkbox Selection Model in GridPanel
    By slonati_adv in forum 2.x Help
    Replies: 0
    Last Post: Jul 12, 2012, 2:19 PM
  2. [CLOSED] GridPanel with Checkbox Selection Model
    By rnfigueira in forum 1.x Premium Help
    Replies: 5
    Last Post: May 07, 2012, 2:37 PM
  3. Replies: 2
    Last Post: Dec 07, 2011, 7:00 PM
  4. Replies: 4
    Last Post: Oct 06, 2010, 9:08 AM
  5. [CLOSED] Checkbox Selection Model in GridPanel
    By egodoy in forum 1.x Premium Help
    Replies: 2
    Last Post: Dec 15, 2009, 10:07 AM

Tags for this Thread

Posting Permissions

Subscribe now to get the latest Ext.NET happenings in our newsletter.