Hi everyone, I am trying to implement the following functionalities with Grid and Server side filtering/paging:
- For the "Subject" column, I would like a dropdown with the ability to choose between two static values: "NPF" and "PF".
columns.Bound(p => p.TipoSoggetto).Groupable(false).Filterable(ftb => ftb.UI("tipoSoggettoFilter"));
And the script --> function tipoSoggettoFilter(element) { element.kendoDropDownList({ dataSource: { data: ["NPF", "PF"] } }); }
- For the "Operator" column, I would like to display a dropdown with values taken from a list item with value and text. I can see the dropdown and the filter works, but I don't see the corresponding text value in the grid; the cell simply remains empty (even though the filter works correctly).
var operatori = _ctx.Users.OrderBy(u => u.Email).Select(e => new SelectListItem
{
Text = e.NomeOperatore,
Value = e.Id.ToString()
}).ToList();
ops.AddRange(operatori);
ViewData["Operatori"] = new SelectList(ops, "Value", "Text");
ViewBag.Operatori = new SelectList(ops, "Value", "Text");
@(Html.Kendo().Grid<AVR.Models.Output.GetAllAvr>()
.Name("AVRgrid")
//.ToolBar(t => t.Search())
.Columns(columns =>
{
columns.Bound(p => p.DataInserimento).Format("{0:dd/MM/yyyy}").Groupable(false);
columns.Bound(p => p.Subject).Groupable(false).Filterable(ftb => ftb.UI("tipoSoggettoFilter"));
columns.ForeignKey(p => p.UserId, (System.Collections.IEnumerable)ViewData["Operatori"], "Text", "Text")
.Title("Operator").Width(200);
columns.Command(command => command.Custom(" ").IconClass("fa-solid fa-eye").Click("showDetails")).Width(45);
})
.Pageable(p => { p.PageSizes(new[] { 10, 20, 30 }); })
.Sortable()
//.Scrollable()
.Groupable()
.Filterable(ftb => ftb.Mode(GridFilterMode.Row))
.DataSource(dataSource => dataSource
.Ajax()
.Model(model =>
{
model.Field(p => p.UserId).DefaultValue(1);
})
.PageSize(10)
.Read(read => read.Action("GetAllFiltered", "AVR"))
)
)