Nice fix for sScrollY='100%' (download at the end) - I know you wanted it

Nice fix for sScrollY='100%' (download at the end) - I know you wanted it

hidekiyamamotohidekiyamamoto Posts: 1Questions: 0Answers: 0
edited January 2014 in FixedHeader
OPENUNO 20140113 first rev 0 - REFERRING TO datatables.js v 1.9.4

-Summary:
--Using the option sScrollY='100%' will work very well without any other information.
--For few pixel adjustation, a new option is added (nScrollYModifier). nScrollYModifier it's a number of pixel, it can be positive on negative.

NOTE VERY WELL : ONLY "100%" WILL WORK, untill the next rev?.
TODO1:Cleanup this one event being added when destroying. Calculate other percentages.
TODO2:Add compatibility enabling sScrollY='auto'.


List of modifications:
1--------------------------------------------------------------------------------------
About Line 3145 (or search code for comment /* When yscrolling, add the height */):
-REPLACE:
nScrollBody.style.height=_fnStringToCss(oSettings.oScroll.sY);
-WITH:
//MOD BY OPENUNO 20140113 first rev 0
if(oSettings.oScroll.sY=='100%'){var ph=(jQuery(document.body).height()*0.99);ph+=oSettings.oScroll.nYM;ph-=jQuery(nScrollHeadInner).height();ph-=jQuery(nScrollFootTable).height();nScrollBody.style.height=ph+'px';$(window).on('resize',function(){_fnUpdateScrollY(nScrollBody.parentNode.parentNode.id,oSettings.oScroll.nYM)});setTimeout(function(){_fnUpdateScrollY(nScrollBody.parentNode.parentNode.id,oSettings.oScroll.nYM)},25);}else{nScrollBody.style.height = _fnStringToCss( oSettings.oScroll.sY );}
2--------------------------------------------------------------------------------------
ABOUT what should now be line 3183
-INSERT A NEW FUNCTION:
// MOD BY OPENUNO 20140113 rev 0 - event handler on resize, event is binded in previous code, only if the scrolling Y is set to a percentage.
function _fnUpdateScrollY(id,fix){var ph=(jQuery(document.body).height()*0.99);ph-=jQuery('#'+id).offset().top;ph+=fix;ph-=jQuery('#'+id+' .dataTables_scroll .dataTables_scrollHead').height();ph-=jQuery('#'+id+' .dataTables_scroll .dataTables_scrollFoot').height();ph-=jQuery('#'+id+' .dataTables_info').height();ph-=jQuery('#'+id+' .dataTables_filter').height();var x=jQuery('#'+id+' .dataTables_scroll .dataTables_scrollBody').css('height',ph+'px');}
3--------------------------------------------------------------------------------------
ABOUT what should now be line 3183
-REPLACE:
nScrollBody.style.height = (nScrollBody.offsetHeight + o.nTHead.offsetHeight)+"px";
-WITH:
//MOD BY OPENUNO 20140113 rev 0
if(o.oScroll.sY=='100%'){var ph=(jQuery(document.body).height()*0.99);ph+=o.oScroll.nYM;ph-=jQuery(nScrollBody.parentElement.parentElement).offset().top;ph-=jQuery('#'+nScrollBody.parentElement.parentElement.id+' .dataTables_filter').height();ph-=jQuery(nScrollHeadInner).height();ph-=jQuery(nScrollFootTable).height();ph-=jQuery('#'+nScrollBody.parentElement.parentElement.id+' .dataTables_info').height();}else{nScrollBody.style.height = (nScrollBody.offsetHeight + o.nTHead.offsetHeight)+"px";}
4--------------------------------------------------------------------------------------
ABOUT what should now be line 3451
-REPLACE:
nScrollBody.style.height = _fnStringToCss( o.oScroll.sY );
-WITH:
//MOD BY OPENUNO 20140113 rev 0
if(o.oScroll.sY=='100%'){var ph=(jQuery(document.body).height()*0.99);ph+=o.oScroll.nYM;ph-=jQuery(nScrollBody.parentElement.parentElement).offset().top;ph-=jQuery('#'+nScrollBody.parentElement.parentElement.id+' .dataTables_filter').height();ph-=jQuery(nScrollHeadInner).height();ph-=jQuery(nScrollFootTable).height();ph-=jQuery('#'+nScrollBody.parentElement.parentElement.id+' .dataTables_info').height();nScrollBody.style.height=ph+'px';}else{nScrollBody.style.height = _fnStringToCss( o.oScroll.sY );}
5--------------------------------------------------------------------------------------
ABOUT what should now be line 6471
-ADD THIS NEW CODE:
// MOD BY OPENUNO 20140113 rev 0
if(!oInit.nScrollYModifier){oInit.nScrollYModifier=0;};if(!oInit["nScrollYModifier"]){oInit["nScrollYModifier"]=0;};oSettings.oScroll.nYM=oInit["nScrollYModifier"];_fnMap( oSettings.oScroll, oInit, "nScrollYModifier", "nYM" );
-------------------------------------
NON MINIFIED - DOWNLOADABLE VERSION WITH MODIFICATIONS IN SELECTED LINES :
www - openuno - org /s/jquery/jquery.dataTables-OPENUNO20140113.js


Enjoy.

Replies

  • allanallan Posts: 62,435Questions: 1Answers: 10,246 Site admin
    Thank you for posting this - I'm sure others will find it useful.

    Allan
This discussion has been closed.