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

Can I Use html code like <td rowsapn=2> in grid

4 Answers 233 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Yoon-Ho Choi
Top achievements
Rank 1
Yoon-Ho Choi asked on 30 Mar 2010, 10:18 AM
Hi, All.

I want to merge some item in grid

Not Header But Item

Can I do this in grid?

Count Name
5 name1
name2
name3
name4
name5
4 name1
name2
name3
name4


God regards you

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 30 Mar 2010, 11:38 AM

Hello,

You can merge the cells having same values using 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.

-Shinu.

0
Yoon-Ho Choi
Top achievements
Rank 1
answered on 01 Apr 2010, 07:09 AM
Thank you Shinu

It's very helpful..
0
Tom
Top achievements
Rank 1
answered on 12 Apr 2016, 01:42 PM

I wanted to do this same thing, but on a grid that is bound on the client side. Here is the above solution for this case, using an onDataBound client event.

Note that in Shinu's code above, the function checks every column for shared values between rows. In the code below, I have a column with the UniqueName "num" that is the column I want to merge.

function rgDataBound(sender, args) {
    var rows = sender.get_masterTableView().get_dataItems();
    var nRows = rows.length;
    if (nRows > 1) {
      for (var r = nRows - 2; r >= 0; r--) {
        var row = rows[r];
        var prevRow = rows[r + 1];
        if (row.get_dataItem().num == prevRow.get_dataItem().num) {
          row.get_cell("num").rowSpan = prevRow.get_cell("num").rowSpan < 2 ? 2 : prevRow.get_cell("num").rowSpan + 1;
          prevRow.get_cell("num").style.display = "none";
        }
      }
    }
  }

0
Eyup
Telerik team
answered on 15 Apr 2016, 01:29 PM
Hello Tom,

Generally, merging rows or cells is not supported by default and thus beyond our support scope. You can try your own custom approaches based on your requirements.

Regards,
Eyup
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
Grid
Asked by
Yoon-Ho Choi
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Yoon-Ho Choi
Top achievements
Rank 1
Tom
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or