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

[Solved] Hide Column and respective Column Group in a Detail View

1 Answer 94 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Luciano Kaesemodel
Top achievements
Rank 1
Luciano Kaesemodel asked on 24 Jul 2012, 01:02 PM
Hi,

   I have a update problem with Detail View when I try to hide some column. So the scenario starts like the grid 3.png and I have a filter that you can choose which column will be shown. The 1.png it is a expansion of 1 detail of the main grid with all columns, with a green border it is a peace of the filter that shows the 2 group columns. The problem starts when I unchecked one of the column groups and I open one more detail view of the main grid. like in the 2.png. The first detail table don't update correctly and just hide peace of the columns, when I open a third detail the columns are completely hidden. The update bug comes from the ColumnGroup inside a DetailTable.

   The method called when I open a detail view is:
OnDetailTableDataBind="rgdPesquisa_OnDetailTableDataBind"

The method simplified:
protected void rgdPesquisa_OnDetailTableDataBind(object __sender, GridDetailTableDataBindEventArgs __e)
{
    //get the id of main grid
    var _idLinha = Convert.ToString(__e.DetailTableView.ParentItem.GetDataKeyValue("ID"));
 
    //cblTrecho.Items is the CheckBoxList filter
    foreach (ListItem e in cblTrecho.Items)
    {
        //the value of the ListItem is the UniqueName of the GridBoundColumn
         
        //e.Value + "_kma" is like the "km incial" of the print screens
        __e.DetailTableView.GetColumn(e.Value + "_kma").Visible = e.Selected;
         
        //e.Value + "_kmb" is like the "km final" of the print screens
        __e.DetailTableView.GetColumn(e.Value + "_kmb").Visible = e.Selected;
         
        //e.Value + "_nome" is like the "Perfil" or "Fixação" of the print screens
        __e.DetailTableView.GetColumn(e.Value + "_nome").Visible = e.Selected;
    }
     
    //more code to make the query and fill the DataSource
     
    __e.DetailTableView.DataSource = trecho.retornaListaCaracteristicas();
}

Thank you.

1 Answer, 1 is accepted

Sort by
0
Accepted
Marin
Telerik team
answered on 27 Jul 2012, 12:12 PM
Hello,

 The problem is that you hide columns in the DetailTableDataBind event which is called to bind only the current detail table that will be expanded so the code is not executed for the other detail tables. That's why it is a better approach to move the code to a later event (for example in Page_PreRender) and execute it for each detail table that is expanded. This should resolve the problem. Here is a sample code:

protected void Page_PreRender(object sender, EventArgs e)
    {
        foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
        {
            if (item.Expanded)
            {
                item.ChildItem.NestedTableViews[0].GetColumn("DetailID").Visible = false;
                item.ChildItem.NestedTableViews[0].GetColumn("Test").Visible = false;
                item.ChildItem.NestedTableViews[0].GetColumn("Child").Visible = false;
                item.ChildItem.NestedTableViews[0].Rebind();
            }
        }
    }

Regards,
Marin
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Luciano Kaesemodel
Top achievements
Rank 1
Answers by
Marin
Telerik team
Share this question
or