This is a migrated thread and some comments may be shown as answers.

Default collapse group not working

4 Answers 63 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Joel
Top achievements
Rank 1
Joel asked on 11 Aug 2014, 09:32 PM
I'm trying to get my RadGrid grouping working like the telerik demos. I can turn groups on and they perform column drag&drop grouping just fine, so far so good, however:

My collapse group buttons are not working. When I click on the arrow to collapse a group, it posts back to the server, but doesn't actually collapse the group. I was assuming it works by default, I didn't notice any handling in the server code in the demo.

Am I doing something wrong, or maybe I missed a step? What should I try next?

I also notice the styling is slightly different than in the demo - my group headers are flat but the demo's are shaded "3D" looking. That may be irrelevant, or might point in the right direction.


The telerik grid demo I'm talking about: http://demos.telerik.com/aspnet-ajax/grid/examples/functionality/grouping/grouping/defaultcs.aspx

I'm using Telerik aspnet-ajax R 2014 Q1

My grid code:
<telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" GridLines="None" PageSize="25" AutoGenerateColumns = "false" ShowFooter="true" ShowGroupPanel="True" >
 
 
<ClientSettings AllowDragToGroup="true">
    <Resizing ResizeGridOnColumnResize="True"></Resizing>
</ClientSettings>
 
<GroupingSettings ShowUnGroupButton="true"></GroupingSettings>
  
<MasterTableView TableLayout="Auto"  Width="100%" > <%-- AllowGroupCollapse="true" --%>
 
 
    <Columns>
        <telerik:GridBoundColumn UniqueName="trvAccountGroup" DataField="t_rv_account_group" HeaderText="trvAccountGroup"></telerik:GridBoundColumn>
        <telerik:GridBoundColumn UniqueName="trvSysAccount" DataField="t_rv_sys_account" HeaderText="trvSysAccount"></telerik:GridBoundColumn>
        <telerik:GridBoundColumn UniqueName="trvAccount" DataField="t_rv_account" HeaderText="trvAccount"></telerik:GridBoundColumn>
        <telerik:GridBoundColumn UniqueName="trvGlObject1" DataField="t_rv_gl_object_1" HeaderText="trvGlObject1"></telerik:GridBoundColumn>
        <telerik:GridBoundColumn UniqueName="trvGlObject2" DataField="t_rv_gl_object_2" HeaderText="trvGlObject2"></telerik:GridBoundColumn>
        <telerik:GridBoundColumn UniqueName="trGl" DataField="t_r_gl" HeaderText="trGl"></telerik:GridBoundColumn>
        <telerik:GridBoundColumn UniqueName="trcId" DataField="t_rc_id" HeaderText="trcId"></telerik:GridBoundColumn>
 
        <telerik:GridBoundColumn UniqueName="mAmt0" DataField="m_amt_0" HeaderText="mAmt0" DataFormatString="{0:F0}" Aggregate="Avg"></telerik:GridBoundColumn>
        <telerik:GridBoundColumn UniqueName="mAmt1" DataField="m_amt_1" HeaderText="mAmt1" DataFormatString="{0:F0}" Aggregate="Avg"></telerik:GridBoundColumn>
        <telerik:GridBoundColumn UniqueName="mAmt2" DataField="m_amt_2" HeaderText="mAmt2" DataFormatString="{0:F0}" Aggregate="Avg"></telerik:GridBoundColumn>
        <telerik:GridBoundColumn UniqueName="mAmt3" DataField="m_amt_3" HeaderText="mAmt3" DataFormatString="{0:F0}" Aggregate="Avg"></telerik:GridBoundColumn>
        <telerik:GridBoundColumn UniqueName="mAmt4" DataField="m_amt_4" HeaderText="mAmt4" DataFormatString="{0:F0}" Aggregate="Avg"></telerik:GridBoundColumn>
        <telerik:GridBoundColumn UniqueName="mAmt5" DataField="m_amt_5" HeaderText="mAmt5" DataFormatString="{0:F0}" Aggregate="Avg"></telerik:GridBoundColumn>
        <telerik:GridBoundColumn UniqueName="mAmt6" DataField="m_amt_6" HeaderText="mAmt6" DataFormatString="{0:F0}" Aggregate="Avg"></telerik:GridBoundColumn>
        <telerik:GridBoundColumn UniqueName="mAmt7" DataField="m_amt_7" HeaderText="mAmt7" DataFormatString="{0:F0}" Aggregate="Avg"></telerik:GridBoundColumn>
        <telerik:GridBoundColumn UniqueName="mAmt8" DataField="m_amt_8" HeaderText="mAmt8" DataFormatString="{0:F0}" Aggregate="Avg"></telerik:GridBoundColumn>
        <telerik:GridBoundColumn UniqueName="mAmt9" DataField="m_amt_9" HeaderText="mAmt9" DataFormatString="{0:F0}" Aggregate="Avg"></telerik:GridBoundColumn>
                             
        <telerik:GridBoundColumn UniqueName="mAmtOther" DataField="m_amt_other" HeaderText="mAmtOther" DataFormatString="{0:F0}" Aggregate="Avg"></telerik:GridBoundColumn>
        <telerik:GridBoundColumn UniqueName="mTotalAmt" DataField="m_total_amt" HeaderText="mTotalAmt" DataFormatString="{0:F0}" Aggregate="Avg"></telerik:GridBoundColumn>
 
    </Columns>
