diff --git a/features/pageResize/dataTables.pageResize.js b/features/pageResize/dataTables.pageResize.js index 52d30155..48f342b9 100644 --- a/features/pageResize/dataTables.pageResize.js +++ b/features/pageResize/dataTables.pageResize.js @@ -37,19 +37,21 @@ (function($){ -var PageResize = function ( dt, pageResizeManualDelta ) +var PageResize = function ( dt, pageResizeManualDelta, pageResizeDrawPagingParameter, pageResizePreDrawCallback ) { var table = dt.table(); this.s = { - dt: dt, - host: $(table.container()).parent(), - header: $(table.header()), - footer: $(table.footer()), - body: $(table.body()), - container: $(table.container()), - table: $(table.node()), - delta: pageResizeManualDelta + dt: dt, + host: $(table.container()).parent(), + header: $(table.header()), + footer: $(table.footer()), + body: $(table.body()), + container: $(table.container()), + table: $(table.node()), + delta: pageResizeManualDelta, + drawPagingParameter: pageResizeDrawPagingParameter, + preDrawCallback: pageResizePreDrawCallback }; var host = this.s.host; @@ -72,7 +74,9 @@ 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; + var delta = settings.delta; + var pagingObject = { paging: settings.drawPagingParameter }; + var preDrawCallback = settings.preDrawCallback; // Subtract the height of the header, footer and the elements // surrounding the table @@ -95,9 +99,10 @@ PageResize.prototype = { if ( drawRows !== Infinity && drawRows !== -Infinity && ! isNaN( drawRows ) && drawRows > 0 && - drawRows !== dt.page.len() + drawRows !== dt.page.len() && + ( !preDrawCallback || preDrawCallback( drawRows, dt.page.len(), pagingObject ) !== false ) ) { - dt.page.len( drawRows ).draw(); + dt.page.len( drawRows ).draw( pagingObject.paging ); } }, @@ -155,7 +160,7 @@ $(document).on( 'init.dt', function ( e, settings ) { settings.oInit.pageResize || $.fn.dataTable.defaults.pageResize ) { - new PageResize( api, settings.oInit.pageResizeManualDelta ); + new PageResize( api, settings.oInit.pageResizeManualDelta, settings.oInit.pageResizeDrawPagingParameter, settings.oInit.pageResizePreDrawCallback ); } } ); diff --git a/features/pageResize/dataTables.pageResize.min.js b/features/pageResize/dataTables.pageResize.min.js index 29ff7606..c778f828 100644 --- a/features/pageResize/dataTables.pageResize.min.js +++ b/features/pageResize/dataTables.pageResize.min.js @@ -1,30 +1 @@ -/*! - Copyright 2015 SpryMedia Ltd. - - License MIT - http://datatables.net/license/mit - - This feature plug-in for DataTables will automatically change the DataTables - page length in order to fit inside its container. This can be particularly - useful for control panels and other interfaces which resize dynamically with - the user's browser window instead of scrolling. - - Page resizing in DataTables can be enabled by using any one of the following - options: - - * Adding the class `pageResize` to the HTML table - * Setting the `pageResize` parameter in the DataTables initialisation to - be true - i.e. `pageResize: true` - * Setting the `pageResize` parameter to be true in the DataTables - defaults (thus causing all tables to have this feature) - i.e. - `$.fn.dataTable.defaults.pageResize = true`. - * Creating a new instance: `new $.fn.dataTable.PageResize( table );` where - `table` is a DataTable's API instance. - - For more detailed information please see: - http://datatables.net/blog/2015-04-10 - PageResize for DataTables v1.0.0 - 2015 SpryMedia Ltd - datatables.net/license -*/ -(function(b){var e=function(a,c){var d=a.table();this.s={dt:a,host:b(d.container()).parent(),header:b(d.header()),footer:b(d.footer()),body:b(d.body()),container:b(d.container()),table:b(d.node()),delta:c};a=this.s.host;"static"===a.css("position")&&a.css("position","relative");this._attach();this._size()};e.prototype={_size:function(){var a=this.s,c=a.dt,d=c.table(),h=b(a.table).offset().top,e=b("tr",a.body).eq(0).height(),f=a.host.height(),k=d.header().parentNode!==d.body().parentNode,g=a.delta; -k||(d.header()&&(f-=a.header.height()),d.footer()&&(f-=a.footer.height()));f=f-h-(a.container.height()-(h+a.table.height()));!isNaN(parseFloat(g))&&isFinite(g)&&(f-=g);a=Math.floor(f/e);Infinity!==a&&-Infinity!==a&&!isNaN(a)&&0").css({position:"absolute",top:0,left:0,height:"100%",width:"100%",zIndex:-1}).attr("type","text/html");c[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())}};c.appendTo(this.s.host).attr("data","about:blank")}};b.fn.dataTable.PageResize=e;b.fn.DataTable.PageResize=e;b(document).on("init.dt",function(a,c){"dt"===a.namespace&&(a=new b.fn.dataTable.Api(c),(b(a.table().node()).hasClass("pageResize")||c.oInit.pageResize||b.fn.dataTable.defaults.pageResize)&&new e(a,c.oInit.pageResizeManualDelta))})})(jQuery); +(function(e){var t=function(t,a,i,n){var o=t.table();this.s={dt:t,host:e(o.container()).parent(),header:e(o.header()),footer:e(o.footer()),body:e(o.body()),container:e(o.container()),table:e(o.node()),delta:a,drawPagingParameter:i,preDrawCallback:n};var s=this.s.host;"static"===s.css("position")&&s.css("position","relative"),this._attach(),this._size()};t.prototype={_size:function(){var t=this.s,a=t.dt,i=a.table(),n=e(t.table).offset().top,o=e("tr",t.body).eq(0).height(),s=t.host.height(),r=i.header().parentNode!==i.body().parentNode,h=t.delta,l={paging:t.drawPagingParameter},d=t.preDrawCallback;r||(i.header()&&(s-=t.header.height()),i.footer()&&(s-=t.footer.height())),s-=n,s-=t.container.height()-(n+t.table.height()),!isNaN(parseFloat(h))&&isFinite(h)&&(s-=h);var g=Math.floor(s/o);g===1/0||g===-(1/0)||isNaN(g)||!(g>0)||g===a.page.len()||d&&d(g,a.page.len(),l)===!1||a.page.len(g).draw(l.paging)},_attach:function(){var t=this,a=e("").css({position:"absolute",top:0,left:0,height:"100%",width:"100%",zIndex:-1}).attr("type","text/html");a[0].onload=function(){var e=this.contentDocument.body,a=e.offsetHeight;this.contentDocument.defaultView.onresize=function(){var i=e.clientHeight||e.offsetHeight;i!==a&&(a=i,t._size())}},a.appendTo(this.s.host).attr("data","about:blank")}},e.fn.dataTable.PageResize=t,e.fn.DataTable.PageResize=t,e(document).on("init.dt",function(a,i){if("dt"===a.namespace){var n=new e.fn.dataTable.Api(i);(e(n.table().node()).hasClass("pageResize")||i.oInit.pageResize||e.fn.dataTable.defaults.pageResize)&&new t(n,i.oInit.pageResizeManualDelta,i.oInit.pageResizeDrawPagingParameter,i.oInit.pageResizePreDrawCallback)}})})(jQuery); \ No newline at end of file