This is a migrated thread and some comments may be shown as answers.

Attach the new Kendo Filter to an existing Grid component without specifying the data source name explicitly

2 Answers 98 Views
Filter
This is a migrated thread and some comments may be shown as answers.
Nikolay
Top achievements
Rank 1
Iron
Nikolay asked on 22 Nov 2019, 02:36 PM

Hello I have existing data grid in an ASP.NET Core project. I want to attach the new Kendo Filter to that grid without specifying the data source name explicitly.

Is there any way to do this?

2 Answers, 1 is accepted

Sort by
0
Alex Hajigeorgieva
Telerik team
answered on 26 Nov 2019, 01:27 PM

Hi, Nikolay,

I assume that you do not wish to extract the data source and share it between the filter and the Kendo UI Grid for ASP.NET Core. If my assumption is correct then you can:

  • Add the Filter with deferred initialization and a data source name
  • Get the grid instance and assign its data source to a variable named as the filter data source name
  • Call the DeferredScriptsFor() method to initialize the Filter

 

@(Html.Kendo().Filter<OrderViewModel>()
        .Name("filter")
        /* other configuration */
        .DataSource("ds") /* this will be the variable name  in the document ready handler  */
        .Deferred()
)

@(Html.Kendo().Grid<OrderViewModel>()
        .Name("grid")
       /* other configuration */
)

<script>
    $(document).ready(function () {
        var ds = $("#grid").data("kendoGrid").dataSource;
        @Html.Kendo().DeferredScriptsFor("filter", false)   // the false parameter is necessary so that the script tags are not rendered    
    });
</script>

In case you had something else in mind, please elaborate so I can suggest an alternative approach.

Kind Regards,
Alex Hajigeorgieva
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Nikolay
Top achievements
Rank 1
Iron
answered on 26 Nov 2019, 02:31 PM

Hello, Alex,

That sample code is working for my case.

Thank you!

Nikolay

Tags
Filter
Asked by
Nikolay
Top achievements
Rank 1
Iron
Answers by
Alex Hajigeorgieva
Telerik team
Nikolay
Top achievements
Rank 1
Iron
Share this question
or