gridPanel with Total Row and Row Expander Plugin

  1. #1

    gridPanel with Total Row and Row Expander Plugin

    Hi,
    I have a problem with combining gridPanel "Total Row" and "Row Expander Plugin" presents problems displaying the total, I think the "Refresh" is not able to add records and show total. Any suggestions.

    <%@ 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[] {"1", "1.1", "1.01"},
                    new object[] {"2", "2.2", "2.02"},
                    new object[] {"3", "3.3", "3.01"}
                };
                
                store.DataBind();
            }
        }
    
        [DirectMethod]
        public static string GetGrid(Dictionary<string, string> parameters)
        {
            // string id = parameters["id"];
    
            List<object> data = new List<object>();
    
            for (int i = 1; i <= 10; i++)
            {
                data.Add(new { ID = "P" + i, Name = "Product " + i });
            }
    
            GridPanel grid = new GridPanel
            {
                Height = 200,
                EnableColumnHide = false,
                Store = 
                { 
                    new Store 
                    { 
                        Model = {
                            new Model {
                                IDProperty = "ID",
                                Fields = 
                                {
                                    new ModelField("ID"),
                                    new ModelField("Name")
                                }
                            }
                        },
                        DataSource = data
                    }
                },
                ColumnModel =
                {
                    Columns = 
                    { 
                        new Column { Text = "Products's Name", DataIndex = "Name" }
                    }
                }
            };
    
            return ComponentLoader.ToConfig(grid);
        }
    </script>
     
    <!DOCTYPE html>
        
    <html>
    <head id="Head1" runat="server">
        <title>GridPanel with Total Row - Ext.Net Example</title>
        <link href="/resources/css/examples.css" rel="stylesheet" />
        
        <script>
            var updateTotal = function (grid, container) {
                if (!grid.view.rendered) {
                    return;
                }
    
                var field,
                    value,
                    width,
                    data = { test1: 0, test2: 0, test3: 0 },
                    c,
                    cs = grid.headerCt.getVisibleGridColumns();
    
                for (var j = 0, jlen = grid.store.getCount() ; j < jlen; j++) {
                    var r = grid.store.getAt(j);
    
                    for (var i = 0, len = cs.length; i < len; i++) {
                        c = cs[i];
                        if (c.dataIndex) {
                            data[c.dataIndex] += r.get(c.dataIndex);
                        }
                    }
                }
    
                container.suspendLayout = true;
                for (var i = 0; i < cs.length; i++) {
                    c = cs[i];
                    value = data[c.dataIndex];
    
                    field = container.down('component[name="' + c.dataIndex + '"]');
    
                    container.remove(field, false);
                    container.insert(i, field);
                    width = c.getWidth();
                    field.setWidth(width - 1);
                    field.setValue(c.renderer ? (c.renderer)(value, {}, {}, 0, i, grid.store, grid.view) : value);
                }
    
                container.items.each(function (field) {
                    var column = grid.headerCt.down('component[dataIndex="' + field.name + '"]');
                    field.setVisible(column.isVisible());
                });
    
                container.suspendLayout = false;
                container.doComponentLayout();
            };
        </script>
     
        <style>
            .total-field{
                background-color : #fff;            
                border           : solid 1px silver;
                padding          : 0px 1px 1px 1px;
                margin-right     : 1px;
                position: absolute;
            }
             
            .total-field .x-form-display-field{            
                font-weight      : bold !important;                       
                font-size        : 11px;
                font-family      : tahoma, arial, verdana, sans-serif;
                color            : #000;  
                padding          : 3px 0px 2px 5px;
                          
            } 
        </style>
    </head>
    <body>
        <form id="Form1" runat="server">
            <h1>GridPanel with Total Row</h1>
            
            <ext:ResourceManager ID="ResourceManager1" runat="server" />
            
            <ext:GridPanel ID="GridPanel1" runat="server" AutoHeight="true" Width="300">
                <Store>
                    <ext:Store ID="Store1" runat="server">
                        <Model>
                            <ext:Model ID="Model1" runat="server">
                                <Fields>
                                    <ext:ModelField Name="test1" Type="Int"/>
                                    <ext:ModelField Name="test2" Type="Float"/>
                                    <ext:ModelField Name="test3" Type="Float"/>
                                </Fields>
                            </ext:Model>
                        </Model>
                    </ext:Store>
                </Store>
                <ColumnModel ID="ColumnModel1" runat="server">
                    <Columns>
                        <ext:Column ID="Column1" runat="server" Text="Test1" DataIndex="test1" Flex="1" />
                        <ext:Column ID="Column2" runat="server" Text="Test2" DataIndex="test2" Flex="1" />
                        <ext:Column ID="Column3" runat="server" Text="Test3" DataIndex="test3" Flex="1" />
                    </Columns>
                </ColumnModel>
                <View>
                    <ext:GridView ID="GridView1" runat="server">
                        <Listeners>
                            <Refresh Handler="updateTotal(this.panel, #{Container1});" />
                        </Listeners>
                    </ext:GridView>
                </View>
                <Listeners> 
                    <ColumnResize Handler="updateTotal(this, #{Container1});" />                
                    <ColumnMove Handler="updateTotal(this, #{Container1});" /> 
                    <ColumnHide Handler="updateTotal(this, #{Container1});" />                
                </Listeners>
                <DockedItems>
                    <ext:Container ID="Container1" runat="server" Layout="HBoxLayout" Dock="Bottom" StyleSpec="margin-top:2px;">
                        <Defaults>
                            <ext:Parameter Name="height" Value="22" />
                        </Defaults>
                        <Items>                        
                            <ext:DisplayField ID="DisplayField1"
                                runat="server"
                                Name="test1"
                                Cls="total-field"
                                Text="-" 
                                />
                            <ext:DisplayField ID="DisplayField2"
                                runat="server"
                                Name="test2"
                                Cls="total-field"
                                Text="-" 
                                />
                            <ext:DisplayField ID="DisplayField3"
                                runat="server"
                                Name="test3"
                                Cls="total-field"
                                Text="-" 
                                />                                                    
                        </Items>
                    </ext:Container>
                </DockedItems>
                  <Plugins>
                        <ext:RowExpander ID="RowExpander1" runat="server"    >
                        <Loader ID="Loader1" runat="server" DirectMethod="#{DirectMethods}.GetGrid" Mode="Component" >
                            <LoadMask ShowMask="true" />
                            <Params>
                                <ext:Parameter Name="id" Value="this.record.getId()" Mode="Raw" />
                            </Params>
                        </Loader>
                    </ext:RowExpander>
                </Plugins>   
            </ext:GridPanel>
        </form>
    </body>
    </html>
  2. #2
    Hello @billy,

    You need to tune up the updateTotal according to the additional column which the RowExpander adds.

    Example
    var updateTotal = function (grid, container) {
        if (!grid.view.rendered) {
            return;
        }
     
        var field,
            value,
            width,
            data = { test1: 0, test2: 0, test3: 0 },
            c,
            cs = grid.headerCt.getVisibleGridColumns();
     
        for (var j = 0, jlen = grid.store.getCount() ; j < jlen; j++) {
            var r = grid.store.getAt(j);
     
            for (var i = 0, len = cs.length; i < len; i++) {
                c = cs[i];
                if (c.dataIndex) {
                    data[c.dataIndex] += r.get(c.dataIndex);
                }
            }
        }
     
        container.suspendLayout = true;
        for (var i = 0; i < cs.length; i++) {
            c = cs[i];
    
            if (i === 0) {
                field = container.items.get(0);
                width = c.getWidth() + 2;
            } else {
                value = data[c.dataIndex];
                field = container.down('component[name="' + c.dataIndex + '"]');
                field.setValue(c.renderer ? (c.renderer)(value, {}, {}, 0, i, grid.store, grid.view) : value);                    
                width = c.getWidth() - 1;
            }
     
            container.remove(field, false);
            container.insert(i, field);
            field.setWidth(width);
        }
     
        container.items.each(function (field, index) {
            var column;
    
            if (index === 0) {
                column = grid.headerCt.items.get(0);
            } else {
                column = grid.headerCt.down('component[dataIndex="' + field.name + '"]');
            }
    
            field.setVisible(column.isVisible());
        });
     
        container.suspendLayout = false;
        container.doComponentLayout();
    };
  3. #3
    Quote Originally Posted by Daniil View Post
    Hello @billy,

    You need to tune up the updateTotal according to the additional column which the RowExpander adds.

    Example
    var updateTotal = function (grid, container) {
        if (!grid.view.rendered) {
            return;
        }
     
        var field,
            value,
            width,
            data = { test1: 0, test2: 0, test3: 0 },
            c,
            cs = grid.headerCt.getVisibleGridColumns();
     
        for (var j = 0, jlen = grid.store.getCount() ; j < jlen; j++) {
            var r = grid.store.getAt(j);
     
            for (var i = 0, len = cs.length; i < len; i++) {
                c = cs[i];
                if (c.dataIndex) {
                    data[c.dataIndex] += r.get(c.dataIndex);
                }
            }
        }
     
        container.suspendLayout = true;
        for (var i = 0; i < cs.length; i++) {
            c = cs[i];
    
            if (i === 0) {
                field = container.items.get(0);
                width = c.getWidth() + 2;
            } else {
                value = data[c.dataIndex];
                field = container.down('component[name="' + c.dataIndex + '"]');
                field.setValue(c.renderer ? (c.renderer)(value, {}, {}, 0, i, grid.store, grid.view) : value);                    
                width = c.getWidth() - 1;
            }
     
            container.remove(field, false);
            container.insert(i, field);
            field.setWidth(width);
        }
     
        container.items.each(function (field, index) {
            var column;
    
            if (index === 0) {
                column = grid.headerCt.items.get(0);
            } else {
                column = grid.headerCt.down('component[dataIndex="' + field.name + '"]');
            }
    
            field.setVisible(column.isVisible());
        });
     
        container.suspendLayout = false;
        container.doComponentLayout();
    };
    Thanks for the explanation and for your time. Suppose that in the plugin "rowExpander" had nested a "gridPanel" I note that it is not capable of doing the updateTotal to is this.
  4. #4
    Please clarify do you want a total row for inner grids?
  5. #5
    Quote Originally Posted by Daniil View Post
    Please clarify do you want a total row for inner grids?
    Exactly, but usability issues change my question is:
    The plugin "rowExpander", working with all records "gridPanel" with "SummaryColumn" I notice that if configured with page shows only a partial total per column, each column shows the sum of the numerical values ​​but per page is shown but not the total value for all records "gridPanel", I wonder if you can display the total of all records.

    Click image for larger version. 

