From b46cc273a4aa14b8c6d14ab093dd62a3facc9e03 Mon Sep 17 00:00:00 2001 From: Denis Belous <38912029+dbelouslv@users.noreply.github.com> Date: Fri, 28 Apr 2023 22:27:23 +0300 Subject: [PATCH 1/3] Added a new edit type - Select. --- .../Models/DataTables/ColumnProperty.cs | 10 ++++++++- .../Models/DataTables/EditType.cs | 3 ++- .../Areas/Admin/Views/Shared/Table.cshtml | 22 ++++++++++++++++--- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/Presentation/Nop.Web.Framework/Models/DataTables/ColumnProperty.cs b/src/Presentation/Nop.Web.Framework/Models/DataTables/ColumnProperty.cs index 283d532223d..436b7b87f23 100644 --- a/src/Presentation/Nop.Web.Framework/Models/DataTables/ColumnProperty.cs +++ b/src/Presentation/Nop.Web.Framework/Models/DataTables/ColumnProperty.cs @@ -1,4 +1,6 @@ -namespace Nop.Web.Framework.Models.DataTables +using Microsoft.AspNetCore.Mvc.Rendering; + +namespace Nop.Web.Framework.Models.DataTables { /// /// Represent DataTables column property @@ -17,6 +19,7 @@ public ColumnProperty(string data) //set default values Visible = true; Encode = true; + DropDownItems = new List(); } #endregion @@ -84,6 +87,11 @@ public ColumnProperty(string data) /// public bool Encode { get; set; } + /// + /// Set the dropdown items. + /// + public IEnumerable DropDownItems { get; set; } + #endregion } } \ No newline at end of file diff --git a/src/Presentation/Nop.Web.Framework/Models/DataTables/EditType.cs b/src/Presentation/Nop.Web.Framework/Models/DataTables/EditType.cs index 4a052814f84..b0a2ad3e771 100644 --- a/src/Presentation/Nop.Web.Framework/Models/DataTables/EditType.cs +++ b/src/Presentation/Nop.Web.Framework/Models/DataTables/EditType.cs @@ -7,6 +7,7 @@ public enum EditType { Number = 1, Checkbox = 2, - String = 3 + String = 3, + Select = 4 } } \ No newline at end of file diff --git a/src/Presentation/Nop.Web/Areas/Admin/Views/Shared/Table.cshtml b/src/Presentation/Nop.Web/Areas/Admin/Views/Shared/Table.cshtml index 2b873d6c805..7ba3e398ea6 100644 --- a/src/Presentation/Nop.Web/Areas/Admin/Views/Shared/Table.cshtml +++ b/src/Presentation/Nop.Web/Areas/Admin/Views/Shared/Table.cshtml @@ -172,7 +172,8 @@ var obj = { 'Data': '@column.Data', 'Editable': @column.Editable.ToString().ToLowerInvariant(), - 'Type': '@column.EditType.ToString().ToLowerInvariant()' + 'Type': '@column.EditType.ToString().ToLowerInvariant()', + 'Items': @Json.Serialize(column.DropDownItems) } columnData_@(tableName).push(obj); @@ -217,11 +218,12 @@ function setEditStateValue_@(tableName)(curRow) { for (var cellName in editRowData_@(tableName)) { - var columnType = 'string'; + var columnType = 'string', items = []; $.each(columnData_@(tableName), function (index, element) { if (element.Data == cellName) { columnType = element.Type; + items = element.Items; } }); @@ -241,6 +243,19 @@ var strValue = editRowData_@(tableName)[cellName]; $($(curRow).children("[data-columnname='" + cellName + "']")[0]).html(''); } + if (columnType == 'select') + { + var selectedValue = editRowData_@(tableName)[cellName], + html = ''; + + $($(curRow).children("[data-columnname='" + cellName + "']")[0]).html(html); + } $('#@Model.Name').DataTable().columns.adjust(); } } @@ -274,7 +289,8 @@ updateRowData.push({ 'pname': nameData, 'pvalue': data }); $.each(columnData_@(tableName), function (index, element) { if (element.Editable == true) { - var value = $($($(currentCells).children("[data-columnname='" + element.Data + "']")).children('input')[0]).val(); + var tagType = element.Type == "select" ? "select" : "input"; + var value = $($($(currentCells).children("[data-columnname='" + element.Data + "']")).children(tagType)[0]).val(); updateRowData.push({ 'pname': element.Data, 'pvalue': value }); From a9f3488d2b6861c1fc8e1cf0be789fcca85ba4fa Mon Sep 17 00:00:00 2001 From: Denis Belous <38912029+dbelouslv@users.noreply.github.com> Date: Fri, 28 Apr 2023 22:43:28 +0300 Subject: [PATCH 2/3] Small style fix --- src/Presentation/Nop.Web/Areas/Admin/Views/Shared/Table.cshtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Presentation/Nop.Web/Areas/Admin/Views/Shared/Table.cshtml b/src/Presentation/Nop.Web/Areas/Admin/Views/Shared/Table.cshtml index 7ba3e398ea6..ba3217645e7 100644 --- a/src/Presentation/Nop.Web/Areas/Admin/Views/Shared/Table.cshtml +++ b/src/Presentation/Nop.Web/Areas/Admin/Views/Shared/Table.cshtml @@ -246,7 +246,7 @@ if (columnType == 'select') { var selectedValue = editRowData_@(tableName)[cellName], - html = ''; items.forEach(function (item){ html += ``; From 54ae2d5a15913cf923487ef10c33003777a5237a Mon Sep 17 00:00:00 2001 From: Denis Belous Date: Wed, 27 Sep 2023 15:04:19 +0300 Subject: [PATCH 3/3] Resolved conflicts --- .../Nop.Web/Areas/Admin/Views/Shared/Table.cshtml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Presentation/Nop.Web/Areas/Admin/Views/Shared/Table.cshtml b/src/Presentation/Nop.Web/Areas/Admin/Views/Shared/Table.cshtml index ba3217645e7..25641405c6c 100644 --- a/src/Presentation/Nop.Web/Areas/Admin/Views/Shared/Table.cshtml +++ b/src/Presentation/Nop.Web/Areas/Admin/Views/Shared/Table.cshtml @@ -291,6 +291,10 @@ if (element.Editable == true) { var tagType = element.Type == "select" ? "select" : "input"; var value = $($($(currentCells).children("[data-columnname='" + element.Data + "']")).children(tagType)[0]).val(); + + if (!/^\d+$/.test(value) && input.attr('type') == 'number') + value = new Intl.NumberFormat("@CultureInfo.CurrentUICulture.Name", { minimumFractionDigits: 10 }).format(value); + updateRowData.push({ 'pname': element.Data, 'pvalue': value });