[CLOSED] column alignment for totals toolbar

  1. #1

    [CLOSED] column alignment for totals toolbar

    Ext 1.6

    I have Grid with a bunch of columns. Each a different size and type. For ONE of the columns, I want to total that specific column. However, I cannot seem to get the totals value to align directly under the column I am totaling. I renamed all the columns to dummy names (and stripped down the example code)

    I call the updateTotal JS via Load handler from store and from the columnResize handler in the grid and that works fine.

    Is there a better way to do this? since what I am doing is not working. I am trying to iterate over all columns and add their width.
    please assist.

    Thanks,
    /Z

    JavaScript used:
            var updateTotal = function (grid) {
                var fbar = Ext.getCmp("GridPanel").getBottomToolbar(),
                    column,
                    field,
                    width,
                    data = { t3: "Totals", t4: 0, t5: null },
                    c,
                    cs = grid.view.getColumnData();
                var totalWidth = 0;
                for (var i = 0; i < grid.getColumnModel().columns.length; i++) {
                    column = grid.getColumnModel().columns[i];
                 
                    c = cs[i];
                    if (c.name == "t6") {
                
                        var toolbarSpacer = Ext.getCmp("totalsSpacer");
                        var totalsAmount = 50;
                        toolbarSpacer.setWidth(totalWidth - 2);
                        totalsAmount.setValue((c.renderer)(data[c.name], {}, {}, 0, i, grid.store));
                    }
                    if (!grid.getColumnModel().columns[i].hidden) {
                        totalWidth += grid.getColumnModel().getColumnWidth(i);
                    }
                }
                fbar.doLayout();
            };
    The view itself
     
     
            <ColumnModel ID="ColumnModel" runat="server">
                <Columns>
                    <ext:Column  Width="0" Hidden="true"/>
                    <ext:Column  Width="0" Hidden="true"/>
                    <ext:Column  Width="0" Hidden="true"/>
                    <ext:Column  Width="0" Hidden="true"/>
                    <ext:Column  Width="0" Hidden="true"/>
                    <ext:Column  Width="0" Hidden="true"/>
                    
                    <ext:Column  Width="0" Hidden="true"/>
                    <ext:CommandColumn Width="24" ColumnID="addNewRow">
                        <Commands>
                            <ext:GridCommand CommandName="AddRow" Icon="Add">
                                <ToolTip Text="Add New Row" />
                            </ext:GridCommand>
                        </Commands>
                    </ext:CommandColumn>
                    <ext:DateColumn Header="Date"  Width="90"  Css="background-color: #cccccc;" Format="ddd MM/dd">
                        <Editor>
                            <ext:DateField ID="t1" runat="server" />
                        </Editor>
                    </ext:DateColumn>
                    <ext:TemplateColumn  MenuDisabled="true" Header="t2" Editable="false" Locked="true" Css="word-wrap:break-word;" DataIndex="t2" Width="100" >
                        <Template ID="TemplateS" runat="server" >
                            <Html>
             </Html>
                        </Template>
                    </ext:TemplateColumn>
                    <ext:Column   Header="t3" Width="75">
                        <Renderer Fn="t3Renderer" />
                        <Editor>                        
                            <ext:ComboBox ID="t3" 
                                runat="server" 
                                Shadow="Drop" 
                                Mode="Local" 
                                TriggerAction="All" 
                                ForceSelection="true"
                                DisplayField="description" 
                                ValueField="id"
                                />
                        </Editor>
                    </ext:Column>
                    <ext:Column  Width="70" DataIndex="t4" >
                        <Renderer Fn="t4Renderer" />
                        <Editor>
                            <ext:TextField ID="t4Text" runat="server" />
                        </Editor>
                    </ext:Column>
                    <ext:Column  Width="70" DataIndex="t5" >
                        <Renderer Fn="t5Renderer" />
                        <Editor>
                            <ext:TextField ID="t4Text" runat="server" />
                        </Editor>
                    </ext:Column>
        
                    <ext:Column ColumnID="t6" Header="Hours" Width="40" Css="background-color: #cccccc;"  DataIndex="t6"/>
                </Columns>
            </ColumnModel>
            <SelectionModel>
                <ext:RowSelectionModel ID="RowSelectionModelT" runat="server" SingleSelect="true" />
            </SelectionModel>
            <BottomBar>
                <ext:Toolbar ID="ToolbarT" runat="server" Layout="Container">
                    <Items>
                        <ext:Toolbar ID="Toolbar2" runat="server">
                            <Items>
                               <ext:ToolbarSpacer ID="totalsSpacer" Width="0" runat="server" />
                               <ext:DisplayField ID="totals"
                                    runat="server"
                                    DataIndex="totals"
                                    Cls="total-field"
                                    Text="-" 
                                    />
                            </Items>
                        </ext:Toolbar>
    Last edited by Baidaly; Aug 18, 2013 at 2:55 AM. Reason: [CLOSED]
  2. #2
    Hi @Z,

    Could you, please, provide a full runnable test case?
  3. #3
    Sure. Give me a few days to throw it together.
    /Z
  4. #4
    Sure. Please just post it here when ready.
  5. #5
    Danill,

    Here is the full standalone example. Note that the "totals" column does not properly align with the "grey" column. however, if you remove the code line for "RegisterOnReadyScript"

    this.ResourceManager1.ResourceManager.RegisterOnRe adyScript("Ext.getCmp('GridPanelTd').colModel.colu mns[13].hidden = true;");

    it works fine. The problem is that if you hide columns AFTER you load the store, it doesn't seem to figure out the proper alignment anymor for the totals bar. If you add a listener to ColumnResize and have it call updateTotals(this), then that will work "when you resize," but I need it to align properly onload after the columns are hidden.

    Thanks
    /Z


    <%@ Page Language="C#" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <%@ Import Namespace="System.Collections.Generic" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <!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 id="Head1" runat="server">
        <title></title>
        <style type="text/css">
            .red-text {
                color     : red;
                font-size : large;
            }
            
            .blue-text {
                color     : blue;
                font-size : large;
            }
        </style>
        <script type="text/javascript">
            var commandHandler = function (cmd, node) {
                switch (cmd) {
                    case "addTestDefinition":
                        var win = WindowAddTestDefinition;
                        win.show();
                        break;
                }
            };
            var updateTestWindow = function (value, p, record) {
                Ext.getCmp("DateFieldTest1").setVisible(false);
            };
            var updateTotal = function (grid) {
                var fbar = Ext.getCmp("GridPanelTd").getBottomToolbar(),
                    column,
                    field,
                    width,
                    data = { formatedDuration: null },
                    c,
                    cs = grid.view.getColumnData();
                var totalWidth = 0;
                for (var i = 0; i < grid.getColumnModel().columns.length; i++) {
                    column = grid.getColumnModel().columns[i];
                    c = cs[i];
                    if (c.id == "formatedDuration") {
                        var toolbarSpacer = Ext.getCmp("totalsSpacer");
                        var totalsAmount = Ext.getCmp("formatedDurationTotal");
                        toolbarSpacer.setWidth(totalWidth - 2);
                        totalsAmount.setValue("1.23");
                    }
                    if (!grid.getColumnModel().columns[i].hidden) {
                        totalWidth += grid.getColumnModel().getColumnWidth(i);
                    }
                }
                fbar.doLayout();
            };
        </script>
    
    <script runat="server">
            protected void Page_Load(object sender, EventArgs e)
        {
            this.Store1.DataSource = new List<Company> 
             { 
                 new Company("3m Co", 71.72, 0.02, 0.03),
                 new Company("Alcoa Inc", 29.01, 0.42, 1.47),
                 new Company("Altria Group Inc", 83.81, 0.28, 0.34),
                 new Company("American Express Company", 52.55, 0.01, 0.02),
                 new Company("American International Group, Inc.", 64.13, 0.31, 0.49),
                 new Company("AT&T Inc.", 31.61, -0.48, -1.54),
                 new Company("Boeing Co.", 75.43, 0.53, 0.71),
                 new Company("Caterpillar Inc.", 67.27, 0.92, 1.39),
                 new Company("Citigroup, Inc.", 49.37, 0.02, 0.04),
                 new Company("E.I. du Pont de Nemours and Company", 40.48, 0.51, 1.28),
                 new Company("Exxon Mobil Corp", 68.1, -0.43, -0.64),
                 new Company("General Electric Company", 34.14, -0.08, -0.23),
                 new Company("General Motors Corporation", 30.27, 1.09, 3.74),
                 new Company("Hewlett-Packard Co.", 36.53, -0.03, -0.08),
                 new Company("Honeywell Intl Inc", 38.77, 0.05, 0.13),
                 new Company("Wal-Mart Stores, Inc.", 45.45, 0.73, 1.63)
             };
            this.Store1.DataBind();
            this.ResourceManager1.ResourceManager.RegisterOnReadyScript("Ext.getCmp('GridPanelTd').colModel.columns[13].hidden = true;");
        }
        public class Company
        {
            public Company(string name, double price, double change, double pctChange)
            {
                this.Name = name;
                this.Price = price;
                this.Change = change;
                this.PctChange = pctChange;
            }
            public string Name { get; set; }
            public double Price { get; set; }
            public double Change { get; set; }
            public double PctChange { get; set; }
        }
    </script>
    
    </head>
    <body>
    <form id="AddNodeForm" runat="server">
        <ext:ResourceManager ID="ResourceManager1" runat="server" />
         <ext:Store ID="Store1" runat="server">
            <Reader>
                <ext:JsonReader>
                    <Fields>
                        <ext:RecordField Name="Name" />
                        <ext:RecordField Name="Price" />
                        <ext:RecordField Name="Change" />
                        <ext:RecordField Name="PctChange" />
                    </Fields>
                </ext:JsonReader>
            </Reader>
        </ext:Store>
            <ext:Viewport ID="Viewport1" runat="server" AutoScroll="True" Layout="FitLayout">          
                <Items>
                    <ext:BorderLayout ID="BorderLayout1" runat="server">
                        <Center>
                            <ext:GridPanel 
                                ColumnLines="true"
                                ID="GridPanelTd"
                                runat="server"
                                ClicksToEdit="1"
                                StripeRows="true"
                                TrackMouseOver="true"
                                StoreID="Store1"
                                Layout="fit"
                                Border="true"
                                AutoHeight="true">
                                <Listeners>
                                    <AfterRender Handler="updateTotal(#{GridPanelTd});" />
                                </Listeners>
                                <LoadMask ShowMask="true" />
                                <ColumnModel ID="ColumnModelTd" runat="server">
                                    <Columns>
                                        <ext:Column Header="t1" ColumnID="t1" DataIndex="Name" Width="0" Hidden="true"/>
                                        <ext:Column Header="t2" ColumnID="t2" DataIndex="Name" Width="0" Hidden="true"/>
                                        <ext:Column Header="t3" ColumnID="t3" DataIndex="Name" Width="0" Hidden="true"/>
                                        <ext:Column Header="t4" ColumnID="t4" DataIndex="Name" Width="0" Hidden="true"/>
                                        <ext:Column Header="t5" ColumnID="t5" DataIndex="Name" Width="0" Hidden="true"/>
                                        <ext:Column Header="t6" ColumnID="t6" DataIndex="Name" Width="0" Hidden="true"/>
                    
                                        <ext:CommandColumn Width="24" ColumnID="t7">
                                            <Commands>
                                                <ext:GridCommand CommandName="t7a" Icon="Add">
                                                    <ToolTip Text="t7" />
                                                </ext:GridCommand>
                                            </Commands>
                                        </ext:CommandColumn>
                                        <ext:TemplateColumn ColumnID="t8" MenuDisabled="true" Header="t8" Editable="false" Locked="true" Css="word-wrap:break-word;" DataIndex="Name" Width="100" >
                                            <Template ID="Templae" runat="server" >
                                                <Html>
                                                    {Name}
                                 </Html>
                                            </Template>
                                        </ext:TemplateColumn>
                                        <ext:Column  ColumnID="ypeId" DataIndex="Price" Header="t10" Width="75">
                                            <Editor>                        
                                                <ext:ComboBox ID="ComboBoxP" 
                                                    runat="server" 
                                                    Shadow="Drop" 
                                                    Mode="Local" 
                                                    TriggerAction="All" 
                                                    ForceSelection="true"
                                                    StoreID="Store1" 
                                                    DisplayField="Price" 
                                                    ValueField="Name"
                                                    />
                                            </Editor>
                                        </ext:Column>
                                        <ext:Column ColumnID="t9" Header="12" Width="70" DataIndex="Change" >
                                            <Editor>
                                                <ext:TextField ID="t9a" runat="server" />
                                            </Editor>
                                        </ext:Column>
                                        <ext:Column ColumnID="t10" Header="t11" Width="70" DataIndex="Change">
                                            <Editor>
                                                <ext:TextField ID="TextFieldE" runat="server"/>
                                            </Editor>
                                        </ext:Column>
                                        <ext:Column ColumnID="formatedDuration" Header="t9" Width="40" Css="background-color: #cccccc;"  DataIndex="PctChange"/>
                                        <ext:Column ColumnID="t10" Header="t11" Width="70" DataIndex="Change" Hidden="true">
                                            <Editor>
                                                <ext:TextField ID="TextField1" runat="server"/>
                                            </Editor>
                                        </ext:Column>
                                        <ext:Column ColumnID="t10" Header="t11" Width="70" DataIndex="Change">
                                            <Editor>
                                                <ext:TextField ID="TextField2" runat="server"/>
                                            </Editor>
                                        </ext:Column>
                                    </Columns>
                                </ColumnModel>
                                <SelectionModel>
                                    <ext:RowSelectionModel ID="RowSelectionModelTd" runat="server" SingleSelect="true" />
                                </SelectionModel>
                                <BottomBar>
                                    <ext:Toolbar ID="ToolbarTdTotal" runat="server" Layout="Container">
                                        <Items>
                                            <ext:Toolbar ID="Toolbar2" runat="server">
                                                <Items>
                                                   <ext:ToolbarSpacer ID="totalsSpacer" Width="0" runat="server" />
                                                   <ext:DisplayField ID="formatedDurationTotal"
                                                        runat="server"
                                                        DataIndex="PctChange"
                                                        Cls="total-field"
                                                        Text="-" 
                                                        />
                                                </Items>
                                            </ext:Toolbar>
                                        </Items>
                                    </ext:Toolbar>
                                </BottomBar>
                            </ext:GridPanel>
                        </Center>
                    </ext:BorderLayout>
                </Items>
            </ext:Viewport>
    
    </form>
    </body>
    </html>
    Last edited by Z; Aug 15, 2013 at 2:33 AM.
  6. #6
    Thank you for the test case.

    Please use a ColumnModel's setHidden method.
    this.ResourceManager1.ResourceManager.RegisterOnReadyScript("Ext.getCmp('GridPanelTd').getColumnModel().setHidden(13, true);");
  7. #7
    that worked perfectly!

    Please look at this method and let me know if there is better methods on colModel for width, header and enabled. I didn't see any but wanted to double check.

    Thanks,
    /Z


        Ext.each(jsonObj.gridColumns, function (op) {
            var control = Ext.getCmp(op.parent);
            if (control != null) {
                var i = 0;
                for (i = 0; i < control.colModel.columns.length; i++) {
                    if (control.colModel.columns[i].id == op.id) {
                        control.colModel.setHidden(i, op.hidden);
                        control.colModel.columns[i].enabled = op.enabled;
                        control.colModel.columns[i].width = op.length;
                        if (op.text != null && op.text.length > 0) {
                            control.colModel.columns[i].header = op.text;
                        }
                    }
                }
            }
        });
  8. #8
    Width
    http://docs.sencha.com/extjs/3.4.0/#...setColumnWidth

    Header
    http://docs.sencha.com/extjs/3.4.0/#...etColumnHeader

    Enabled
    Could you, please, clarify what this property is for?
  9. #9
    great!

    for Enabled.... I used setEditable.

    pls close.

    Thanks
    /Z

Similar Threads

  1. GridPanel Toolbar Alignment
    By MCKorgan in forum 2.x Help
    Replies: 0
    Last Post: Jan 22, 2013, 8:52 AM
  2. [CLOSED] Grid - Toolbar/Columnar Alignment
    By adelaney in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Sep 13, 2012, 4:32 PM
  3. [CLOSED] Gridpanel Filter and Recalculate Column Totals
    By IanPearce in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Feb 22, 2012, 3:08 PM
  4. [CLOSED] How to set the Toolbar buttons alignment to bottom
    By ISI in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Aug 02, 2011, 1:02 PM
  5. Toolbar Alignment Question
    By erey in forum 1.x Help
    Replies: 3
    Last Post: Jun 09, 2009, 3:33 PM

Posting Permissions