From 94282bc61d559edb2d3271a287aac66a7ab91861 Mon Sep 17 00:00:00 2001 From: Roman Date: Tue, 17 Nov 2015 00:45:54 +0400 Subject: [PATCH] Fix bug with restoreState Plugin don`t work when restore state have ids non-existing columns. --- jquery.dragtable.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/jquery.dragtable.js b/jquery.dragtable.js index 32a4f23..4433bc8 100644 --- a/jquery.dragtable.js +++ b/jquery.dragtable.js @@ -108,6 +108,7 @@ */ _restoreState: function(persistObj) { for (var n in persistObj) { + if ($('#' + n).length == 0) continue; this.originalTable.startIndex = $('#' + n).closest('th').prevAll().size() + 1; this.originalTable.endIndex = parseInt(persistObj[n], 10) + 1; this._bubbleCols(); @@ -131,8 +132,10 @@ .add(thtb.find('> tr > th:nth-child(' + i + ')')); col2 = thtb.find('> tr > td:nth-child(' + (i + 1) + ')') .add(thtb.find('> tr > th:nth-child(' + (i + 1) + ')')); - for (j = 0; j < col1.length; j++) { - swapNodes(col1[j], col2[j]); + if ((col1.length > 0) && (col2.length > 0)) { + for (j = 0; j < col1.length; j++) { + swapNodes(col1[j], col2[j]); + } } } } else { @@ -141,8 +144,10 @@ .add(thtb.find('> tr > th:nth-child(' + i + ')')); col2 = thtb.find('> tr > td:nth-child(' + (i - 1) + ')') .add(thtb.find('> tr > th:nth-child(' + (i - 1) + ')')); - for (j = 0; j < col1.length; j++) { - swapNodes(col1[j], col2[j]); + if ((col1.length > 0) && (col2.length > 0)) { + for (j = 0; j < col1.length; j++) { + swapNodes(col1[j], col2[j]); + } } } }