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

Setting Variable Filter on Grid

3 Answers 64 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
Perry
Top achievements
Rank 1
Perry asked on 15 Mar 2019, 10:27 PM

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

3 Answers, 1 is accepted

Sort by
0
Georgi
Telerik team
answered on 19 Mar 2019, 12:50 PM
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.
0
Perry
Top achievements
Rank 1
answered on 19 Mar 2019, 03:42 PM
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)
0
Accepted
Georgi
Telerik team
answered on 21 Mar 2019, 08:49 AM
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.
Tags
MVVM
Asked by
Perry
Top achievements
Rank 1
Answers by
Georgi
Telerik team
Perry
Top achievements
Rank 1
Share this question
or