We are trying to add dynamic columns in between static columns in kendo grid. I tried a lot of examples online but nothing worked for me.
We have the following setup
public class Columns { public int Id { get; set; } public int Column1 { get; set; } public string Column2 { get; set; } public string Column3 { get; set; } public IReadOnlyCollection<DynamicColumns> DynamicColumns { get; set; } } public class DynamicColumns { public string ColumnName { get; set; } public string ColumnValue { get; set; } } The grid is being initialized but now we want to add mulitple dynamic columns in the grid.
@(Html.Kendo().Grid(Model) .Name("Grid") .Columns(columns => { columns.Bound(e => e.Column1) .Width("175px") .Title(Localizer["Column1Name"].Value) .Filterable(false); columns.Bound(e => e.Column2) .Width("200px") .Title(Localizer["Column2Name"].Value) .Filterable(f => f.Multi(true)); //Between Column2 and Column3, we want to add the dynamic columns, I have tried a lot of examples online but was not successfull. columns.Bound(e => e.Column3) .Width("125px") .Title(Localizer["Column3Name"].Value) .Format("{0:dd MMM yyyy}"); .Mobile() .Sortable(s => s.AllowUnsort(false)) .DataSource(ds => ds .Ajax() .ServerOperation(false) .PageSize(Model.PageSizes.ToArray()[0]) ) ) Example data set.
[{ ID: 10 Column1: "C1" Column2: "John", Column3: "Doe", DynamicColumns: { { Name: "Dynamic Col 1", Value: "Dynamic Val 1",}, { Name: "Dynamic Col 2", Value: "Dynamic Val 2",}, { Name: "Dynamic Col 3", Value: "Dynamic Val 3",}, } }, { ID: 20 Column1: "C2" Column2: "Peter", Column3: "Pan", DynamicColumns: { { Name: "Dynamic Col 2", Value: "Dynamic Val 2",}, { Name: "Dynamic Col 3", Value: "Dynamic Val 3",}, { Name: "Dynamic Col 4", Value: "Dynamic Val 4",}, } }, { ID: 30 Column1: "C3" Column2: "Mike", Column3: "Kit", DynamicColumns: { { Name: "Dynamic Col 6", Value: "Dynamic Val 6",}, } }]; The grid output we are looking for is as below.
Please let us know if you have any suggestions.
Thank you!!
