Setting Variable Filter on Grid

4 posts, 1 answers
  1. Perry
    Perry avatar
    25 posts
    Member since:
    Feb 2019

    Posted 15 Mar Link to this post

    What is the proper way of setting a filter on a datagrid from a variable?

    I can manually set a filter in the parse function of the datasource but I assume there is a better way.

    I've seen a post about setting the grid.datasource.filter  such as

            grid.dataSource.filter({field: "someValue", operator: "eq", value: someValue });

    but when I put this in the databound event it does work but I'm getting some stack overflow errors so I assume this is wrong.

     

    I've created a dojo showing what I have sofar.

    Dojo

  2. Georgi
    Admin
    Georgi avatar
    547 posts

    Posted 19 Mar Link to this post

    Hi Perry,

    Filtering the grid will actually rebind the grid, thus filtering the grid within the dataBound event handler will cause an endless loop.

    If the requirement is to apply an initial filter to the dataSource, I would suggest you to use the dataSource.fitler configuration.

    e.g.

    var unitPrice = "10";
    var viewModelIndex = new baseViewModel({
     
      dsPrices: new kendo.data.DataSource({
        data: [
          {
            unitPrice: "10" 
          },
          {
            unitPrice: "18" 
          },  
          {
            unitPrice: "19" 
          },  
          {
            unitPrice: "21" 
          },      
        ],
        filter:{field: "unitPrice", operator: "eq", value:unitPrice },
      }),    
     
    });

    Below you will find a modified version of the provided sample:



    Regards,
    Georgi
    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.
  3. Perry
    Perry avatar
    25 posts
    Member since:
    Feb 2019

    Posted 19 Mar in reply to Georgi Link to this post

    But in your updated dojo you are filtering the selection page......How would you apply the filter on the second page grid and datasource with the value from the selection page?   (e.g. Select price 10 and only see products with a price of 10)
  4. Answer
    Georgi
    Admin
    Georgi avatar
    547 posts

    Posted 21 Mar Link to this post

    Hello Perry,

    You could filter the second page grid before displaying the page itself.

    e.g.

    router.route("/productspage/unitPrice/:id", function (id) {
      viewModelproductspage.set("unitPrice", id);
      viewModelproductspage.products.filter({
          field: "UnitPrice",
          operator: "eq",
          value: id
        })
      layout.showIn("#content", productspage);
    });

    Below you will find a modified version of the sample:



    Regards,
    Georgi
    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.
Back to Top