From f36bedd2b8e0b7ebd63b54cb31db4941a9d4367e Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 27 Dec 2017 12:12:40 +0300 Subject: [PATCH] Update pageResize plugin. Add paging parameter to pass it to the draw function call inside pageResize plugin. Add callback which called before draw and provides cancel ability and ability to override the draw paging parameter. --- features/pageResize/dataTables.pageResize.js | 31 +++++++++++-------- .../dataTables.slidingChild.min.js | 7 +++++ 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/features/pageResize/dataTables.pageResize.js b/features/pageResize/dataTables.pageResize.js index a63ee24d..cf0d2d92 100644 --- a/features/pageResize/dataTables.pageResize.js +++ b/features/pageResize/dataTables.pageResize.js @@ -63,19 +63,21 @@ 'use strict'; -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; @@ -99,7 +101,9 @@ PageResize.prototype = { var rowHeight = rows.eq( rows.length > 1 ? 1 : 0 ).height(); // Attempt to use the second row if poss, for top and bottom border 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 @@ -122,9 +126,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 ); } }, @@ -182,7 +187,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/slidingChild/dataTables.slidingChild.min.js b/features/slidingChild/dataTables.slidingChild.min.js index e69de29b..5d850948 100644 --- a/features/slidingChild/dataTables.slidingChild.min.js +++ b/features/slidingChild/dataTables.slidingChild.min.js @@ -0,0 +1,7 @@ +(function(d){"function"===typeof define&&define.amd?define(["jquery","datatables.net"],function(f){return d(f,window,document)}):"object"===typeof exports?module.exports=function(f,e){f||(f=window);if(!e||!e.fn.dataTable)e=require("datatables.net")(f,e).$;return d(e,f,f.document)}:d(jQuery,document)})(function(d,f){var e=function(a,c){var b=this;a.on("draw",function(){b._updateFadedRows()});var h=a.table(),g=f.createElement("div");g.className="slider";this.s=d.extend({},{dt:a,table:d(h.node()),slider:d(g)}, +e.defaults,c);this._bind()};e.prototype={_bind:function(){var a=this,c=a.s;d(c.table,"> tbody").on("click",c.selector,function(){var b=d(this),b=b.is("tr")?b:b.closest("tr");b.is("tr")&&(b=c.dt.row(b),a._toggleChild(b))})},_toggleChild:function(a){var c=this.s;if(a.child.isShown())this._hideChild(a,function(){});else{var b=c.dt.row(".shown");b.length&&c.toggle?this._hideChild(b,this._showChildCallback(a)):this._showChild(a)}},_showChildCallback:function(a){return function(a){this._showChild(a)}.bind(this, +a)},_showChild:function(a){this.s.source(d(a.node()),this._response(a))},_response:function(a){return function(a,b){this.__showChild(a,b)}.bind(this,a)},__showChild:function(a,c){var b=this.s,e=b.slider;e.append(c);a.child(e,b.childClass).show();d(a.node()).toggleClass("shown");this._updateFadedRows();b.animateShow?this._showChildWithAnimation(a):this._showChildWithoutAnimation(a)},_showChildWithAnimation:function(a){var c=this.s;d(c.slider,a.child()).slideDown(c.animationSpeed,function(){c.onShown(a)})}, +_showChildWithoutAnimation:function(a){var c=this.s;d(c.slider,a.child()).show();c.onShown(a)},_hideChild:function(a,c){var b=this.s;d(a.node()).toggleClass("shown");this._updateFadedRows();b.animateHide?this._hideChildWithAnimation(a,c):this._hideChildWithoutAnimation(a,c)},_hideChildWithAnimation:function(a,c){var b=this.s,e=b.slider;d(e,a.child()).slideUp(b.animationSpeed,function(){a.child.remove();e.empty();b.onHidden(a);c()})},_hideChildWithoutAnimation:function(a,c){var b=this.s,e=b.slider; +d(e,a.child()).hide();a.child.remove();e.empty();b.onHidden(a);c()},_updateFadedRows:function(){this.s.fadeNonShowingRows?(this._fadeNonShowingRows(),this._removeFadeFromShowingRows()):this._removeFadeFromRows()},_fadeNonShowingRows:function(){this.s.dt.rows(".shown:visible").count()?this.s.dt.rows(":visible:not(.shown):not(.faded)").nodes().to$().css("opacity",this.s.fadeOpacity).addClass("faded"):this._removeFadeFromRows()},_removeFadeFromShowingRows:function(){this.s.dt.rows(".shown.faded:visible").nodes().to$().css("opacity", +1).removeClass("faded")},_removeFadeFromRows:function(){this.s.dt.rows(".faded").nodes().to$().css("opacity",1).removeClass("faded")}};e.defaults={selector:"tr",childClass:"child",source:function(){},toggle:!0,animateShow:!0,animateHide:!0,fadeNonShowingRows:!1,fadeOpacity:0.4,animationSpeed:200,onShown:function(){},onHidden:function(){}};d.fn.dataTable.SlidingChild=e;d.fn.DataTable.SlidingChild=e;d(f).on("init.dt",function(a,c){if("dt"===a.namespace){var b=new d.fn.dataTable.Api(c);(d(b.table().node()).hasClass("slidingChild")|| +c.oInit.slidingChild||d.fn.dataTable.defaults.slidingChild)&&new e(b,c.oInit.slidingChild)}})});