Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new edit type - select #6685

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Nop.Web.Framework.Models.DataTables
using Microsoft.AspNetCore.Mvc.Rendering;

namespace Nop.Web.Framework.Models.DataTables
{
/// <summary>
/// Represent DataTables column property
Expand All @@ -17,6 +19,7 @@ public ColumnProperty(string data)
//set default values
Visible = true;
Encode = true;
DropDownItems = new List<SelectListItem>();
}

#endregion
Expand Down Expand Up @@ -84,6 +87,11 @@ public ColumnProperty(string data)
/// </summary>
public bool Encode { get; set; }

/// <summary>
/// Set the dropdown items.
/// </summary>
public IEnumerable<SelectListItem> DropDownItems { get; set; }

#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public enum EditType
{
Number = 1,
Checkbox = 2,
String = 3
String = 3,
Select = 4
}
}
24 changes: 20 additions & 4 deletions src/Presentation/Nop.Web/Areas/Admin/Views/Shared/Table.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -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);
</text>
Expand Down Expand Up @@ -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;
}
});

Expand All @@ -241,6 +243,19 @@
var strValue = editRowData_@(tableName)[cellName];
$($(curRow).children("[data-columnname='" + cellName + "']")[0]).html('<input value="' + escapeQuotHtml(strValue) + '" class="userinput" style="width: 99% " />');
}
if (columnType == 'select')
{
var selectedValue = editRowData_@(tableName)[cellName],
html = '<select class="userinput" style="width: 99%;height: 30px">';

items.forEach(function (item){
html += `<option value="${item.Value}" ${item.Value == selectedValue ? 'selected' : ''} ${item.Disabled ? 'disabled' : ''}">${item.Text}</option>`;
});

html += '</select>';

$($(curRow).children("[data-columnname='" + cellName + "']")[0]).html(html);
}
$('#@Model.Name').DataTable().columns.adjust();
}
}
Expand Down Expand Up @@ -274,8 +289,9 @@
updateRowData.push({ 'pname': nameData, 'pvalue': data });
$.each(columnData_@(tableName), function (index, element) {
if (element.Editable == true) {
var input = $($($(currentCells).children("[data-columnname='" + element.Data + "']")).children('input')[0]);
var value = input.val();
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);

Expand Down