[CLOSED] How to add a checkbox to column header to check all / uncheck all for a boolean column?

  1. #1

    [CLOSED] How to add a checkbox to column header to check all / uncheck all for a boolean column?

    What's the best way to add a Check All / Uncheck All feature to Boolean Column in a GridPanel? Ideally, it should be a checkbox in the column header.
    Last edited by Daniil; Aug 08, 2013 at 6:09 AM. Reason: [CLOSED]
  2. #2
    Try this

    Column
    <ext:BooleanColumn runat="server" DataIndex="booleanCol" Text="Boolean">
                            <CustomConfig>
                                <ext:ConfigItem Name="onTitleElClick" Value="onTitleElClick" Mode="Raw" />
                            </CustomConfig>
                            <RenderTpl>
                                <Html>
                                    <div id="{id}-titleEl" {tipMarkup}class="x-column-header-inner">
                                        <div style="display:inline; float:left;">
                                            <div class="x-grid-checkheader" style="width:22px;">&nbsp;</div>
                                        </div>
                                        <span id="{id}-textEl" class="x-column-header-text {childElCls}">                                        
                                            {text}
                                        </span>
                                        <tpl if="!menuDisabled">
                                            <div id="{id}-triggerEl" class="x-column-header-trigger {childElCls}"></div>
                                        </tpl>
                                    </div>
                                    {%this.renderContainer(out,values)%}
                                </Html>
                            </RenderTpl>
                            <Listeners>
                                <AfterRender Fn="initClickOnHeader" />
                            </Listeners>
                        </ext:BooleanColumn>
    Javascript code
    function onTitleElClick (e, t) {
                if (!e.getTarget(".x-grid-checkheader")) { 
                    Ext.grid.column.Column.prototype.onTitleElClick.apply(this, arguments);
                }
            }
    
    
            function initClickOnHeader (column) {           
    
    
                column.el.on("click", function (e, t) {
                    var me= this,
                        grid = this.up('tablepanel'),
                        store = grid.getStore(),
                        div = Ext.fly(e.getTarget());
    
    
                    me.checked = !me.checked;
                    div[me.checked ? "addCls" :"removeCls"]("x-grid-checkheader-checked");                
    
    
                    store.suspendEvents();
                    store.each(function(record){
                        record.set(me.dataIndex, me.checked);
                    });
                    store.resumeEvents();
                    store.fireEvent("refresh", store);
    
    
                    e.stopEvent();
                    return false;
                }, column, {delegate: ".x-grid-checkheader"})
            }

Similar Threads

  1. [CLOSED] Checkbox Column header in GridPanel
    By speedstepmem4 in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Aug 12, 2014, 8:16 PM
  2. [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
  3. [CLOSED] How To Check or UnCheck Checkbox of treepanel from server side
    By legaldiscovery in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Jun 27, 2011, 1:01 PM
  4. Replies: 2
    Last Post: Mar 21, 2010, 1:18 PM
  5. Replies: 1
    Last Post: Aug 13, 2009, 9:37 AM

Posting Permissions