Overriding the "filter" UI on grid bound to dynamic data

1 Answer 416 Views
Filter Grid
Stéphane
Top achievements
Rank 1
Stéphane asked on 02 Dec 2021, 10:00 AM

Hello,

 

In a .net 5.0 application using MVC, I have a grid that has been defined as Html.Kendo().Grid<dynamic>() because it needs to have dynamically generated columns (a mix between static and dynamic columns).

Html.Kendo().Grid<dynamic>() 
/*..*/
.Filterable(ftb => ftb.Mode(GridFilterMode.Menu))
.EnableCustomBinding(true)
.Columns(columns =>
{
    for (int i = 0; i < Model.TotalDimensions * 2; i++)
    {
        columns
            .Bound(Model.Data.Columns[i].DataType, Model.Data.Columns[i].ColumnName)
            .Title(Model.Data.Columns[i].Caption)
            .ClientGroupHeaderTemplate($"{Model.Data.Columns[i].Caption} #= value #")
            .Width(100);
    }
}
/*..*/

I am attempting to override the behavior of the filter UI. The documentation states that I should use this syntax:

columns.Bound(/*..*/).Filterable(filter => filter.UI("filterFunction")

Unfortunately, since the grid model has been defined as dynamic, the above line does not compile.

Is there a workaround for this?

1 Answer, 1 is accepted

Sort by
0
Aleksandar
Telerik team
answered on 06 Dec 2021, 11:40 AM

Hello Stéphane,

We have an example demonstrating how you can bind the Grid to dynamic data. I used this example as reference and added the configuration you have mentioned. On my end the sample application compiles and I am able to see the custom editor:

.Columns(columns =>
    {
        foreach (System.Data.DataColumn dcolumn in Model.Columns)
        {
            switch (dcolumn.DataType.ToString())
            {
                case "System.Float":
                    columns.Bound(dcolumn.ColumnName).Title(dcolumn.Caption).EditorTemplateName("Number").Filterable(ftb=>ftb.UI("filterFunction"));
                    break;
      ...
            }
     }

 

Custom Editor:

<script>
    function filterFunction(element) {
        element.css("color","red")
        element.kendoNumericTextBox({
            round: false
        });
    }
</script>

 

I am attaching the sample for you to review. Consider updating it, or sharing additional details on the error and how to reproduce it, in order for me to be able to provide further guidance on handling the scenario.

Regards,
Aleksandar
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Filter Grid
Asked by
Stéphane
Top achievements
Rank 1
Answers by
Aleksandar
Telerik team
Share this question
or