Column Spanning

24 Feb 202216 minutes to read

The grid has option to span the adjacent cells. You need to define the colSpan attribute to span cells in the queryCellInfo event.

In the following demo, employee Davolio is doing testing from 9.00 A.M. to 10.00 A.M. so that the cells have been spanned.

<ejs-grid id="Grid" dataSource="@ViewBag.DataSource" queryCellInfo="QueryCellEvent" gridLines="Both" allowPaging="true">
    <e-grid-columns>
        <e-grid-column field="EmployeeID" headerText="Employee ID" isPrimaryKey="true"  textAlign="Right" width="150"></e-grid-column>
        <e-grid-column field="EmployeeName" headerText="Employee Name" width="200"></e-grid-column>
        <e-grid-column field="Time900" headerText="9.00 AM" width="120"></e-grid-column>
        <e-grid-column field="Time930" headerText="9.30 AM" width="120"></e-grid-column>
        <e-grid-column field="Time1000" headerText="10.00 AM" width="120"></e-grid-column>
        <e-grid-column field="Time1030" headerText="10.30 AM" width="120"></e-grid-column>
        <e-grid-column field="Time1100" headerText="11.00 AM" width="120"></e-grid-column>
        <e-grid-column field="Time1130" headerText="11.30 AM" width="120"></e-grid-column>
        <e-grid-column field="Time1200" headerText="12.00 AM" width="120"></e-grid-column>
        <e-grid-column field="Time1230" headerText="12.30 AM" width="120"></e-grid-column>
        <e-grid-column field="Time100" headerText="1.00 PM" width="120"></e-grid-column>
        <e-grid-column field="Time130" headerText="1.30 PM" width="120"></e-grid-column>
        <e-grid-column field="Time200" headerText="2.00 PM" width="120"></e-grid-column>
        <e-grid-column field="Time230" headerText="2.30 PM" width="120"></e-grid-column>
        <e-grid-column field="Time300" headerText="3.00 PM" width="120"></e-grid-column>
        <e-grid-column field="Time330" headerText="3.30 PM" width="120"></e-grid-column>
        <e-grid-column field="Time400" headerText="4.00 PM" width="120"></e-grid-column>
        <e-grid-column field="Time430" headerText="4.30 PM" width="120"></e-grid-column>
        <e-grid-column field="Time500" headerText="5.00 PM" width="120"></e-grid-column>
    </e-grid-columns>          
</ejs-grid>
<script>
 function QueryCellEvent(args)
        {
            var data = args.data;
            switch (data.EmployeeID) {
                case 10001:
                    if (args.column.field === 'Time900' || args.column.field === 'Time230' || args.column.field === 'Time430') {
                        args.colSpan = 2;
                    } else if (args.column.field === 'Time1100') {
                        args.colSpan = 3;
                    }
                    break;
                case 10002:
                    if (args.column.field === 'Time930' || args.column.field === 'Time230' ||
                        args.column.field === 'Time430') {
                        args.colSpan = 3;
                    } else if (args.column.field === 'Time1100') {
                        args.colSpan = 4;
                    }
                    break;
                case 10003:
                    if (args.column.field === 'Time900' || args.column.field === 'Time1130') {
                        args.colSpan = 3;
                    } else if (args.column.field === 'Time1030' || args.column.field === 'Time330' ||
                        args.column.field === 'Time430' || args.column.field === 'Time230') {
                        args.colSpan = 2;
                    }
                    break;
                case 10004:
                    if (args.column.field === 'Time900') {
                        args.colSpan = 3;
                    } else if (args.column.field === 'Time1100') {
                        args.colSpan = 4;
                    } else if (args.column.field === 'Time400' || args.column.field === 'Time230') {
                        args.colSpan = 2;
                    }
                    break;
                case 10005:
                    if (args.column.field === 'Time900') {
                        args.colSpan = 4;
                    } else if (args.column.field === 'Time1130') {
                        args.colSpan = 3;
                    } else if (args.column.field === 'Time330' || args.column.field === 'Time430' || args.column.field === 'Time230') {
                        args.colSpan = 2;
                    }
                    break;
                case 10006:
                    if (args.column.field === 'Time900' || args.column.field === 'Time430' ||
                        args.column.field === 'Time230' || args.column.field === 'Time330') {
                        args.colSpan = 2;
                    } else if (args.column.field === 'Time1000' || args.column.field === 'Time1130') {
                        args.colSpan = 3;
                    }
                    break;
                case 10007:
                    if (args.column.field === 'Time900' || args.column.field === 'Time300' || args.column.field === 'Time1030') {
                        args.colSpan = 2;
                    } else if (args.column.field === 'Time1130' || args.column.field === 'Time400') {
                        args.colSpan = 3;
                    }
                    break;
                case 10008:
                    if (args.column.field === 'Time900' || args.column.field === 'Time1030' || args.column.field === 'Time230') {
                        args.colSpan = 3;
                    } else if (args.column.field === 'Time400') {
                        args.colSpan = 2;
                    }
                    break;
                case 10009:
                    if (args.column.field === 'Time900' || args.column.field === 'Time1130') {
                        args.colSpan = 3;
                    } else if (args.column.field === 'Time430' || args.column.field === 'Time230') {
                        args.colSpan = 2;
                    }
                    break;
                case 100010:
                    if (args.column.field === 'Time900' || args.column.field === 'Time230' ||
                        args.column.field === 'Time400' || args.column.field === 'Time1130') {
                        args.colSpan = 3;
                    } else if (args.column.field === 'Time1030') {
                        args.colSpan = 2;
                    }
                    break;
            }

         }
</script>
public IActionResult Index()
{
    ViewBag.DataSource = Merge.GetAllRecords()
    return View();
}