From 17e901e928ad2cbfa23c5cf54d5038f49bb70255 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 11 Oct 2017 17:03:27 +0300 Subject: [PATCH 1/4] Fix: Resizing not working if there are no header or footer. The possible absence of a header and a footer when calculating the height of the container for table rows and rows count is taken into account. --- features/pageResize/dataTables.pageResize.js | 8 ++++++-- features/pageResize/dataTables.pageResize.min.js | 8 +------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/features/pageResize/dataTables.pageResize.js b/features/pageResize/dataTables.pageResize.js index cd9a0bf..cef5aca 100644 --- a/features/pageResize/dataTables.pageResize.js +++ b/features/pageResize/dataTables.pageResize.js @@ -75,8 +75,12 @@ PageResize.prototype = { // Subtract the height of the header, footer and the elements // surrounding the table if ( ! scrolling ) { - availableHeight -= settings.header.height(); - availableHeight -= settings.footer.height(); + if ( t.header() ) { + availableHeight -= settings.header.height(); + } + if ( t.footer() ) { + availableHeight -= settings.footer.height(); + } } availableHeight -= offsetTop; availableHeight -= settings.container.height() - ( offsetTop + settings.table.height() ); diff --git a/features/pageResize/dataTables.pageResize.min.js b/features/pageResize/dataTables.pageResize.min.js index d5b0c35..e19f898 100644 --- a/features/pageResize/dataTables.pageResize.min.js +++ b/features/pageResize/dataTables.pageResize.min.js @@ -1,7 +1 @@ -/*! - PageResize for DataTables v1.0.0 - 2015 SpryMedia Ltd - datatables.net/license -*/ -(function(c){var d=function(a){var b=a.table();this.s={dt:a,host:c(b.container()).parent(),header:c(b.header()),footer:c(b.footer()),body:c(b.body()),container:c(b.container()),table:c(b.node())};a=this.s.host;"static"===a.css("position")&&a.css("position","relative");this._attach();this._size()};d.prototype={_size:function(){var a=this.s,b=a.dt,f=b.table(),g=c(a.table).offset().top,d=c("tr",a.body).eq(0).height(),e=a.host.height();f.header().parentNode===f.body().parentNode&&(e-=a.header.height(), -e-=a.footer.height());e=e-g-(a.container.height()-(g+a.table.height()));a=Math.floor(e/d);Infinity!==a&&(-Infinity!==a&&!isNaN(a)&&0").css({position:"absolute",top:0,left:0,height:"100%",width:"100%",zIndex:-1}).attr("type","text/html");b[0].onload=function(){var b=this.contentDocument.body,c=b.offsetHeight;this.contentDocument.defaultView.onresize=function(){var d=b.clientHeight||b.offsetHeight;d!==c&&(c=d,a._size())}}; -b.appendTo(this.s.host).attr("data","about:blank")}};c.fn.dataTable.PageResize=d;c.fn.DataTable.PageResize=d;c(document).on("init.dt",function(a,b){if("dt"===a.namespace){var f=new c.fn.dataTable.Api(b);(c(f.table().node()).hasClass("pageResize")||b.oInit.pageResize||c.fn.dataTable.defaults.pageResize)&&new d(f)}})})(jQuery); +(function(t){var e=function(e){var a=e.table();this.s={dt:e,host:t(a.container()).parent(),header:t(a.header()),footer:t(a.footer()),body:t(a.body()),container:t(a.container()),table:t(a.node())};var o=this.s.host;"static"===o.css("position")&&o.css("position","relative"),this._attach(),this._size()};e.prototype={_size:function(){var e=this.s,a=e.dt,o=a.table(),i=t(e.table).offset().top,n=t("tr",e.body).eq(0).height(),s=e.host.height(),h=o.header().parentNode!==o.body().parentNode;h||(o.header()&&(s-=e.header.height()),o.footer()&&(s-=e.footer.height())),s-=i,s-=e.container.height()-(i+e.table.height());var r=Math.floor(s/n);r!==1/0&&r!==-(1/0)&&!isNaN(r)&&r>0&&r!==a.page.len()&&a.page.len(r).draw()},_attach:function(){var e=this,a=t("").css({position:"absolute",top:0,left:0,height:"100%",width:"100%",zIndex:-1}).attr("type","text/html");a[0].onload=function(){var t=this.contentDocument.body,a=t.offsetHeight;this.contentDocument.defaultView.onresize=function(){var o=t.clientHeight||t.offsetHeight;o!==a&&(a=o,e._size())}},a.appendTo(this.s.host).attr("data","about:blank")}},t.fn.dataTable.PageResize=e,t.fn.DataTable.PageResize=e,t(document).on("init.dt",function(a,o){if("dt"===a.namespace){var i=new t.fn.dataTable.Api(o);(t(i.table().node()).hasClass("pageResize")||o.oInit.pageResize||t.fn.dataTable.defaults.pageResize)&&new e(i)}})})(jQuery); \ No newline at end of file From 652507a0d9b18a813949fe6f73ff8457c15fd13a Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 12 Oct 2017 00:11:21 +0300 Subject: [PATCH 2/4] Add an optional parameter for adjusting the height of the container for table rows manually. It is actual at least when using "angular-datatables v0.5.x" DataTables.net wrapper for AngularJS because it has specific layout. --- features/pageResize/dataTables.pageResize.js | 12 +++++++++--- features/pageResize/dataTables.pageResize.min.js | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/features/pageResize/dataTables.pageResize.js b/features/pageResize/dataTables.pageResize.js index cef5aca..52d3015 100644 --- a/features/pageResize/dataTables.pageResize.js +++ b/features/pageResize/dataTables.pageResize.js @@ -37,7 +37,7 @@ (function($){ -var PageResize = function ( dt ) +var PageResize = function ( dt, pageResizeManualDelta ) { var table = dt.table(); @@ -48,7 +48,8 @@ var PageResize = function ( dt ) footer: $(table.footer()), body: $(table.body()), container: $(table.container()), - table: $(table.node()) + table: $(table.node()), + delta: pageResizeManualDelta }; var host = this.s.host; @@ -71,6 +72,7 @@ PageResize.prototype = { var rowHeight = $( 'tr', settings.body ).eq(0).height(); var availableHeight = settings.host.height(); var scrolling = t.header().parentNode !== t.body().parentNode; + var delta = settings.delta; // Subtract the height of the header, footer and the elements // surrounding the table @@ -85,6 +87,10 @@ PageResize.prototype = { availableHeight -= offsetTop; availableHeight -= settings.container.height() - ( offsetTop + settings.table.height() ); + if ( !isNaN( parseFloat( delta ) ) && isFinite( delta ) ) { + availableHeight -= delta; + } + var drawRows = Math.floor( availableHeight / rowHeight ); if ( drawRows !== Infinity && drawRows !== -Infinity && @@ -149,7 +155,7 @@ $(document).on( 'init.dt', function ( e, settings ) { settings.oInit.pageResize || $.fn.dataTable.defaults.pageResize ) { - new PageResize( api ); + new PageResize( api, settings.oInit.pageResizeManualDelta ); } } ); diff --git a/features/pageResize/dataTables.pageResize.min.js b/features/pageResize/dataTables.pageResize.min.js index e19f898..9faf7d4 100644 --- a/features/pageResize/dataTables.pageResize.min.js +++ b/features/pageResize/dataTables.pageResize.min.js @@ -1 +1 @@ -(function(t){var e=function(e){var a=e.table();this.s={dt:e,host:t(a.container()).parent(),header:t(a.header()),footer:t(a.footer()),body:t(a.body()),container:t(a.container()),table:t(a.node())};var o=this.s.host;"static"===o.css("position")&&o.css("position","relative"),this._attach(),this._size()};e.prototype={_size:function(){var e=this.s,a=e.dt,o=a.table(),i=t(e.table).offset().top,n=t("tr",e.body).eq(0).height(),s=e.host.height(),h=o.header().parentNode!==o.body().parentNode;h||(o.header()&&(s-=e.header.height()),o.footer()&&(s-=e.footer.height())),s-=i,s-=e.container.height()-(i+e.table.height());var r=Math.floor(s/n);r!==1/0&&r!==-(1/0)&&!isNaN(r)&&r>0&&r!==a.page.len()&&a.page.len(r).draw()},_attach:function(){var e=this,a=t("").css({position:"absolute",top:0,left:0,height:"100%",width:"100%",zIndex:-1}).attr("type","text/html");a[0].onload=function(){var t=this.contentDocument.body,a=t.offsetHeight;this.contentDocument.defaultView.onresize=function(){var o=t.clientHeight||t.offsetHeight;o!==a&&(a=o,e._size())}},a.appendTo(this.s.host).attr("data","about:blank")}},t.fn.dataTable.PageResize=e,t.fn.DataTable.PageResize=e,t(document).on("init.dt",function(a,o){if("dt"===a.namespace){var i=new t.fn.dataTable.Api(o);(t(i.table().node()).hasClass("pageResize")||o.oInit.pageResize||t.fn.dataTable.defaults.pageResize)&&new e(i)}})})(jQuery); \ No newline at end of file +(function(t){var e=function(e,a){var o=e.table();this.s={dt:e,host:t(o.container()).parent(),header:t(o.header()),footer:t(o.footer()),body:t(o.body()),container:t(o.container()),table:t(o.node()),delta:a};var i=this.s.host;"static"===i.css("position")&&i.css("position","relative"),this._attach(),this._size()};e.prototype={_size:function(){var e=this.s,a=e.dt,o=a.table(),i=t(e.table).offset().top,n=t("tr",e.body).eq(0).height(),s=e.host.height(),h=o.header().parentNode!==o.body().parentNode,r=e.delta;h||(o.header()&&(s-=e.header.height()),o.footer()&&(s-=e.footer.height())),s-=i,s-=e.container.height()-(i+e.table.height()),!isNaN(parseFloat(r))&&isFinite(r)&&(s-=r);var d=Math.floor(s/n);d!==1/0&&d!==-(1/0)&&!isNaN(d)&&d>0&&d!==a.page.len()&&a.page.len(d).draw()},_attach:function(){var e=this,a=t("").css({position:"absolute",top:0,left:0,height:"100%",width:"100%",zIndex:-1}).attr("type","text/html");a[0].onload=function(){var t=this.contentDocument.body,a=t.offsetHeight;this.contentDocument.defaultView.onresize=function(){var o=t.clientHeight||t.offsetHeight;o!==a&&(a=o,e._size())}},a.appendTo(this.s.host).attr("data","about:blank")}},t.fn.dataTable.PageResize=e,t.fn.DataTable.PageResize=e,t(document).on("init.dt",function(a,o){if("dt"===a.namespace){var i=new t.fn.dataTable.Api(o);(t(i.table().node()).hasClass("pageResize")||o.oInit.pageResize||t.fn.dataTable.defaults.pageResize)&&new e(i,o.oInit.pageResizeManualDelta)}})})(jQuery); \ No newline at end of file From 938b092d23f929ecbc2cd94a03a5011d48a0995f Mon Sep 17 00:00:00 2001 From: ThorbenG <26707299+ThorbenG@users.noreply.github.com> Date: Fri, 13 Oct 2017 14:19:35 +0200 Subject: [PATCH 3/4] Use valid JSON in german translation --- i18n/German.lang | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/i18n/German.lang b/i18n/German.lang index a871f9e..d71afc5 100644 --- a/i18n/German.lang +++ b/i18n/German.lang @@ -28,11 +28,11 @@ "sSortAscending": ": aktivieren, um Spalte aufsteigend zu sortieren", "sSortDescending": ": aktivieren, um Spalte absteigend zu sortieren" }, - select: { - rows: { - _: '%d Zeilen ausgewählt', - 0: 'Zum Auswählen auf eine Zeile klicken', - 1: '1 Zeile ausgewählt' + "select": { + "rows": { + "_": "%d Zeilen ausgewählt", + "0": "Zum Auswählen auf eine Zeile klicken", + "1": "1 Zeile ausgewählt" } } } From 284ebf1251809acdcd86cbcc533596811a6f0eeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Ma=C4=87kowski?= Date: Wed, 8 Nov 2017 11:55:41 +0100 Subject: [PATCH 4/4] Don't use window variable when instantiating Collator This fixes #350 --- sorting/intl.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sorting/intl.js b/sorting/intl.js index 099339f..cb92041 100644 --- a/sorting/intl.js +++ b/sorting/intl.js @@ -71,7 +71,7 @@ $.fn.dataTable.ext.order.intl = function ( locales, options ) { if ( window.Intl ) { - var collator = new window.Intl.Collator( locales, options ); + var collator = new Intl.Collator( locales, options ); var types = $.fn.dataTable.ext.type; delete types.order['string-pre'];