This topic is locked
[SOLVED]

Group by and Merge Grouped cells

5/2/2024 3:55:58 AM
PHPRunner General questions
P
PK author

Hello All,
I have master-detail linked tables. In the designer have grouped one column of the details table and this is how is appears

img alt

But what I actually want to achieve is this below (group and then merge):

img alt

How can I acheive this?

C
cristi 5/4/2024

in the JS onload event of the detail table list page you put this code:

function MergeGridCells(TableID,rCols) {
var dimension_cells = new Array();
var dimension_col = null;
for(Col in rCols) {
dimension_col=rCols[Col];

var first_Hash="";
var first_instance = null;
var rowspan = 1;

$("#"+TableID+"> tbody > tr").children("td").attr('hidden', false);
$("#"+TableID+"> tbody > tr").children("td").attr('rowspan', 1);
$("#"+TableID).find('tr').each(function () {

var dimension_td = $(this).find('td:nth-child(' + dimension_col + ')');
var dim_Hash="";
for(x=1;x<dimension_col;x++){
dim_Hash+=$(this).find('td:nth-child(' + x + ')').text();
}
if (first_instance === null) {

first_instance = dimension_td;
} else if (dimension_td.text() === first_instance.text() && first_Hash === dim_Hash) {

dimension_td.attr('hidden', true);
++rowspan;

first_instance.attr('rowspan', rowspan);
} else {

first_instance = dimension_td;
first_Hash = dim_Hash;
rowspan = 1;
}
});
}
}

MergeGridCells('table_id',[col_numbers]);

For example if you want to merge column 3 rows - as is your case:

MergeGridCells('table_id',[3]);

The table id you get it from web developer tools.

img alt

From the ss above you use it like this:

MergeGridCells('form_grid_1',[3]);

You can also merge multiple columns rows with identical values - maybe you have multiple group by:

MergeGridCells('table_id',[3,4,5, whatever]);

If you want the identical values alligned in the middle of the cells you put this in the element cell custom css:

:host {
vertical-align: middle;
}
P
PK author 5/4/2024

cristi, your solution is brilliant. Thank you!!
Now I have this... Is it possible to have a subtotal for each group (where I inserted the red line in this case)

img alt

P
PK author 5/5/2024

Thank you so much cristi. I will give it a shot