Better row limiting by using CSS instead of grid's average height

This commit is contained in:
Nathan Gray 2015-02-19 17:16:39 +00:00
parent a6bb56d2e1
commit 904bc8b19f

View File

@ -1953,30 +1953,20 @@ var et2_nextmatch = et2_DOMWidget.extend([et2_IResizeable, et2_IInput, et2_IPrin
defer.reject();
return;
}
if(value < total)
{
// Set height to the requested number of rows, using the average height.
// We add one, in case there's some larger rows we
// try to get most of it but that's pretty hacky
nm.controller._grid.setScrollHeight(nm.controller._grid.getAverageHeight() * (value+1));
}
// Use CSS to hide all but the requested rows
// Prevents us from showing more than requested, if actual height was less than average
nm.print_row_selector = ".egwGridView_grid > tbody > tr:not(:nth-child(-n+"+value+"))";
egw.css(nm.print_row_selector, 'display: none');
// No scrollbar in print view
$j('.egwGridView_scrollarea',this.div).css('overflow-y','hidden');
// Show it all
$j('.egwGridView_scrollarea',this.div).css('height','auto');
// Grid needs to redraw before it can be printed, so wait
window.setTimeout(jQuery.proxy(function() {
dialog.destroy();
if(value < total)
{
// Show requested number, based on average height
nm.controller._grid.setScrollHeight(nm.controller._grid.getAverageHeight() * (value));
// No scrollbar in print view
$j('.egwGridView_scrollarea',this.div).css('overflow-y','hidden');
}
else
{
// Show it all
$j('.egwGridView_scrollarea',this.div).css('height','auto');
}
// Should be OK to print now
defer.resolve();
},nm),ET2_GRID_INVALIDATE_TIMEOUT);
@ -1991,7 +1981,15 @@ var et2_nextmatch = et2_DOMWidget.extend([et2_IResizeable, et2_IInput, et2_IPrin
else
{
// Don't need more rows, limit to requested and finish
this.controller._grid.setScrollHeight(this.controller._grid.getAverageHeight() * (value));
// Show it all
$j('.egwGridView_scrollarea',this.div).css('height','auto');
// Use CSS to hide all but the requested rows
// Prevents us from showing more than requested, if actual height was less than average
this.print_row_selector = ".egwGridView_grid > tbody > tr:not(:nth-child(-n+"+value+"))";
egw.css(this.print_row_selector, 'display: none');
// No scrollbar in print view
$j('.egwGridView_scrollarea',this.div).css('overflow-y','hidden');
// Give dialog a chance to close, or it will be in the print
@ -2017,10 +2015,29 @@ var et2_nextmatch = et2_DOMWidget.extend([et2_IResizeable, et2_IInput, et2_IPrin
}
// Don't return anything, just work normally
},
/**
* Try to clean up the mess we made getting ready for printing
* in beforePrint()
*/
afterPrint: function() {
this.div.removeClass('print');
// Put scrollbar back
$j('.egwGridView_scrollarea',this.div).css('overflow-y','');
// Correct size of grid, and trigger resize to fix it
this.controller._grid.setScrollHeight(this.old_height);
delete this.old_height;
// Remove CSS rule hiding extra rows
if(this.print_row_selector)
{
egw.css(this.print_row_selector, false);
delete this.print_row_selector;
}
this.dynheight.outerNode.css('max-width','inherit');
this.resize();
}