var rids = $('#' + grid).jqGrid('getDataIDs');
var celldataParent = $('#' + grid).jqGrid('getCell', rids[0], groupCol);
var count = 0;
var range = 0;
for (var i = 0; i <= rids.length; i++) {
var celldataCurrent = $('#' + grid).jqGrid('getCell', rids[i], groupCol);
if (celldataCurrent == celldataParent) {
count++;
}
else {
for (var k = 0; k < count; k++) {
if (k == 0) {
$('#' + grid).jqGrid('setCell', rids[range + k], 'cb', '', 'visible-cell');
SetRowSpan(grid, count);
}
else {
$('#' + grid).setCell(rids[range + k], 'cb', '', 'hide-cell');
}
}
celldataParent = celldataCurrent;
range = range + count;
count = 1;
}
}
removeCol(grid);
}
function SetRowSpan(grid, n) {
$('#' + grid + ' tr').each(function () {
if (n > 1) {
$(this).find(".visible-cell").attr("rowspan", n);
}
});
$('#' + grid + ' tr').each(function () {
$(this).find(".visible-cell").removeClass("visible-cell");
});
}
function removeCol(grid) {
$('#' + grid + ' tr').each(function () {
$(this).find(".hide-cell").hide();
});
$('#' + grid).each(function () {
$(this).find(".jqgroup ui-row-ltr").hide();
});
}
function DoSort(a, b) {
var LastColName = "id";
for (var p in a) {
LastColName = p;
}
for (var p in a) {
for (var q in SortingColumnName) {
if (p == SortingColumnName[q]) {
x = a[p].toString().toLowerCase();
y = b[p].toString().toLowerCase();
if (x != y) {
if (x < y) return -1;
if (x > y) return 1;
return 0;
}
}
}
if (p == LastColName) {
return 0;
}
}
}
function MergeGridCellGroupWise(grid, ColumnNameList) {
for (var y = 0; y <= ColumnNameList.length - 1; y++) {
$.extend({
threadedEach: MergeCell(grid, y, ColumnNameList)
});
}
RemoveClass(grid);
}
function MergeCell(grid, Index, ColumnNameList) {
var i = 0;
var row = 0;
var celldataParent = '';
var count = 0;
var span = 1;
var groupcount = 0;
var cellObjectParent = null;
var cellClassParent = '';
var celldataCurrent = '';
var cellClassCurrent = '';
var obj = null;
$('#' + grid + ' tbody tr td').each(function () {
if (i > 0) {
obj = $(this);
if (obj.attr('aria-describedby') == grid + '_' + ColumnNameList[Index]) {
if (count == 0) {
celldataParent = obj.html();
cellClassParent = obj.context.className;
groupcount++;
SetClass(grid, row, Index, groupcount, ColumnNameList);
cellObjectParent = obj;
}
else {
celldataCurrent = obj.html();
cellClassCurrent = obj.context.className;
}
if (Index > 0) {
if (cellClassCurrent == cellClassParent) {
if (celldataCurrent == celldataParent) {
span++;
obj.hide();
if (span > 1) {
cellObjectParent.attr('rowspan', span);
}
SetClass(grid, row, Index, groupcount, ColumnNameList);
}
else if (celldataCurrent != celldataParent) {
if (count != 0) {
count = 0;
groupcount++;
span = 1;
celldataParent = obj.html();
cellClassParent = obj.context.className;
cellObjectParent = obj;
SetClass(grid, row, Index, groupcount, ColumnNameList);
}
}
}
else if (cellClassCurrent != cellClassParent) {
if (count != 0) {
count = 0;
groupcount++;
span = 1;
celldataParent = obj.html();
cellClassParent = obj.context.className;
cellObjectParent = obj;
SetClass(grid, row, Index, groupcount, ColumnNameList);
}
}
row++;
count++;
}
if (Index == 0) {
if (celldataCurrent == celldataParent) {
span++;
obj.hide();
if (span > 1) {
cellObjectParent.attr('rowspan', span);
}
SetClass(grid, row, Index, groupcount, ColumnNameList);
}
else {
if (count != 0) {
count = 0;
groupcount++;
span = 1;
celldataParent = obj.html();
cellObjectParent = obj;
SetClass(grid, row, Index, groupcount, ColumnNameList);
}
}
row++;
count++;
}
}
}
i++;
});
}
function SetClass(grid, row, Index, groupcount, ColumnNameList) {
row = row + 1;
$('#' + grid).jqGrid('setCell', row, ColumnNameList[Index + 1], '', ColumnNameList[Index + 1] + '_' + groupcount);
}
function RemoveClass(grid) {
var obj = null;
$('#' + grid + ' tbody tr td').each(function () {
obj = $(this);
obj.removeAttr('Class');
});
}
function MergeFirstGroupCell(grid, groupCol) {
var rids = $('#' + grid).jqGrid('getDataIDs');
var celldataParent = $('#' + grid).jqGrid('getCell', rids[0], groupCol);
var count = 0;
var range = 0;
for (var i = 0; i <= rids.length; i++) {
var celldataCurrent = $('#' + grid).jqGrid('getCell', rids[i], groupCol);
if (celldataCurrent == celldataParent) {
count++;
}
else {
for (var k = 0; k < count; k++) {
if (k == 0) {
$('#' + grid).jqGrid('setCell', rids[range + k], groupCol, '', 'visible-cell');
SetRowSpan(grid, count);
}
else {
$('#' + grid).jqGrid('setCell', rids[range + k], groupCol, '', 'hide-cell');
}
}
celldataParent = celldataCurrent;
range = range + count;
count = 1;
}
}
removeCol(grid);
}
Call merge grid cell into grid load complete
loadComplete: function () {
MergeGridColumn();
}
function MergeGridColumn() {
if ($("#grid").getGridParam("records") != 0) {
MergeGridCellGroupWise('grid', SortingColumnName = ["Column1", "Column2", "Column3", "Column4", "Column5"]);
MergeFirstGroupCell('grid', 'Column1');
MergeFirstGroupCell('grid', 'Column2');
MergeFirstGroupCell('grid', 'Column3');
MergeCheckboxCell('grid', 'Column4');
MergeFirstGroupCell('grid', 'Column5');
}
}
0 Comments