We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Conditional cell merging

Hi,

I want to merge cells in both direction based on cell value like below example.

Col1 Col2 Col3 Col4
0 0 0 1
1 2
2 3
1 3 4
4 5

In Col2, row1 & row2 can be merged only if Col1 value is same. I tried to do this using mergeCellInfo event. Am able to merge row1 & row1 for Col1. AM not able to add the row3 to the already merged cell. What is the right approach to do this ? 

Thanks
Kumaran



1 Reply

AS Alan Sangeeth S Syncfusion Team January 27, 2017 10:08 AM UTC

Hi Kumaran, 

To add a row to the already merged cell, traverse to the sibling element which has defined ‘rowSpan’ attribute and modify its value. Please refer the following code example. 
$("#Grid").ejGrid({ 
 
mergeCellInfo: function (args) { 
                             
if (args.data.EmployeeID == 10005) { 
 if (args.column.field == "9:00" && args.data[args.column.field] == "Check Mail"){ 
  var cellEle =getParentElement($(args.cell)); 
   var rowSpan = cellEle.attr("rowSpan"); 
  cellEle.attr("rowSpan", ++rowSpan); 
 } 
} 
                } 
            }); 
        }); 
        function getParentElement(cell) { 
            var index = cell.index(); 
            var cellEle = cell.closest("tr").prev("tr").find("td").eq(index); 
            if (cellEle.hasClass("e-hide")) 
                return getParentElement(cellEle); 
            else 
                return cellEle; 
        } 


For your convenience, we have created a sample and the same be downloaded from below location 


Regards,
Alan Sangeeth S 


Loader.
Up arrow icon