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

P
PK author 5/19/2024

@cristi,
I am back on this.
The merge works perfectly on tables and I used Fernando's here
to perform the grouping. All nice.

I just realized however that this code does not work with views only tables.
Any trick to making it work on views?

Thanks agian
Percy

fhumanes 5/20/2024

Hello,

My solution works both in tables and views (database or phprunner).

Greetings,
fernando

P
PK author 5/21/2024

Hi Fernando,
Thank you for your response.
True, your solution works perfectly in all cases. The grouping works everywhere. The problem is with merging the cells
And I apologize, becuase I did not clearly understand the problem.
The actual problem is that the merging does not work on the view page because on the view page the column to merge is column 2 and on edit page is is column 3.
And because I am using column 3 in the code, it does not work on the view page.
So I guess my problem is how can I detect if the master table is opening the edit or view page so that I can use a condition in the detail table to change the column number in my code to merge the correct field?
Maybe if I can get the visible state of the "add" button on the detail table I will know if it we are in edit or view mode becuase the "add" button is not visible on the view page.

Thanks

Percy

P
PK author 5/21/2024

OK. This is solved.
I moved the merged column to the be the column 1 so that is always conlum 1 on every page.
Thank you very much

C
cristi 5/22/2024

Glad that you solved.
Sorry for the late reply by I am involved in a big project now that takes all my time.
I written my solution as a function so you can adap it for all the pages if you want....like a method overload in other programming languages (true that javascript does not have function overload but it does not need to...)
So this way you can adapt the code for the design and not the other way around,,,
Fernando's solution can also be modified to work for merging cells like you requested so you can use one approache for two different problems.
I also think that this kind of design should be implemented in PHPRunner by default when using "Group By" because those empty cells can be confusing for some users.

P
PK author 5/22/2024

Thanks cristi,
I will definately be adapting it in other projects. And you are right this should be built in because as you said when a column is grouped, it doesnt make sense to have the values repeating on each line within the group. Good luck with you project.

Thanks again

Percy