Hi there,
I have a hard time getting my grid displaying the data I want to see.
Main Object
public class CustomerViewModel
{
[Key]
public string Vin { get; set; }
public List<Campaign> TechnicalCampaigns { get; set; } = new();
public string? CustomerNumber { get; set; }
public string? CustomerName { get; set; }
}
Campaign Model
public class Campaign { public string Vin { get; set; } public string CampaignId { get; set; } }
Grid
Html.Kendo().Grid<CustomerViewModel>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(p => p.Vin).Filterable(ftb => ftb.Multi(true).Search(true).CheckAll(true)).Width(100).Title("Vin").HtmlAttributes(new { style = "text-align: center" }).Locked(true);
columns.Command(command => { command.Edit(); }).Width(150).HtmlAttributes(new { style = "text-align: center" }).Locked(true);
columns.Bound(p => p.CustomerNumber).Filterable(ftb => ftb.Cell(y => y.Template("datePicker"))).Width(100).Title("Kundennummer").HtmlAttributes(new { style = "text-align: center" });
columns.Bound(p => p.CustomerName).Filterable(ftb => ftb.Multi(true).Search(true).CheckAll(true)).Width(100).Title("Kunde").HtmlAttributes(new { style = "text-align: center" });
columns.Bound(p => p.TechnicalCampaigns).Width(200).Title("Offene TA's").HtmlAttributes(new { style = "text-align: center" }).ClientTemplate("#=generateTemplate(TechnicalCampaigns)#");
.ColumnResizeHandleWidth(20)
.ColumnMenu()
.Sortable()
.Scrollable(s => s.Height("auto"))
.Filterable()
.Reorderable(reorder => reorder.Columns(true))
.Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName("CustomPopupTA"))
.DataSource(dataSource => dataSource
.SignalR()
.AutoSync(false)
.PageSize(10)
.Sort(sort => sort.Add("Vin").Descending())
.Transport(tr => tr
.Promise("hubStart")
.Hub("hub")
.Client(c => c
.Read("read")
.Create("create")
.Update("update")
.Destroy("destroy"))
.Server(s => s
.Read("read")
.Create("create")
.Update("update")
.Destroy("destroy")))
.Schema(schema => schema
.Model(model =>
{
model.Id(p => p.Vin);
model.Field(p => p.Vin).Editable(false);
}
)
)
)
I want to show the TechnicalCampaigns in a column. To be more specific: For each Campaign in List TechnicalCampaigns I want to display the string Campaign.CampaignId.
I have read every single thread in this forum regarding custom columns, customtemplates, using cshtml files as template, or forwarding the list in a customtemplate to a js function, iterating and returning values.
Absolutely nothing is working. It can't be that hard to display a simple string, or a list of strings, in a column.
Any hint would be greatly appreciated!
Cheers
Tom
Note: The customtemplate visible in the grid column abobe was my last try, still not working. Below the called function
function generateTemplate(TechnicalCampaigns) { var template = ""; for (i in TechnicalCampaigns) { let entries = Object.entries(TechnicalCampaigns[i].CampaignId); console.log(entries); template = template + entries + "\n"; } return template; //for (var i = 0; i < TechnicalCampaigns.count; i++) { // template = template + TechnicalCampaigns[i].CampaignId + "\n"; // alert(template); //} //return template; //var template = "<ul>"; //for (var i = 0; i < TechnicalCampaigns.count; i++) { // template = template + "<li>" + TechnicalCampaigns[i].CampaignId + "</li>"; // alert(TechnicalCampaigns[i].CampaignId); //} //return template + "</ul>"; }