Name:	Imagen A.jpg 
Views:	250 
Size:	75.2 KB 
ID:	5493
    <%@ 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[] {"1", "1.1", "1.01"},
                    new object[] {"2", "2.2", "2.02"},
                    new object[] {"3", "3.3", "3.01"}
                };
    
                store.DataBind();
            }
        }
    
        protected void BeforeExpand(object sender, DirectEventArgs e)
        {
            this.Store2.DataSource = new object[]
                {
                    new { company = "3m Co", price = 71.72, change = 0.02 },
                    new   {company = "Alcoa Inc", price =  29.01, change =  0.42 },
                    new   { company ="Altria Group Inc", price =  83.81, change =  0.28 },
                    new  { company ="American Express Company",  price = 52.55, change =  0.01 },
                    new   {company = "American International Group, Inc.", price =  64.13, change = 0.31 },
                    new   {company = "AT&T Inc.", price =  31.61, change = -0.48 },
                    new   {company = "Boeing Co.",  price = 75.43, change =  0.53 },
                    new   {company = "Caterpillar Inc.", price =  67.27, change = 0.92 }
                };
            this.Store2.DataBind();
        }
       
    </script>
    
    <!DOCTYPE html>
    
    <html>
    <head id="Head1" runat="server">
        <title>GridPanel with Total Row - Ext.Net Example</title>
        <link href="/resources/css/examples.css" rel="stylesheet" />
        <script>
    
            var updateTotal = function (grid, container) {
                if (!grid.view.rendered) {
                    return;
                }
    
                var field,
                    value,
                    width,
                    data = { test1: 0, test2: 0, test3: 0 },
                    c,
                    cs = grid.headerCt.getVisibleGridColumns();
    
                for (var j = 0, jlen = grid.store.getCount() ; j < jlen; j++) {
                    var r = grid.store.getAt(j);
    
                    for (var i = 0, len = cs.length; i < len; i++) {
                        c = cs[i];
                        if (c.dataIndex) {
                            data[c.dataIndex] += r.get(c.dataIndex);
                        }
                    }
                }
    
                container.suspendLayout = true;
                for (var i = 0; i < cs.length; i++) {
                    c = cs[i];
    
                    if (i === 0) {
                        field = container.items.get(0);
                        width = c.getWidth() + 2;
                    } else {
                        value = data[c.dataIndex];
                        field = container.down('component[name="' + c.dataIndex + '"]');
                        field.setValue(c.renderer ? (c.renderer)(value, {}, {}, 0, i, grid.store, grid.view) : value);
                        width = c.getWidth() - 1;
                    }
    
                    container.remove(field, false);
                    container.insert(i, field);
                    field.setWidth(width);
                }
    
                container.items.each(function (field, index) {
                    var column;
    
                    if (index === 0) {
                        column = grid.headerCt.items.get(0);
                    } else {
                        column = grid.headerCt.down('component[dataIndex="' + field.name + '"]');
                    }
    
                    field.setVisible(column.isVisible());
                });
    
                container.suspendLayout = false;
                container.doComponentLayout();
            };
    
            var totalCost = function (records) {
                var i = 0,
                    length = records.length,
                    total = 0,
                    record;
    
                for (; i < length; ++i) {
                    record = records[i];
                    total += record.get('price') * record.get('change');
                }
    
                return total;
            };
    
    
        </script>
    
        <style>
            .total-field {
                background-color: #fff;
                border: solid 1px silver;
                padding: 0px 1px 1px 1px;
                margin-right: 1px;
                position: absolute;
            }
    
                .total-field .x-form-display-field {
                    font-weight: bold !important;
                    font-size: 11px;
                    font-family: tahoma, arial, verdana, sans-serif;
                    color: #000;
                    padding: 3px 0px 2px 5px;
                }
    
            .x-grid-body .x-grid-cell-Cost {
                background-color : #f1f2f4;
            }
             
            .x-grid-row-summary .x-grid-cell-Cost .x-grid-cell-inner{
                background-color : #e1e2e4;
            }    
    
            .task .x-grid-cell-inner {
                padding-left: 15px;
            }
    
            .x-grid-row-summary .x-grid-cell-inner {
                font-weight      : bold;
                font-size        : 11px;
                background-color : #f1f2f4;
            } 
        </style>
    </head>
    <body>
        <form id="Form1" runat="server">
            <ext:ResourceManager ID="ResourceManager1" runat="server" />
            <ext:Store ID="Store2" runat="server" PageSize="5">
                <Model>
                    <ext:Model ID="Model3" runat="server" Name="company" IDProperty="company">
                        <Fields>
                            <ext:ModelField Name="company" />
                            <ext:ModelField Name="price" Type="Float" />
                            <ext:ModelField Name="change" Type="Float" />
                        </Fields>
                    </ext:Model>
                </Model>
            </ext:Store>
            <ext:GridPanel ID="GridPanel1" runat="server" Height="350" Width="650">
                <Store>
                    <ext:Store ID="Store1" runat="server">
                        <Model>
                            <ext:Model ID="Model1" runat="server">
                                <Fields>
                                    <ext:ModelField Name="test1" Type="Int" />
                                    <ext:ModelField Name="test2" Type="Float" />
                                    <ext:ModelField Name="test3" Type="Float" />
                                </Fields>
                            </ext:Model>
                        </Model>
                    </ext:Store>
                </Store>
                <ColumnModel ID="ColumnModel1" runat="server">
                    <Columns>
                        <ext:Column ID="Column1" runat="server" Text="Test1" DataIndex="test1" Flex="1" />
                        <ext:Column ID="Column2" runat="server" Text="Test2" DataIndex="test2" Flex="1" />
                        <ext:Column ID="Column3" runat="server" Text="Test3" DataIndex="test3" Flex="1" />
                    </Columns>
                </ColumnModel>
                <View>
                    <ext:GridView ID="GridView1" runat="server">
                        <Listeners>
                            <Refresh Handler="updateTotal(this.panel, #{Container1});" />
                        </Listeners>
                    </ext:GridView>
                </View>
                <Listeners>
                    <ColumnResize Handler="updateTotal(this, #{Container1});" />
                    <ColumnMove Handler="updateTotal(this, #{Container1});" />
                    <ColumnHide Handler="updateTotal(this, #{Container1});" />
                </Listeners>
                <DockedItems>
                    <ext:Container ID="Container1" runat="server" Layout="HBoxLayout" Dock="Bottom" StyleSpec="margin-top:2px;">
                        <Defaults>
                            <ext:Parameter Name="height" Value="22" />
                        </Defaults>
                        <Items>
                            <ext:DisplayField ID="DisplayField1" runat="server" Name="test1" Cls="total-field" Text="-" />
                            <ext:DisplayField ID="DisplayField2" runat="server" Name="test2" Cls="total-field" Text="-" />
                            <ext:DisplayField ID="DisplayField3" runat="server" Name="test3" Cls="total-field" Text="-" />
                        </Items>
                    </ext:Container>
                </DockedItems>
                <Plugins>
                    <ext:RowExpander ID="RowExpander1" runat="server">
                        <DirectEvents>
                            <BeforeExpand OnEvent="BeforeExpand" />
                        </DirectEvents>
                        <Component>
                            <ext:GridPanel ID="gridPanel" runat="server" StoreID="Store2" AutoHeight="true" tripeRows="true" TrackMouseOver="true">
                                <ColumnModel ID="ColumnModel2" runat="server">
                                    <Columns>
                                        <ext:Column ID="Column9" runat="server" Text="Company" DataIndex="company" Flex="1" />
                                        <ext:SummaryColumn ID="SummaryColumn2" runat="server" Width="75" Text="Price" Sortable="true"
                                            DataIndex="price" SummaryType="Sum" />
                                        <ext:SummaryColumn ID="SummaryColumn1" runat="server" Width="75" Text="Change" Sortable="true"
                                            DataIndex="change" SummaryType="Sum" />
                                        <ext:SummaryColumn runat="server" Width="75" ID="Total" Text="Total"
                                            CustomSummaryType="totalCost" Sortable="false" Groupable="false">
                                            <Renderer Handler="return Ext.util.Format.usMoney(record.data.price * record.data.change);" />
                                            <SummaryRenderer Fn="Ext.util.Format.usMoney" />
                                        </ext:SummaryColumn>
                                    </Columns>
                                </ColumnModel>
                                <Features>
                                    <ext:Summary ID="Summary1" runat="server" />
                                </Features>
                                <View>
                                    <ext:GridView ID="GridView" runat="server" MarkDirty="false" LoadMask="true" StripeRows="true" />
                                </View>
                                <BottomBar>
                                    <ext:PagingToolbar ID="PagingToolbar1" runat="server" StoreID="Store2" />
                                </BottomBar>
                            </ext:GridPanel>
                        </Component>
                    </ext:RowExpander>
                </Plugins>
            </ext:GridPanel>
        </form>
    </body>
    </html>
    Last edited by billy; Jan 28, 2013 at 4:42 PM.

Similar Threads

  1. Problem: Row Expander Plugin with GridPanel
    By DanielU in forum 1.x Help
    Replies: 10
    Last Post: Dec 03, 2012, 9:34 AM
  2. [CLOSED] Paging Row Expander Plugin with GridPanel
    By pdcase in forum 1.x Legacy Premium Help
    Replies: 0
    Last Post: May 15, 2012, 7:00 PM
  3. [CLOSED] Row Expander Plugin with GridPanel
    By deejayns in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jan 27, 2011, 8:06 PM
  4. Replies: 4
    Last Post: Nov 08, 2010, 11:13 AM
  5. Row Expander Plugin with Gridpanels
    By NishaLijo in forum 1.x Help
    Replies: 0
    Last Post: Aug 19, 2010, 12:07 PM

Posting Permissions