</MasterTableView>
 
</telerik:RadGrid>

4 Answers, 1 is accepted

Sort by
0
Joel
Top achievements
Rank 1
answered on 11 Aug 2014, 09:37 PM
In my code I had something that looks idotic, but I've fixed it and still have the same problem:
  <MasterTableView TableLayout="Auto"  Width="100%" > <%-- AllowGroupCollapse="true" --%>
Is now:
  <MasterTableView TableLayout="Auto"  Width="100%" AllowGroupCollapse="true" >

But the behavior is still the same "no collapse" behavior.
Thanks!
0
Princy
Top achievements
Rank 1
answered on 12 Aug 2014, 05:55 AM
Hi Joel,

I was not able to replicate this issue at my end. Can you make sure you are binding the Grid using Advanced Data-binding (Using NeedDataSource Event), also make sure that EnableViewState property of the grid is set to true. If this doesn't help, can you provide your code behind as well.

Thanks,
Princy
0
Joel
Top achievements
Rank 1
answered on 12 Aug 2014, 03:33 PM
Thanks, Princy! I'm definitely using Advanced Data-binding (after all, I can group!) and I tried the EnableViewState="true" without any change in behavior.

My page is an ascx page embedded in a dynamically loaded frame page inside an iframe in the main site page; hopefully that doesn't matter, but just in case.

Here is the HTML rendering of the group collapse button on my page:
<input type="submit" name="fb$ctl00$RadGrid1$ctl00$ctl04$ctl00" value=" " title="Collapse group" class="rgCollapse" id="fb_ctl00_RadGrid1_ctl00__2__0">
(I notice when RadGrid renders my page this collapse button is an input type="submit", when it renders the demo page, it is a input type="button" with a __doPostback onclick handler. Does that matter, and is there a flag I can switch to control that?)

