[CLOSED] Checkbox Column header in GridPanel

  1. #1

    [CLOSED] Checkbox Column header in GridPanel

    Hi,

    Could you please provide us for sample of Checkbox column header in Gridpanel. It means all column header will have checkbox which will use some javascript function

    Please see the attached image
    Click image for larger version. 

Name:	grid.jpg 
Views:	882 
Size:	25.7 KB 
ID:	2709

    Thanks & Regards,

    Rameshkumar.T
    Last edited by Daniil; May 17, 2011 at 2:04 PM. Reason: [CLOSED]
  2. #2
    Hi,

    Unfortunately, such behavior is not supported. The best thing we can do at this moment - create a feature request ticket to review/implement in the future realizes.

    For now, I can provide you with the following example. In general, it works, but not fully tested. So, it can be broken in some cases.

    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>
        <ext:ResourcePlaceHolder runat="server" />
    
        <script type="text/javascript">
            Ext.grid.GridView.override({
                renderHeaders : function () {
                    var colModel = this.cm,
                        templates = this.templates,
                        headerTpl = templates.hcell,
                        properties = {},
                        colCount = colModel.getColumnCount(),
                        last = colCount - 1,
                        cells = [],
                        i, 
                        cssCls;
    
                    for (i = 0; i < colCount; i++) {
                        if (i == 0) {
                            cssCls = 'x-grid3-cell-first ';
                        } else {
                            cssCls = i == last ? 'x-grid3-cell-last ' : '';
                        }
    
                        properties = {
                            id : colModel.getColumnId(i),
                            value : colModel.getColumnHeader(i) || '',
                            style : this.getColumnStyle(i, true),
                            css : cssCls,
                            tooltip : this.getColumnTooltip(i),
                            checked : this.checkboxes["my-header-checkbox-" + colModel.getColumnId(i)] //added
                        };
    
                        if (colModel.config[i].align == 'right') {
                            properties.istyle = 'padding-right: 16px;';
                        } else {
                            delete properties.istyle;
                        }
    
                        cells[i] = headerTpl.apply(properties);
                    }
    
                    return templates.header.apply({
                        cells: cells.join(""),
                        tstyle: String.format("width: {0};", this.getTotalWidth())
                    });
                },
                
                onHeaderClick : function (g, index) {
                    if (Ext.fly(Ext.EventObject.getTarget()).hasClass('my-header-checkbox')) {  //added
                        return;                                                                 //added
                    }                                                                           //added
                
                    if (this.headersDisabled || !this.cm.isSortable(index)) {
                        return;
                    }
                    
                    g.stopEditing(true);
                    g.store.sort(this.cm.getDataIndex(index));
                }
            });
        </script>
    
        <script type="text/javascript">
            var getTemplates = function() {
                return {
                    hcell: new Ext.Template(
                            '<td class="x-grid3-hd x-grid3-cell x-grid3-td-{id} {css}" style="{style}">',
                                '<div {tooltip} {attr} class="x-grid3-hd-inner x-grid3-hd-{id}" unselectable="on" style="{istyle}">',
                                    '<input id="my-header-checkbox-{id}" type="checkbox" class="my-header-checkbox" onclick="myHeaderCheckboxHandler(this, event)" {checked}></input>', // added
                                    true ? '<a class="x-grid3-hd-btn" href="#"></a>' : '',
                                    '{value}',
                                    '<img alt="" class="x-grid3-sort-icon" src="', Ext.BLANK_IMAGE_URL, '" />',
                                '</div>',
                            '</td>'
                        )
                }
            }
    
            var myHeaderCheckboxHandler = function(checkbox, event) {
                GridPanel1.view.checkboxes[checkbox.id] = checkbox.checked ? "checked" : "";
                //here is your handler code
            }
        </script>
    
        <style type="text/css">
            .my-header-checkbox {
                margin-right: 10px;
            }
        </style>
    </head>
    <body>
        <form runat="server">
        <ext:ResourceManager runat="server" />
        <ext:GridPanel 
            ID="GridPanel1" 
            runat="server" 
            AutoHeight="true" 
            EnableColumnMove="false">
            <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 ColumnID="Test1" Header="Test1" DataIndex="test1" />
                    <ext:Column ColumnID="Test2" Header="Test2" DataIndex="test2" />
                    <ext:Column ColumnID="Test3" Header="Test3" DataIndex="test3" />
                </Columns>
            </ColumnModel>
            <View>
                <ext:GridView runat="server">
                    <CustomConfig>
                        <ext:ConfigItem Name="templates" Value="={getTemplates()}" />
                        <ext:ConfigItem Name="checkboxes" Value="{}" Mode="Raw" />
                    </CustomConfig>
                </ext:GridView>
            </View>
        </ext:GridPanel>
        </form>
    </body>
    </html>
    Last edited by Daniil; May 12, 2011 at 9:54 AM.
  3. #3
    Here is a solution for Ext.NET v2.
    http://forums.ext.net/showthread.php...ll=1#post89280
  4. #4
    Hi Daniil,

    Is there any way to mark a specific column header only as having a checkbox in this code sample?
  5. #5
    I've sort of figured it out:

    <%@ 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)
            {
                ResourceManager1.Theme = Ext.Net.Theme.Default;
                Store store = this.GridPanel1.GetStore();
                store.DataSource = new object[] 
                { 
                    new object[] { "test11", "test12", "test13", "test43" },
                    new object[] { "test12", "test22", "test23", "test43" },
                    new object[] { "test13", "test32", "test33", "test43" }
                };
                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>
        <ext:ResourcePlaceHolder runat="server" />
    
        <script type="text/javascript">
            Ext.grid.GridView.override({
                renderHeaders: function () {
                    var colModel = this.cm,
                        templates = this.templates,
                        myTemplates = getTemplates(),
                        headerTpl = templates.hcell,
                        myHeaderTpl = myTemplates.hcell,
                        properties = {},
                        colCount = colModel.getColumnCount(),
                        last = colCount - 1,
                        cells = [],
                        i,
                        cssCls;
    
                    for (i = 0; i < colCount; i++) {
                        if (i == 0) {
                            cssCls = 'x-grid3-cell-first ';
                        } else {
                            cssCls = i == last ? 'x-grid3-cell-last ' : '';
                        }
    
                        properties = {
                            id: colModel.getColumnId(i),
                            value: colModel.getColumnHeader(i) || '',
                            style: this.getColumnStyle(i, true),
                            css: cssCls,
                            tooltip: this.getColumnTooltip(i),
                            checked: this.checkboxes["my-header-checkbox-" + colModel.getColumnId(i)] //added
                        };
    
                        if (colModel.config[i].align == 'right') {
                            properties.istyle = 'padding-right: 16px;';
                        } else {
                            delete properties.istyle;
                        }
    
                        if (colModel.columns[i].columnType === "CheckboxColumn")
                            cells[i] = myHeaderTpl.apply(properties);
                        else
                            cells[i] = headerTpl.apply(properties);
                    }
    
                    return templates.header.apply({
                        cells: cells.join(""),
                        tstyle: String.format("width: {0};", this.getTotalWidth())
                    });
                },
    
                onHeaderClick: function (g, index) {
                    if (Ext.fly(Ext.EventObject.getTarget()).hasClass('my-header-checkbox')) {  //added
                        return;                                                                 //added
                    }                                                                           //added
    
                    if (this.headersDisabled || !this.cm.isSortable(index)) {
                        return;
                    }
    
                    g.stopEditing(true);
                    g.store.sort(this.cm.getDataIndex(index));
                }
            });
        </script>
    
        <script type="text/javascript">
            var getTemplates = function () {
                return {
                    hcell: new Ext.Template(
                            '<td class="x-grid3-hd x-grid3-cell x-grid3-td-{id} {css}" style="{style}">',
                                '<div {tooltip} {attr} class="x-grid3-hd-inner x-grid3-hd-{id}" unselectable="on" style="{istyle}">',
                                    '<input id="my-header-checkbox-{id}" type="checkbox" class="my-header-checkbox" style="margin-right: 5px;vertical-align:middle;margin-bottom:2px;" onclick="if(typeof myHeaderCheckboxHandler != \'undefined\') myHeaderCheckboxHandler(this, event);" {checked}></input>', // added
                                    true ? '<a class="x-grid3-hd-btn" href="#"></a>' : '',
                                    '{value}',
                                    '<img alt="" class="x-grid3-sort-icon" src="', Ext.BLANK_IMAGE_URL, '" />',
                                '</div>',
                            '</td>'
                        )
                }
            }
    
            var myHeaderCheckboxHandler = function (checkbox, event) {
                GridPanel1.view.checkboxes[checkbox.id] = checkbox.checked ? "checked" : "";
                //here is your handler code
            }
        </script>
    
        <style type="text/css">
            .my-header-checkbox {
                margin-right: 10px;
            }
        </style>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" ID="ResourceManager1" />
            <ext:GridPanel
                ID="GridPanel1"
                runat="server"
                AutoHeight="true"
                EnableColumnMove="false">
                <Store>
                    <ext:Store runat="server">
                        <Reader>
                            <ext:ArrayReader>
                                <Fields>
                                    <ext:RecordField Name="test1" />
                                    <ext:RecordField Name="test2" />
                                    <ext:RecordField Name="test3" />
                                    <ext:RecordField Name="test4" />
                                </Fields>
                            </ext:ArrayReader>
                        </Reader>
                    </ext:Store>
                </Store>
                <ColumnModel runat="server">
                    <Columns>
                        <ext:Column ColumnID="Test1" Header="Test1" DataIndex="test1" Sortable="true">
                            <CustomConfig>
                                <ext:ConfigItem Name="ColumnType" Value="CheckboxColumn" Mode="Value"></ext:ConfigItem>
                            </CustomConfig>
                        </ext:Column>
                        <ext:Column ColumnID="Test2" Header="Test2" DataIndex="test2" />
                        <ext:Column ColumnID="Test3" Header="Test3" DataIndex="test3" />
                        <ext:Column ColumnID="Test4" Header="Test4" DataIndex="test4" />
                    </Columns>
                </ColumnModel>
                <View>
                    <ext:GridView runat="server">
                        <CustomConfig>
                            <%--<ext:ConfigItem Name="templates" Value="={getTemplates()}" />--%>
                            <ext:ConfigItem Name="checkboxes" Value="{}" Mode="Raw" />
                        </CustomConfig>
                    </ext:GridView>
                </View>
            </ext:GridPanel>
        </form>
    </body>
    </html>

Similar Threads

  1. Replies: 3
    Last Post: Aug 13, 2010, 4:25 PM
  2. [CLOSED] How to access checkbox in header of GridPanel
    By Hari_CSC in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Mar 25, 2010, 6:26 PM
  3. [CLOSED] gridpanel header menu column checkbox remove
    By majestic in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Oct 15, 2009, 11:28 AM
  4. [CLOSED] GridPanel column header and column chooser different value
    By acrossdev in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jul 07, 2009, 6:01 AM
  5. [CLOSED] Gridpanel header checkbox hide
    By speedstepmem3 in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Nov 19, 2008, 7:41 AM

Tags for this Thread

Posting Permissions