From d6ee4a4703181069b006f61f6c8cdd59d68935dd Mon Sep 17 00:00:00 2001 From: Tady Date: Fri, 31 May 2019 21:30:28 +0300 Subject: [PATCH 1/4] Update jquery.edittable.js --- jquery.edittable.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/jquery.edittable.js b/jquery.edittable.js index e9d07d4..f1d47ac 100644 --- a/jquery.edittable.js +++ b/jquery.edittable.js @@ -1,4 +1,4 @@ -/*! editTable v0.2.0 by Alessandro Benoit */ +/*! editTable v0.2.2 by Alessandro Benoit */ (function ($, window, i) { 'use strict'; @@ -35,12 +35,12 @@ i = i + 1; // Build cell - function buildCell(content, type) { + function buildCell(content, type, row) { content = (content === 0) ? "0" : (content || ''); // Custom type if (type && 'text' !== type){ var field = s.field_templates[type]; - return '' + field.setValue(field.html, content)[0].outerHTML + ''; + return '' + field.setValue(field.html, content, row)[0].outerHTML + ''; } // Default return ''; @@ -56,13 +56,13 @@ if (!s.row_template) { // Without row template for (b = 0; b < (len || data.length); b += 1) { - rowcontent += buildCell(data[b]); + rowcontent += buildCell(data[b], false, b); } } else { // With row template for (b = 0; b < s.row_template.length; b += 1) { // For each field in the row - rowcontent += buildCell(data[b], s.row_template[b]); + rowcontent += buildCell(data[b], s.row_template[b], b); } } @@ -306,4 +306,4 @@ }; }; -})(jQuery, this, 0); \ No newline at end of file +})(jQuery, this, 0); From ce49224472a40da1469e2ef2037016f4d252ed85 Mon Sep 17 00:00:00 2001 From: Tady Date: Sat, 1 Jun 2019 20:48:30 +0300 Subject: [PATCH 2/4] Update README.md --- README.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/README.md b/README.md index e6dcc63..389b9a0 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,37 @@ To define a custom field type object: } ] ``` +To define a custom field type object, +and to set different properties for input elements depending on the row in which the input is located: + +```js +var selectOptions = []; +selectOptions[1] = ""; +selectOptions[2] = ""; + +var mytable = $('#edittable')..editTable({ + field_templates: { + 'select': { + html: '', // Input type html + getValue: function getValue(input) { + return $(input).val(); + }, + setValue: function setValue(input, value, row) { + var select = $(input); + //Add options depending on the row number + if (row !== undefined && selectOptions[row] !== undefined) { + select.html(selectOptions[row]); + } + + select.find('option').filter(function () { + return $(this).val() == value; + }).attr('selected', true); + return select; + } + } + } +}); +``` That's it, now give a look to [the examples](http://codeb.it/edittable/) to understand how it works. From 921434e2a24482a17ddeadad78f3bbcafc75ab62 Mon Sep 17 00:00:00 2001 From: Tady Date: Thu, 6 Jun 2019 05:11:05 +0300 Subject: [PATCH 3/4] Update jquery.edittable.js --- jquery.edittable.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jquery.edittable.js b/jquery.edittable.js index f1d47ac..73b9554 100644 --- a/jquery.edittable.js +++ b/jquery.edittable.js @@ -35,12 +35,12 @@ i = i + 1; // Build cell - function buildCell(content, type, row) { + function buildCell(content, type, col) { content = (content === 0) ? "0" : (content || ''); // Custom type if (type && 'text' !== type){ var field = s.field_templates[type]; - return '' + field.setValue(field.html, content, row)[0].outerHTML + ''; + return '' + field.setValue(field.html, content, col)[0].outerHTML + ''; } // Default return ''; From 75a4fd703e44f7b4597ebbe27204e00ce63f3944 Mon Sep 17 00:00:00 2001 From: Tady Date: Thu, 6 Jun 2019 05:13:41 +0300 Subject: [PATCH 4/4] Update README.md depending on the column index not row index --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 389b9a0..5861778 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ To define a custom field type object: ] ``` To define a custom field type object, -and to set different properties for input elements depending on the row in which the input is located: +and to set different properties for input elements depending on the column index in which the input is located: ```js var selectOptions = []; @@ -80,11 +80,11 @@ var mytable = $('#edittable')..editTable({ getValue: function getValue(input) { return $(input).val(); }, - setValue: function setValue(input, value, row) { + setValue: function setValue(input, value, col) { var select = $(input); //Add options depending on the row number - if (row !== undefined && selectOptions[row] !== undefined) { - select.html(selectOptions[row]); + if (col !== undefined && selectOptions[col] !== undefined) { + select.html(selectOptions[col]); } select.find('option').filter(function () {