[CLOSED] Disabling checkbox grid column cell based on data.

  1. #1

    [CLOSED] Disabling checkbox grid column cell based on data.

    Hi,

    How do you achieve the solution posted on this thread

    http://forums.ext.net/showthread.php...ending-on-data

    for V2. I want to be able to disable some checkboxes (gray it out) based on the data in the record.

    Regards
    Last edited by Daniil; Aug 09, 2012 at 10:26 AM. Reason: [CLOSED]
  2. #2
    Hi,

    Here you are.

    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.Store.Primary;
                store.DataSource = new object[] 
                {
                    new object[] {"non-editable", true },
                    new object[] {"editable", true },
                    new object[] {"non-editable", false },
                    new object[] {"editable", false }
                };
                store.DataBind();
            }
        }
    </script>
     
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <title>Ext.NET v2 Example</title>
     
        <script type="text/javascript">
            var myRenderer = function (value, metadata, record) {
                var cssPrefix = Ext.baseCSSPrefix,
                    cls = [cssPrefix + 'grid-checkheader'],
                    editable = record.get("test1") === "editable";
    
                if (value) {
                    cls.push(cssPrefix + 'grid-checkheader-checked');
                }
    
                if (!editable) {
                    cls.push("checkcolumn-disabled-" + (value ? "checked" : "unchecked"));
                }
    
                return '<div class="' + cls.join(' ') + '">&#160;</div>';
            }
        </script>
     
        <style type="text/css">
            .checkcolumn-disabled-checked {
                background-image: url(resources/images/checked-disabled.gif) !important;
            }
             
            .checkcolumn-disabled-unchecked {
                background-image: url(resources/images/unchecked-disabled.gif) !important;
            }
        </style>
    </head>
    <body>
        <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" />
                            </Fields>
                        </ext:Model>
                    </Model>
                </ext:Store>
            </Store>
            <ColumnModel runat="server">
                <Columns>
                    <ext:Column runat="server" Text="Test1" DataIndex="test1">
                        <Editor>
                            <ext:TextField runat="server" />
                        </Editor>
                    </ext:Column>
                    <ext:CheckColumn
                        runat="server"    
                        ID="CheckColumn1"
                        Text="Checked"
                        DataIndex="test2"
                        Editable="true">
                        <Renderer Fn="myRenderer" />
                    </ext:CheckColumn>
                </Columns>
            </ColumnModel>
            <Plugins>
                <ext:CellEditing runat="server">
                    <Listeners>
                        <BeforeEdit Handler="if ((e.column.id === 'CheckColumn1') &&
                                                 !(e.record.get('test1') === 'editable')) {
                                            
                                                 return false; //to cancel editing          
                                             }"/>
                    </Listeners>
                </ext:CellEditing>
            </Plugins>
        </ext:GridPanel>
    </body>
    </html>
    The images:
    Name:  checked-disabled.gif
Views: 1235
Size:  958 BytesName:  unchecked-disabled.gif
Views: 1247
Size:  923 Bytes
  3. #3
    Thanks that worked

Similar Threads

  1. [CLOSED] Disabling specific Checkboxes ina Checkbox-Tree
    By macap in forum 1.x Legacy Premium Help
    Replies: 6
    Last Post: Nov 07, 2013, 9:37 PM
  2. Replies: 0
    Last Post: Sep 21, 2011, 11:26 PM
  3. [CLOSED] How to check checkbox based on database column value
    By iansriley in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jul 05, 2011, 6:12 PM
  4. Replies: 4
    Last Post: Jun 09, 2011, 3:20 PM
  5. Replies: 3
    Last Post: Nov 19, 2009, 9:17 AM

Tags for this Thread

Posting Permissions