Merging Unmergin Table Cells
Hi Guys,
Here is the issue I'm currently having.
I have a HTML table with five columns and 50 rows. some of the cells in the columns have repeated text that I would like to have the option to merge or unmerge. Here is my merge function
- function mergeGridCells()
- {
- var dimension_col = null;
-
- dimension_col = 1;
-
- // first_instance holds the first instance of identical td
- var first_instance = null;
- var rowspan=1;
- var columnCount = $("#mainTable tr:first th").length;
-
- for (dimension_col = 1; dimension_col <= columnCount; dimension_col++) {
- var first_instance = null;
- var rowspan = 1;
- $("#mainTable").find('tr:visible').each(function() {
- var dimension_td = $(this).find('td:nth-child(' + dimension_col + '):visible');
- if (first_instance == null) {
- // must be the first row
- first_instance = dimension_td;
- } else if (dimension_td.text() == first_instance.text()) {
- // the current td is identical to the previous
- // remove the current td
- //var myBg = dimension_td.css('background-color');
- dimension_td.hide();
- ++rowspan;
- // increment the rowspan attribute of the first instance
- first_instance.attr('rowspan', rowspan);
- first_instance.css('vertical-align', 'middle');
- first_instance.css('background-color', '#FFFFFF');
- } else {
- // this cell is different from the last
- first_instance = dimension_td;
- rowspan=1;
- }
- });
- }
This function works great in all browser (Chrome, IE/EDGE, Firefox, Opera) the problem is when I try to unmerge the cells once they have been merge. Here is the function I'm currently using to unmerge the cells.
- function unmergeCells() {
- $temp = $("#mainTable td[rowspan]");
-
- $temp.each(function() {
- $(this).attr("rowspan", "0");
- });
-
- $("#mainTable td:hidden").show();
-
- $("#mainTable td").css("background-color","");
- $("#mainTable tr:not(:has(th))").css("background-color","#FFFFFF");
- $("#mainTable tr:not(:has(th)):odd").css("background-color","#D4D4D4");
- }
this function works well with Chrome and Opera but not in Firefox/Edge. Is there a way I can improve the code to make it work in firefox/Edge?
Any help will be greatly appreciated.