diff --git a/dataTables.colResize.js b/dataTables.colResize.js index 51459cc..71fb216 100644 --- a/dataTables.colResize.js +++ b/dataTables.colResize.js @@ -1,10 +1,10 @@ -/*! ColResize 0.0.11 +/*! ColResize 0.0.12 */ /** * @summary ColResize * @description Provide the ability to resize columns in a DataTable - * @version 0.0.11 + * @version 0.0.12 * @file dataTables.colResize.js * @author Silvacom Ltd. * @@ -15,6 +15,7 @@ * - tdillan (for 0.0.3 and 0.0.5 bug fixes) * - kylealonius (for 0.0.8 bug fix) * - the86freak (for 0.0.9 bug fix) + * - grburgos (0.0.25 bug fix) */ (function (window, document, undefined) { @@ -215,6 +216,19 @@ this.s.dt.adjust().draw(); + return this; + }, + + // awa added this function so I can set the col widths from the persisted state values + "fnSetColWidths": function (widths) { + for (var i = 0, iLen = widths.length; i < iLen; i++) { + this.s.dt.aoColumns[i].width = widths[i]; + this.s.dt.aoColumns[i]._ColResize_iOrigWidth = widths[i]; + this.s.dt.aoColumns[i].sWidthOrig = this.s.dt.aoColumns[i].sWidth = widths[i]; + } + + this.s.dt.oInstance.fnAdjustColumnSizing(); + return this; }, @@ -351,15 +365,24 @@ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Mouse drop and drag */ - + //grb added data-column-index attribute to footer. + "_fnSetupMouseListeners": function () { var that = this; $(that.s.dt.nTableWrapper).off("mouseenter.ColResize").on("mouseenter.ColResize", "th", function (e) { e.preventDefault(); + if(that.s.dt.aoColumns.length>0 && typeof $(that.s.dt.aoColumns[0].nTf).attr('data-column-index') === "undefined") + $.each(that.s.dt.aoColumns, function (i, column) { + $(column.nTf).attr('data-column-index', $(column.nTh).attr('data-column-index')); + }); that._fnMouseEnter.call(that, e, this); }); $(that.s.dt.nTableWrapper).off("mouseleave.ColResize").on("mouseleave.ColResize", "th", function (e) { - e.preventDefault(); + e.preventDefault(); + if(that.s.dt.aoColumns.length>0 && typeof $(that.s.dt.aoColumns[0].nTf).attr('data-column-index') === "undefined") + $.each(that.s.dt.aoColumns, function (i, column) { + $(column.nTf).attr('data-column-index', $(column.nTh).attr('data-column-index')); + }); that._fnMouseLeave.call(that, e, this); }); }, @@ -420,7 +443,6 @@ */ "_fnMouseDown": function (e, nTh) { var that = this; - that.s.isMousedown = true; /* Store information about the mouse position */ @@ -553,7 +575,7 @@ */ "_fnResizeHandleCheck": function (e, nTh) { var that = this; - + var offset = $(nTh).offset(); var relativeX = (e.pageX - offset.left); var relativeY = (e.pageY - offset.top); @@ -603,10 +625,11 @@ } //If table width is fixed make sure both columns are resizable else just check the one. - if (this.s.init.tableWidthFixed) - resizeAvailable &= this.s.init.exclude.indexOf(parseInt($(that.dom.resizeCol).attr("data-column-index"))) == -1 && this.s.init.exclude.indexOf(parseInt($(that.dom.resizeColNeighbour).attr("data-column-index"))) == -1; - else - resizeAvailable &= this.s.init.exclude.indexOf(parseInt($(that.dom.resizeCol).attr("data-column-index"))) == -1; + if (this.s.init.tableWidthFixed) + resizeAvailable &= this.s.init.exclude.indexOf(parseInt($(that.dom.resizeCol).attr("data-column-index"))) == -1 && this.s.init.exclude.indexOf(parseInt($(that.dom.resizeColNeighbour).attr("data-column-index"))) == -1; + else + resizeAvailable &= this.s.init.exclude.indexOf(parseInt($(that.dom.resizeCol).attr("data-column-index"))) == -1; + $(nTh).off('mousedown.ColResize'); if (resizeAvailable) { @@ -687,6 +710,8 @@ $.each(this.s.dt.aoColumns, function (i, column) { $(column.nTh).removeAttr('data-column-index'); + //grb remove footer atribute + $(column.nTf).removeAttr('data-column-index'); }); this.s.dt._colResize = null; @@ -703,7 +728,7 @@ "_fnSetColumnIndexes": function () { $.each(this.s.dt.aoColumns, function (i, column) { $(column.nTh).attr('data-column-index', i); - }); + }); } }; @@ -820,6 +845,12 @@ return this.iterator('table', function (ctx) { ctx._colResize.fnReset(); }); + }); + // awa added this function so I can set the col widths from the persisted state values + $.fn.dataTable.Api.register('colResize.setColWidths()', function (widths) { + return this.iterator('table', function (ctx) { + ctx._colResize.fnSetColWidths(widths); + }); }); }