// function to hide column(s) in array (number) with empty header // remaining columns are stretched to original total width // "table.questions-list" is default to find the input table -- may be this can be defined more accurate? // function hideEmptyColumns(tableIdentifyer = "table.questions-list") { $(tableIdentifyer).each(function(){ var basetable=$(this); var i = 0; var p = 0; var hiddenPos = []; var remainPos = []; var oldWidth = []; var oldWidthPercentages = []; var sumRemainWidth = 0; var sumOldWidth = 0; var stretchFactor = 0; var dummy = ""; // works with thead in LS 3.18 former version worked with col (why?) $(this).find("thead tr.ls-heading th").each(function(){ // save the index of those cols that are to hide and those who remain visible => how to do with valudation? if($.trim($(this).html())===""){ hiddenPos.push(i); } else { remainPos.push(i); } oldWidth.push($(this).width()); i = i + 1; }); // calculate the sum with of all cols as they are without shrink sumOldWidth = oldWidth.reduce(function(a,b){ return a + b; }); // recalculate the old *percentages* of all columns oldWidth.forEach(function(w){ oldWidthPercentages.push(w/sumOldWidth*100); }); // calculate the sum width of only the remaining cols for (p of remainPos) { sumRemainWidth += oldWidth[p -1]; } // calculate the stretch factor stretchFactor = sumOldWidth/sumRemainWidth; // hide all columns with empty header but not col 1 for (p of hiddenPos) { i= p+1; $(tableIdentifyer + " th:nth-child("+ i + ")").hide(); $(tableIdentifyer + " td:nth-child("+ i + ")").hide(); } // refresh the column css width attributes, but let first column as it was dummy = "'" + oldWidthPercentages[0] + "%" + "'"; $(tableIdentifyer + ' col:nth-child(0)').css({ 'width': dummy }); // set hidden cols to 0% p = remainPos.length + 2; for (i of hiddenPos) { $(tableIdentifyer + " col:nth-child(" + p + ")").css({ 'width': '0%' }); p = p + 1; } // stretch visible cols, line title with original width first p = 0; i = 1; dummy = oldWidthPercentages[p] + "%" ; $(tableIdentifyer + " col:nth-child(" + i + ")").css({ 'width': dummy }); // now answer columns p = 2; for(i of remainPos) { dummy = oldWidthPercentages[i] * stretchFactor + "%"; $(tableIdentifyer + " col:nth-child(" + p + ")").css({ 'width': dummy }); p = p + 1; } }); }