My view model is structured as follows
public class ItemViewModel
{
[Required]
public int Id { get; set; }
[Required]
public int JobId { get; set; }
public string ItemId { get; set; }
public string ItemName { get; set; }
public IList<ItemPartViewModel> Parts { get; set; }
}
The ItemViewModel includes an IList of Parts with the following structure
public class ItemPartViewModel
{
[Required]
public int ID { get; set; }
public int ItemID { get; set; }
public string PartID { get; set; }
public string PartName { get; set; }
public float QtyInItem { get; set; }
public float Qty { get; set; }
public bool MoveAll { get; set; }
// Additional property for user picks: harvest/transfer/dispose
public PartActionType SelectedActionType { get; set; }
}
In display table, if 'moveAll' option in row unchecked, row is cloned to track user actions such as transferring and disposing parts
JavaScript snippet to clone rows:</p>
$(document).ready(function () {
$('.tr_clonePart input.part-class').change(function () {
let Id = $(this).attr('id');
let partId = $(this).attr('data-partId');
var selector = $(this).closest('.tr_clonePart');
if ($(this).prop("checked") == true){
$('#' + Id + 'clone').remove();
selector.find(".AllTxt").show();
selector.find(".editQty").hide();
}
else {
var $tr = $(this).closest('.tr_clonePart');
var $clone = $tr.clone();
...
}
});
Setup of a single row:
<tr class="tr_clonePart">
<td>
@part.PartIDLink
</td>
<td>
@Html.DisplayFor(x => x.Parts[i].PartName)
@Html.HiddenFor(x => x.Parts[i].PartName)
</td>
...
</tr>
View image for more clarity: https://i.sstatic.net/D0AOe.png
To handle multiple user actions within the same row in the part list, you can extend the cloning logic to reflect each action accurately.
Make adjustments to ensure complete tracking of all user actions across the part list rows.