From 8be02d2d65115ae1ed51a7fbdf64fe8820dd25a2 Mon Sep 17 00:00:00 2001 From: La Reclame Date: Tue, 22 Apr 2014 12:29:53 +0200 Subject: [PATCH 1/5] use closest() instead of parents() --- jquery.edittable.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/jquery.edittable.js b/jquery.edittable.js index 7cb77d0..60a4a41 100644 --- a/jquery.edittable.js +++ b/jquery.edittable.js @@ -144,7 +144,7 @@ // Add column $table.on('click', '.addcol', function () { - var colid = parseInt($(this).parents('tr').children().index($(this).parent('th')), 10); + var colid = parseInt($(this).closest('tr').children().index($(this).parent('th')), 10); colnumber += 1; @@ -166,7 +166,7 @@ return false; } - var colid = parseInt($(this).parents('tr').children().index($(this).parent('th')), 10); + var colid = parseInt($(this).closest('tr').children().index($(this).parent('th')), 10); colnumber -= 1; @@ -190,7 +190,7 @@ rownumber += 1; - $(this).parents('tr').after(buildRow(0, colnumber)); + $(this).closest('tr').after(buildRow(0, colnumber)); $table.find('.delrow').removeClass('disabled'); @@ -210,7 +210,7 @@ checkButtons(); - $(this).parents('tr').remove(); + $(this).closest('tr').remove(); $table.find('.addrow').removeClass('disabled'); From 98694a9b8d5a859ee71261d8c3e13660db5fbb7f Mon Sep 17 00:00:00 2001 From: La Reclame Date: Tue, 22 Apr 2014 12:30:42 +0200 Subject: [PATCH 2/5] Added some data check --- jquery.edittable.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/jquery.edittable.js b/jquery.edittable.js index 60a4a41..7718db8 100644 --- a/jquery.edittable.js +++ b/jquery.edittable.js @@ -80,8 +80,8 @@ for (a = 0; a < crow; a += 1) { buildRow(data[a], s.headerCols.length).appendTo($table.find('tbody')); } - } else { - // Variable columns + } else if ( data[0] ) { + // Variable columns for (a = 0; a < data[0].length; a += 1) { $table.find('thead tr').append(defaultth); } @@ -124,7 +124,12 @@ // Fill the table with data from textarea or given properties if ($el.is('textarea')) { - reset = JSON.parse($el.val()); + try { + reset = JSON.parse($el.val()); + } catch (e) { + reset = {}; + } + $el.after($table); // If inside a form set the textarea content on submit From db479c3fb5e73d56610b8c2099a4aa0248598c57 Mon Sep 17 00:00:00 2001 From: La Reclame Date: Tue, 22 Apr 2014 12:41:55 +0200 Subject: [PATCH 3/5] Update version --- bower.json | 2 +- demo/index.php | 6 +++--- jquery.edittable.js | 2 +- jquery.edittable.min.js | 3 +-- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/bower.json b/bower.json index c8ced9b..893eb1d 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "editTable", - "version": "0.1.0", + "version": "0.1.1", "description": "jQuery plugin that implement a data table input", "keywords": [ "table", diff --git a/demo/index.php b/demo/index.php index b1b8e14..8d68771 100644 --- a/demo/index.php +++ b/demo/index.php @@ -27,9 +27,9 @@ - + - +