Pre-filter in dynamic kendo grid

3 posts, 1 answers
  1. Anca
    Anca avatar
    5 posts
    Member since:
    Mar 2015

    Posted 07 Sep 2015 Link to this post

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

     My code is : 

      var grid =

               // 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. Answer
    Rosen avatar
    3253 posts

    Posted 09 Sep 2015 Link to this post

    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")

    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
  3. Anca
    Anca avatar
    5 posts
    Member since:
    Mar 2015

    Posted 10 Sep 2015 in reply to Rosen Link to this post

    Thanks a lot! That solved my problem. 
Back to Top