69 lines
2.6 KiB
JavaScript
69 lines
2.6 KiB
JavaScript
var resizeFreez = function (tableId, scope) {
|
|
//var start = new Date();
|
|
//console.log('cell resizing started ' + start);
|
|
var t = $("#" + tableId);
|
|
|
|
var thsWidthI = 0;
|
|
var tr = t.find("tr:eq(1)");
|
|
var ths = tr.find("th");
|
|
var thNameWidth = ths.eq(1).width();
|
|
|
|
var dateThs = ths.filter(":gt(2):visible");
|
|
if (dateThs.length == 0)
|
|
return;
|
|
var visibleColumns = 0;
|
|
ths.filter(":visible").each(function (i, o) {
|
|
thsWidthI += $(o).innerWidth();
|
|
visibleColumns++;
|
|
});
|
|
var divWidthI = t.parent().parent().innerWidth();
|
|
var longestCategory = 0;
|
|
t.find("td:nth-child(2)").each(function (i, td) {
|
|
var text = $(td).html();
|
|
var txtElement = $("<td></td>").html(text).css({
|
|
'class': "headcol"
|
|
}).prependTo($(td).parent());
|
|
longestCategory = Math.max(longestCategory, txtElement.width());
|
|
txtElement.remove();
|
|
});
|
|
var delta = 0;
|
|
if (thsWidthI > divWidthI) {
|
|
// if width of all columns > visible table then we need to shrink name column to the width of smallest category name
|
|
delta = -Math.min(thNameWidth - longestCategory, thsWidthI - divWidthI + visibleColumns + 1);
|
|
} else if (thsWidthI < divWidthI) {
|
|
delta = divWidthI - thsWidthI - visibleColumns - 1;
|
|
}
|
|
if (delta == 0)
|
|
return;
|
|
t.find("tbody tr td:nth-child(2)").each(rszObj, [delta, null, null]);
|
|
t.find("th:nth-child(2)").each(rszObj, [delta, null, null]);
|
|
t.find("tfoot td:first").each(rszObj, [delta, null, null]);
|
|
t.find("tbody tr td:nth-child(3)").each(rszObj, [null, delta, null]);
|
|
t.find("th:nth-child(3)").each(rszObj, [null, delta, null]);
|
|
t.find("tfoot td:eq(1)").each(rszObj, [null, delta, null]);
|
|
var total3Width = ths.eq(0).outerWidth() + ths.eq(1).outerWidth() + ths.eq(2).outerWidth();
|
|
t.parent().each(rszObj, [null, null, total3Width - 1]);
|
|
|
|
//var end = new Date();
|
|
//console.log("## cell resizing took: " + (end - start) + " ms");
|
|
return;
|
|
};
|
|
|
|
function rszObj(deltaWidth, deltaLeft, padLeft) {
|
|
if (deltaWidth != null && deltaWidth != 0) {
|
|
var oldWidth = $(this).width();
|
|
$(this).css('width', oldWidth + deltaWidth);
|
|
}
|
|
if (deltaLeft != null && deltaLeft != 0) {
|
|
var oldLeft = $(this).css('left');
|
|
if (oldLeft != null && oldLeft.length > 0) {
|
|
var l = parseInt(oldLeft.substr(0, oldLeft.length - 1));
|
|
if (!isNaN(l))
|
|
$(this).css('left', l + deltaLeft);
|
|
}
|
|
}
|
|
if (padLeft != null && !isNaN(padLeft)) {
|
|
$(this).css('padding-left', padLeft);
|
|
}
|
|
}
|