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

5 posts, 0 answers
  1. Yoon-Ho Choi
    Yoon-Ho Choi avatar
    22 posts
    Member since:
    Dec 2009

    Posted 30 Mar 2010 Link to this post

    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
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 30 Mar 2010 Link to this post

    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.

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Yoon-Ho Choi
    Yoon-Ho Choi avatar
    22 posts
    Member since:
    Dec 2009

    Posted 01 Apr 2010 Link to this post

    Thank you Shinu

    It's very helpful..
  5. Tom
    Tom avatar
    44 posts
    Member since:
    Oct 2010

    Posted 12 Apr Link to this post

    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";
            }
          }
        }
      }

  6. Eyup
    Admin
    Eyup avatar
    3005 posts

    Posted 15 Apr Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017