Here is the RadGrid related codebehind.:
protected void Control_Init(object sender, EventArgs e)
 {
            // My init here
            // ...
 
            RadGrid1.PreRender += RadGrid1_PreRender;
            RadGrid1.ItemCreated += RadGrid1_ItemCreated;
            RadGrid1.ItemDataBound += RadGrid1_ItemDataBound;
            RadGrid1.NeedDataSource += RadGrid1_NeedDataSource;
}
 
 
        protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {
            if (DataSet != null && DataSet.xgl_balance != null)
            {
                (sender as RadGrid).DataSource = DataSet.xgl_balance;
            }
            else
            {
                (sender as RadGrid).DataSource = null;
            }
        }
 
 
 
        protected void RadGrid1_PreRender(object sender, EventArgs e)
        {
            Dictionary<string, string> TitlesDictionary = new Dictionary<string, string>();
 
            TitlesDictionary["trvAccountGroup"] = GetElementTitle(102858);
            TitlesDictionary["trvSysAccount"] = GetElementTitle(102863);
            TitlesDictionary["trvAccount"] = GetElementTitle(102829);
            TitlesDictionary["trvGlObject1"] = GetElementTitle(102859);
            TitlesDictionary["trvGlObject2"] = GetElementTitle(102860);
            TitlesDictionary["trGl"] = GetElementTitle(102861);
            TitlesDictionary["trcId"] = GetElementTitle(102862);
             
            TitlesDictionary["mAmtOther"] = GetElementTitle(102856);
            TitlesDictionary["mTotalAmt"] = GetElementTitle(102857);
 
            TitlesDictionary["trvGlObject1"] = OwnerInfo.GLObject1.Text;
            TitlesDictionary["trvGlObject1"] = OwnerInfo.GLObject2.Text;
 
            Dictionary<string, bool> VisibleDictionary = new Dictionary<string, bool>();
 
            VisibleDictionary["mAmt0"] =  false;
            VisibleDictionary["mAmt1"] =  false;
            VisibleDictionary["mAmt2"] =  false;
            VisibleDictionary["mAmt3"] =  false;
            VisibleDictionary["mAmt4"] =  false;
            VisibleDictionary["mAmt5"] =  false;
            VisibleDictionary["mAmt6"] =  false;
            VisibleDictionary["mAmt7"] =  false;
            VisibleDictionary["mAmt8"] =  false;
            VisibleDictionary["mAmt9"] =  false;
 
            VisibleDictionary["trvAccountGroup"] = chkAccountGroup.Checked;
            VisibleDictionary["trvSysAccount"] = chkShowSysAccount.Checked;
            VisibleDictionary["trvAccount"] = chkAccount.Checked;
             
            VisibleDictionary["trvGlObject1"] = chkShowGLObject1.Checked && OwnerInfo.GLObject1.Value > 0;
            VisibleDictionary["trvGlObject2"] = chkShowGLObject2.Checked && OwnerInfo.GLObject2.Value > 0;
            VisibleDictionary["trGl"] = chkShowXGL.Checked && OwnerInfo.RGL.Value > 0;
             
            VisibleDictionary["trcId"] = chkShowClient.Checked;
 
            foreach (GLMetaDataRowType row in DataSet.xgl_meta_data)
            {
                string Name = "mAmt" + row.i_sequence.ToString();
                VisibleDictionary[Name] = true;
                TitlesDictionary[Name] = row.t_rv_pivot;
            }
 
            foreach (GridColumn col in RadGrid1.MasterTableView.RenderColumns)
            {
                if (TitlesDictionary.ContainsKey(col.UniqueName))
                {
                    col.HeaderText = TitlesDictionary[col.UniqueName];
                }
                if (VisibleDictionary.ContainsKey(col.UniqueName))
                {
                    col.Visible = VisibleDictionary[col.UniqueName];
                }
            }
 
            // Commit changes
            RadGrid1.MasterTableView.Rebind();
        }
 
        protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
        {
            // Html Export sample
            if (e.Item is GridDataItem || e.Item is GridHeaderItem)
            {
                e.Item.Cells[2].CssClass = "employeeColumn";
            }
 
            // Pager items being created, setup our own page sizes based on user default value (usually 25 rows)
            if (e.Item is GridPagerItem)
            {
                var dropDown = (RadComboBox)e.Item.FindControl("PageSizeComboBox");
                var totalCount = ((GridPagerItem)e.Item).Paging.DataSourceCount;
                var sizes = new Dictionary<string, string>();
                int DefaultSize = 25; // Load user's default rows per grid from their settings - why isn't it on UserInfo?
 
                // 25
                if (totalCount > DefaultSize)
                {
                    string SizeTitle = DefaultSize.ToString();
                    sizes.Add(SizeTitle, SizeTitle);
                }
                // 50
                if (totalCount > DefaultSize * 2)
                {
                    string SizeTitle = (DefaultSize * 2).ToString();
                    sizes.Add(SizeTitle, SizeTitle);
                }
                // 100
                if (totalCount > DefaultSize * 4)
                {
                    string SizeTitle = (DefaultSize * 4).ToString();
                    sizes.Add(SizeTitle, SizeTitle);
                }
                // 200
                if (totalCount > DefaultSize * 8)
                {
                    string SizeTitle = (DefaultSize * 8).ToString();
                    sizes.Add(SizeTitle, SizeTitle);
                }
 
                // Always show "All" to tell user they have everything (even if just 1)
                sizes.Add("All", totalCount.ToString());
 
                dropDown.Items.Clear();
                foreach (var size in sizes)
                {
                    var cboItem = new RadComboBoxItem() { Text = size.Key, Value = size.Value };
                    cboItem.Attributes.Add("ownerTableViewId", e.Item.OwnerTableView.ClientID);
                    dropDown.Items.Add(cboItem);
                }
                var curItem = dropDown.FindItemByValue(e.Item.OwnerTableView.PageSize.ToString());
                if (curItem != null)
                {
                    curItem.Selected = true;
                }
                else if (dropDown.Items.Count > 0)
                {
                    dropDown.Items[0].Selected = true;
                }
            }
        }
 
        /// <summary>
        /// Even handler when a grid item is databound - usually a cell
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
        {
            // If a datarow, alter the columns we care about to hide zero and add proper clss classes
            if (e.Item is GridDataItem)
            {
                GridDataItem dataItem = e.Item as GridDataItem;
 
                //
                // Numeric data columns
                //
                string[] NumericDataColumns = {
                                "mAmt0", "mAmt1", "mAmt2", "mAmt3", "mAmt4", "mAmt5", "mAmt6", "mAmt7", "mAmt8", "mAmt9",
                                "mAmtOther"};
 
                foreach (string col in NumericDataColumns)
                {
                    string text = dataItem[col].Text;
 
                    // Probably a better way to do this than a few zero strings, but works for demo
                    if (text == "0.0000" || text == "0.00" || text == "0")
                    {
                        dataItem[col].Text = "";
                    }
 
                    // Add standard numeric class
                    dataItem[col].CssClass = "lbm data_cell";
 
                    // class to make negative values red
                    if (text.StartsWith("-"))
                    {
                        dataItem[col].CssClass += " lbml";
                    }
                }
 
                //
                // Total columns
                //
                string[] NumericTotalColumns = { "mTotalAmt" };
 
                foreach (string col in NumericTotalColumns)
                {
                    string text = dataItem[col].Text;
 
                    // Probably a better way to do this than a few zero strings, but works for demo
                    if (text == "0.0000" || text == "0.00" || text == "0")
                    {
                        dataItem[col].Text = "";
                    }
 
                    // Add standard numeric class
                    dataItem[col].CssClass = "lbm row_total_cell";
 
                    // class to make negative values red
                    if (text.StartsWith("-"))
                    {
                        dataItem[col].CssClass += " lbml";
                    }
                }
            }
 
            if (e.Item is GridFooterItem)
            {
                GridFooterItem dataItem = e.Item as GridFooterItem;
 
 
                //
                // Row Totals
                //
                string[] NumericDataColumns = {
                                "mAmt0", "mAmt1", "mAmt2", "mAmt3", "mAmt4", "mAmt5", "mAmt6", "mAmt7", "mAmt8", "mAmt9",
                                "mAmtOther"};
 
                foreach (string col in NumericDataColumns)
                {
                    dataItem[col].CssClass = "lbm col_total_cell";
 
 
                    // class to make negative values red
                    if (dataItem[col].Text.StartsWith("-"))
                    {
                        dataItem[col].CssClass += " lbml";
                    }
                }
 
                string[] NumericTotalColumns = { "mTotalAmt" };
 
                foreach (string col in NumericTotalColumns)
                {
                    dataItem[col].CssClass = "lbm table_total_cell";
 
 
                    // class to make negative values red
                    if (dataItem[col].Text.StartsWith("-"))
                    {
                        dataItem[col].CssClass += " lbml";
                    }
                }
            }
            if (e.Item is GridGroupFooterItem)
            {
                GridGroupFooterItem dataItem = e.Item as GridGroupFooterItem;
 
 
                //
                // Row Totals
                //
                string[] NumericDataColumns = {
                                "mAmt0", "mAmt1", "mAmt2", "mAmt3", "mAmt4", "mAmt5", "mAmt6", "mAmt7", "mAmt8", "mAmt9",
                                "mAmtOther"};
 
                foreach (string col in NumericDataColumns)
                {
                    dataItem[col].CssClass = "lbm col_total_cell";
 
 
                    // class to make negative values red
                    if (dataItem[col].Text.StartsWith("-"))
                    {
                        dataItem[col].CssClass += " lbml";
                    }
                }
 
                string[] NumericTotalColumns = { "mTotalAmt" };
 
                foreach (string col in NumericTotalColumns)
                {
                    dataItem[col].CssClass = "lbm table_total_cell";
 
 
                    // class to make negative values red
                    if (dataItem[col].Text.StartsWith("-"))
                    {
                        dataItem[col].CssClass += " lbml";
                    }
                }
            }
        }
0
Viktor Tachev
Telerik team
answered on 15 Aug 2014, 12:47 PM
Hi Joel,

I tried replicating the problematic behavior, however I was unable to. I am attaching a sample project I used for testing. Expanding and collapsing a group in the RadGrid seems to work as expected on my end. Would you take a look at it and let me know if I am missing something? I would appreciate it if you could let me know what should be changed in the sample in order for the issue to be replicated.

On a side note, if you have Ajax enabled on the page would you disable it and see if the behavior changes? You could set the EnableAjax property of RadAjaxManager to false in order to disable Ajax.

Regards,
Viktor Tachev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Joel
Top achievements
Rank 1
Answers by
Joel
Top achievements
Rank 1
Princy
Top achievements
Rank 1
Viktor Tachev
Telerik team
Share this question
or