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

Pre-filter in dynamic kendo grid

2 Answers 426 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Anca
Top achievements
Rank 1
Anca asked on 07 Sep 2015, 12:10 PM

I have worked based on : .Filter(filter => filter.Add(/* your filter rule */)) , that I found in here.

 My code is : 

  var grid =
        Html.Kendo().Grid<dynamic>().Name(Model.Current.Id).HtmlAttributes(new
        {

           // lot of stuff

       }

 grid.DataSource(ds =>
    {
        var ajaxDsBuilder = ds.Ajax();
        ajaxDsBuilder.Model(model => model.Id("ID")).Events(ev => ev.Error("gridOnError")).ServerOperation(Model.Current.LazyLoading);

// mode code

      var cols = Model.Current.Columns.ToList();

           foreach (var col in cols)
              {​

                 ajaxDsBuilder.Sort(sort => sort.Add(col.Name).Ascending()); // this works perfect for pre-sorting     ( col.Name = the column name ) 

                 ajaxDsBuilder.Group(grp => grp.Add(col.Name, typeof(string))); // this the same works great for pre-grouping

 

 â€‹but when I try this:

          ajaxDsBuilder.Filter(f => f.Add(c=> c.col.Name).IsEqualTo("TEST")); â€‹

I get : Error309 An expression tree may not contain a dynamic operation 

 

if I try:  ajaxDsBuilder.Filter(f => f.Add(c=> col.Name.ToString()).IsEqualTo("TEST")); â€‹// I am overriding ToString() to give me the name of column

I get : Internal server error

 

 if I try:  ajaxDsBuilder.Filter(f => f.Add(c=> col.Name).IsEqualTo("TEST")); 
I get : Property with specified name: col.Name cannot be found on type: System.Data.DataRowView

 

I have also worked with lambda expressions, but I have pretty much the same errors. 

My grid has to be dynamic, so I can't change that.

Any help?

2 Answers, 1 is accepted

Sort by
0
Accepted
Rosen
Telerik team
answered on 09 Sep 2015, 07:55 AM

Hello Anca,

In order to add filter, in this case you will need to use AddRange method in which to pass the correct FilterDescriptor. Similar to the following:

.Filter(filter => filter.AddRange(new [] {
     new Kendo.Mvc.FilterDescriptor(col.Name, Kendo.Mvc.FilterOperator.IsEqualTo, "TEST")
})

Regards,
Rosen
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Anca
Top achievements
Rank 1
answered on 10 Sep 2015, 08:15 AM
Thanks a lot! That solved my problem. 
Tags
Grid
Asked by
Anca
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Anca
Top achievements
Rank 1
Share this question
or