From a3661fd6c0370ada7ed46032e539d079b6bd6f7c Mon Sep 17 00:00:00 2001 From: Andre Goncalves Date: Fri, 15 May 2026 12:48:36 -0700 Subject: [PATCH] AB#32619 update datagrid editor to open modal with fields in table order --- .../Worksheets/CustomFieldValueAppService.cs | 7 +- .../DataGrid/EditDataRowModal.cshtml.cs | 22 +++++-- .../Components/DataGridWidget/Default.js | 65 ++++++++++--------- 3 files changed, 60 insertions(+), 34 deletions(-) diff --git a/applications/Unity.GrantManager/modules/Unity.Flex/src/Unity.Flex.Application/Worksheets/CustomFieldValueAppService.cs b/applications/Unity.GrantManager/modules/Unity.Flex/src/Unity.Flex.Application/Worksheets/CustomFieldValueAppService.cs index c4bb4261d1..5f0accc309 100644 --- a/applications/Unity.GrantManager/modules/Unity.Flex/src/Unity.Flex.Application/Worksheets/CustomFieldValueAppService.cs +++ b/applications/Unity.GrantManager/modules/Unity.Flex/src/Unity.Flex.Application/Worksheets/CustomFieldValueAppService.cs @@ -27,7 +27,12 @@ public async Task ExplicitSetAsync(Guid valueId, string value) [RemoteService(false)] public async Task ExplicitAddAsync(CustomFieldValueDto value) { - await customFieldValueRepository.InsertAsync(ObjectMapper.Map(value)); + var entity = new CustomFieldValue( + value.Id, + value.WorksheetInstanceId, + value.CustomFieldId, + value.CurrentValue ?? "{}"); + await customFieldValueRepository.InsertAsync(entity); } [RemoteService(false)] diff --git a/applications/Unity.GrantManager/modules/Unity.Flex/src/Unity.Flex.Web/Pages/Components/DataGrid/EditDataRowModal.cshtml.cs b/applications/Unity.GrantManager/modules/Unity.Flex/src/Unity.Flex.Web/Pages/Components/DataGrid/EditDataRowModal.cshtml.cs index 50fc621fa5..ebe5fe0968 100644 --- a/applications/Unity.GrantManager/modules/Unity.Flex/src/Unity.Flex.Web/Pages/Components/DataGrid/EditDataRowModal.cshtml.cs +++ b/applications/Unity.GrantManager/modules/Unity.Flex/src/Unity.Flex.Web/Pages/Components/DataGrid/EditDataRowModal.cshtml.cs @@ -68,7 +68,8 @@ public async Task OnGetAsync(Guid valueId, Guid worksheetInstanceId, Guid formVersionId, Guid applicationId, - string uiAnchor) + string uiAnchor, + string columnOrder = "") { Row = row; ValueId = valueId; @@ -114,7 +115,7 @@ public async Task OnGetAsync(Guid valueId, DynamicKeyMap = JsonSerializer.Serialize(keyMap); - AllFields = MergeAndSortFields(DynamicFields ?? [], Properties ?? []); + AllFields = MergeAndSortFields(DynamicFields ?? [], Properties ?? [], columnOrder); } private static DynamicFieldMap[] PrefixDynamicFields(DynamicFieldMap[] dynamicFieldMaps) @@ -246,15 +247,26 @@ private static void ApplyDynamicFieldPresentationFormat( private sealed record DynamicKeyMapEntry(string Name, string Type, bool IsDynamic = true); - private static List MergeAndSortFields(DynamicFieldMap[] dynamicFields, List customFields) + private static List MergeAndSortFields(DynamicFieldMap[] dynamicFields, List customFields, string columnOrder) { + var columnKeys = columnOrder.Split(',', StringSplitOptions.RemoveEmptyEntries); + var orderMap = columnKeys + .Select((key, idx) => (key, idx)) + .ToDictionary(t => t.key, t => t.idx, StringComparer.OrdinalIgnoreCase); + + int GetOrder(string key) => orderMap.TryGetValue(key, out var idx) ? idx : int.MaxValue; + var fields = new List(); foreach (var df in dynamicFields) { + var rawKey = df.Key.StartsWith(DynamicFieldPrefix, StringComparison.Ordinal) + ? df.Key[DynamicFieldPrefix.Length..] + : df.Key; fields.Add(new EditRowField { SortKey = df.Name, + SortOrder = GetOrder(rawKey), DynamicField = df }); } @@ -264,16 +276,18 @@ private static List MergeAndSortFields(DynamicFieldMap[] dynamicFi fields.Add(new EditRowField { SortKey = cf.Label, + SortOrder = GetOrder(cf.Name), CustomField = cf }); } - return [.. fields.OrderBy(f => f.SortKey, StringComparer.OrdinalIgnoreCase)]; + return [.. fields.OrderBy(f => f.SortOrder).ThenBy(f => f.SortKey, StringComparer.OrdinalIgnoreCase)]; } public class EditRowField { public string SortKey { get; set; } = string.Empty; + public int SortOrder { get; set; } = int.MaxValue; public WorksheetFieldViewModel? CustomField { get; set; } public DynamicFieldMap? DynamicField { get; set; } public bool IsDynamic => DynamicField != null; diff --git a/applications/Unity.GrantManager/modules/Unity.Flex/src/Unity.Flex.Web/Views/Shared/Components/DataGridWidget/Default.js b/applications/Unity.GrantManager/modules/Unity.Flex/src/Unity.Flex.Web/Views/Shared/Components/DataGridWidget/Default.js index 6e1c2b2eda..7fd001ce6c 100644 --- a/applications/Unity.GrantManager/modules/Unity.Flex/src/Unity.Flex.Web/Views/Shared/Components/DataGridWidget/Default.js +++ b/applications/Unity.GrantManager/modules/Unity.Flex/src/Unity.Flex.Web/Views/Shared/Components/DataGridWidget/Default.js @@ -162,31 +162,32 @@ $(function () { } return -1; // Return -1 if the column is not found } - function openEditDatagridRowModal(valueId, - fieldId, - worksheetId, - worksheetInstanceId, - row, - isNew, - uiAnchor) { - + function openEditDatagridRowModal(options) { let formVersionId = $('#ApplicationFormVersionId').val(); let applicationId = $('#DetailsViewApplicationId').val(); editDatagridRowModal.open({ - valueId: valueId, - fieldId: fieldId, - row: row, - isNew: isNew, - worksheetId: worksheetId, - worksheetInstanceId: worksheetInstanceId, + valueId: options.valueId, + fieldId: options.fieldId, + row: options.row, + isNew: options.isNew, + worksheetId: options.worksheetId, + worksheetInstanceId: options.worksheetInstanceId, // There is dependency here on the core module and details page ! formVersionId: formVersionId, applicationId: applicationId, - uiAnchor: uiAnchor + uiAnchor: options.uiAnchor, + columnOrder: options.columnOrder || '' }); } + function getColumnOrder(dt) { + return dt.columns().header().toArray() + .map(th => $(th).data('key')) + .filter(key => key !== undefined && key !== null) + .join(','); + } + let actionButtons = [ { id: 'AddRecord', @@ -201,13 +202,16 @@ $(function () { let tableElement = $('#' + tableId); let tableDataSet = tableElement[0].dataset; - openEditDatagridRowModal(tableDataSet.valueId, - tableDataSet.fieldId, - tableDataSet.wsId, - tableDataSet.wsiId, - 0, - true, - tableDataSet.wsAnchor); + openEditDatagridRowModal({ + valueId: tableDataSet.valueId, + fieldId: tableDataSet.fieldId, + worksheetId: tableDataSet.wsId, + worksheetInstanceId: tableDataSet.wsiId, + row: 0, + isNew: true, + uiAnchor: tableDataSet.wsAnchor, + columnOrder: getColumnOrder(dt) + }); } }, { @@ -320,13 +324,16 @@ $(function () { let table = $(button).closest('table'); let tableDataSet = table[0].dataset; - openEditDatagridRowModal(tableDataSet.valueId, - tableDataSet.fieldId, - tableDataSet.wsId, - tableDataSet.wsiId, - rowDataSet.rowNo, - false, - tableDataSet.uiAnchor); + openEditDatagridRowModal({ + valueId: tableDataSet.valueId, + fieldId: tableDataSet.fieldId, + worksheetId: tableDataSet.wsId, + worksheetInstanceId: tableDataSet.wsiId, + row: rowDataSet.rowNo, + isNew: false, + uiAnchor: tableDataSet.uiAnchor, + columnOrder: getColumnOrder(table.DataTable()) + }); } PubSub.subscribe(