简体   繁体   English

KendoUI Grid在下拉选项上选择应用过滤器

[英]KendoUI Grid apply filter on dropdown option select

I have a filterable column that uses a dropdown as a template where the user can select an option to filter by. 我有一个可过滤的列,它使用下拉列表作为模板,用户可以在其中选择一个选项作为过滤依据。

How can I make it filter the moment the option is selected rather than the user having to have to click the filter button once the selection is made? 如何在选择选项后立即对其进行过滤,而不是使用户必须在选择后单击过滤器按钮?

My following code doesn't work. 我的以下代码不起作用。 The moment a selection is made the grid refreshes without the filter applied and the dropdown selection is reset. 在做出选择的那一刻,在没有应用过滤器的情况下,网格刷新了,下拉选择被重置。

For my dropdown I have: 对于我的下拉菜单,我有:

function salesPersonFilter(element)
{
  element.kendoDropDownList({
    dataSource: [{Id: 0, Name: 'Jimbo Jones'}, {Id: 1, Name: 'Jimmy'}],
    dataTextField: 'Name',
    dataValueField: 'Name',
    optionLabel: 'Select salesperson',
    template: '#="<span class=\'filterTrigger\'>"+Name+"</span>" #'
  })
}

I have bound a click event to filterTrigger classes: 我已经将click事件绑定到filterTrigger类:

$('.k-list .filterTrigger').click(function()
{
  applyFilters();
})

I include the applyFilters() function as reference: 我包含了applyFilters()函数作为参考:

function applyFilters() // Custom filters...
{
  var dupes = {};
  var finalFilters = [];

  $.each(filterBus, function(i, el) {
    if(!dupes[el.field])
    {
      dupes[el.field] = true;
      finalFilters.push(el);
    }
  });

  filterBus = finalFilters ;

  grid.dataSource.filter(finalFilters) ;
}

I managed to do it this way, but surely there must be a better way?: 我设法做到了,但是肯定有更好的方法吗?:

function salesPersonFilter(element)
  {
    element.kendoDropDownList({
      dataSource: [{Id: 60, Name: 'Sam'}, {Id: 5, Name: 'Jimmy'}],
      dataTextField: 'Name',
      dataValueField: 'Id',
      optionLabel: 'Select salesperson',
      template: '#="<span class=\'filterTrigger\' data-value=\'"+Id+"\'>"+Name+"</span>" #',
      select: function(e) 
      {// Dirty, is there a better way?
        html = e.item[0].outerHTML;
        html = html.substring(html.indexOf('data-value="')+12);
        traderId = html.substring(0, html.indexOf('"'));

        filterBus.push({
          field: 'traderId',
          operator: 'eq',
          value: traderId
        })
        $('.k-animation-container').hide();
        grid.dataSource.filter(filterBus);
      }
    })
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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