I need to display data in grid view with merged rows for some columns. Please help me to prepare a grid view in below defined format:
And the original data comes from database is in below format:
Please help me to find best way for doing this task dynamically and efficiently.
Hi Jinchul,
Thanks for contacting Syncfusion Support.
Use “AllowCellMerging” property of Grid to enable the cell merging feature in Grid Control. Using “MergeCellInfo” event of Grid we can customize cells to be merged. Please refer to the code example, online sample link and online document link:
<ej:Grid ID="EmployeeGrid" runat="server" AllowCellMerging="true"> <ClientSideEvents MergeCellInfo ="cellmerge" /> . . . </ej:Grid> function cellmerge(args) { //Merging the cells based on condition } |
https://asp.syncfusion.com/demos/web/grid/cellmerging.aspx
https://help.syncfusion.com/api/js/ejgrid#events:mergecellinfo
https://help.syncfusion.com/api/js/ejgrid#members:allowcellmerging
We have created a sample that you can download from the below link.
https://www.syncfusion.com/downloads/support/forum/121068/ze/F121068-237097166
Regards,
Saravanan A.
http://asp.syncfusion.com/demos/web/grid/cellmerging.aspx
http://help.syncfusion.com/js/api/ejgrid#events:mergecellinfo
http://help.syncfusion.com/js/api/ejgrid#members:allowcellmerging
function cellmerge(args) { var cell = args.cell;
var cellIndex = args.cell.cellIndex var prevvRow = $(args.cell).closest("tr").prev();
var prevCell = $(args.cell).closest("tr").prev().find("td:eq(“+cellIndex+”)")
if(cell.text() == prevCell.text()) args.merge(prevRow.rowIndex, $(args.cell).closest("tr")[0].rowIndex) } |
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent"> <div> <ej:Grid ID="FlatGrid" runat="server" AllowCellMerging="true" AllowSorting="True" AllowPaging="True" IsResponsive="true"> ..... <ClientSideEvents MergeCellInfo ="cellmerge" /> </ej:Grid> </div> <script> function cellmerge(args) { if (args.column.field == "ShipCity" && !$(args.cell).hasClass("e-merged")) { var rowInx = this.getIndexByRow(args.cell.closest("tr")); var merInx = rowInx; var pageSize = this.model.currentViewData.length; var prevRow = null, nexRow = null; var data = ej.DataManager(this.model.currentViewData).executeLocal(new ej.Query().where("ShipCity", "equal", args.data["ShipCity"])); for (var inx = 0; inx < data.length; inx++) { var currentdata = this.model.currentViewData; if (currentdata.indexOf(data[inx]) == merInx) continue; else if (merInx + 1 == currentdata.indexOf(data[inx])) merInx++; else break; } if (rowInx != merInx) args.rowMerge(merInx - rowInx + 1); } } </script> </asp:Content> |