简体   繁体   中英

Set Kendo Grid Filter Cell Value

Is there a way to set a filter cell's value in Kendo Grid in code? We're using 'row' mode with operators turned off.

在此处输入图片说明

Have you tried setting the filter-field of the datasource?
http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-filter

Snippet from that page:

<script>
var dataSource = new kendo.data.DataSource({
  data: [
    { name: "Jane Doe" },
    { name: "John Doe" }
  ],
  filter: { field: "name", operator: "startswith", value: "Jane" }
});
dataSource.fetch(function(){
  var view = dataSource.view();
  console.log(view.length); // displays "1"
  console.log(view[0].name); // displays "Jane Doe"
});
</script>

If you want to set a filter value of your own you'll have to set it on the grid's dataSource.

You can do it when you initialize the data source using the filter parameter:

$("#grid").kendoGrid({
  dataSource: {
    filter: { field: "YourFiledName", operator: "startWith", value: "A" }
    //Other parameters...
  }
});

... or you can do it after the grid initialization if you need to by using the dataSource filter method:

$("#grid").data("kendoGrid").dataSource.filter({ field: "YourFiledName", operator: "startWith", value: "A" });

You should just provide initial filter to the dataSource. Check the API reference here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM