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

Merge header columns

5 Answers 202 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Minkyu Lee
Top achievements
Rank 1
Minkyu Lee asked on 31 Aug 2010, 10:54 AM
Hello,

Can I create the following table?

 

 

A

B

C

D

E

I

F

G

H

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 
I would like to merge some of the columns.

Can you show me a sample code?


Thank you for your help.
Minkyu Lee.

5 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 31 Aug 2010, 12:03 PM
Hello,


The following documentation shows how to customize the RadGrid header using GridTemplateColumn.
Customizing with GridTemplateColumn

I think, this is what you are searching for.


-Shinu.
0
Minkyu Lee
Top achievements
Rank 1
answered on 01 Sep 2010, 02:36 AM
Wow!! Great.

Thank you Shinu.

I have one more question.

As shown in the table below, can I merge the rows?

 

Singer 

Song 

C

D

E

I

F

G

H

Michael Jackson

  Billie Jean

 

 

 

 

 

  Thriller

 

 

 

 

 

Stevie Wonder 

  Lately

 

 

 

 

 

  Isn't She Lovely

 

 

 

 

 

 Superstition

 

 

 

 

 

 

0
Accepted
Shinu
Top achievements
Rank 2
answered on 01 Sep 2010, 05:31 AM
Hello,


It is possible to merge the cells having same values by increasing the RowSpan for the cells. Take a look at the following code.

C#:
protected void RadGrid1_PreRender(object sender, EventArgs e)  
{  
    for (int rowIndex = RadGrid1.Items.Count - 2; rowIndex >= 0; rowIndex--)  
    {  
        GridDataItem row = RadGrid1.Items[rowIndex];  
        GridDataItem previousRow = RadGrid1.Items[rowIndex + 1];  
 
        for (int i = 0; i < row.Cells.Count; i++)  
        {  
            if (row.Cells[i].Text == previousRow.Cells[i].Text)  
            {  
                row.Cells[i].RowSpan = previousRow.Cells[i].RowSpan < 2 ? 2 : previousRow.Cells[i].RowSpan + 1;  
                previousRow.Cells[i].Visible = false;  
            }  
        }  
    }   
}

In this example, if a cell value is the same as a value in the next (lower) row, then its RowSpan is increased and the lower cell is made invisible.


Happy coding,
Shinu.
0
Minkyu Lee
Top achievements
Rank 1
answered on 06 Sep 2010, 12:48 AM
Thank you Shinu.
0
Jason
Top achievements
Rank 1
answered on 31 Aug 2011, 01:33 AM
Is it possible to achieve the same merged header cells using the WPF Q1 2011 version?

We really need this functionality to manage grids with many columns that really need to be grouped together and still allowed to be sortable.


Thanks

JW
Tags
Grid
Asked by
Minkyu Lee
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Minkyu Lee
Top achievements
Rank 1
Jason
Top achievements
Rank 1
Share this question
or