聚合物1.x:如何过滤铁数据表? [英] Polymer 1.x: How to filter iron-data-table?

查看:81
本文介绍了聚合物1.x:如何过滤铁数据表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将filter属性添加到<iron-data-table? (请发布一个小样的演示.)

How do I add a filter attribute to <iron-data-table? (Please post a plunk demo.)

我分叉了这把小酒.然后,我尝试通过添加以下行来添加过滤器:

I forked this plunk. Then I tried to add a filter by adding the following line:

<iron-data-table
  ...
  filter="['item.user.name.first.length', '< 5']">

哪个打破了unk. 这是新的(现在坏掉的)插件.

Which broke the plunk. Here is the new (now broken) plunk.

此处的文档描述了filter属性,如下所示:

The documentation here describes the filter attribute as follows:

filter一个数组,其中包含用于过滤项目的路径/过滤器值对.

filter An array containing path/filter value pairs that are used to filter the items.

但是它缺少如何使用它的示例.

But it lacks an example of how to use it.

如何将filter属性添加到<iron-data-table? (请发布一个小样的演示.)

How do I add a filter attribute to <iron-data-table? (Please post a plunk demo.)

推荐答案

这不是一个非常有据可查的功能:

This isn't a very well documented feature:

通常,您可以在<data-table-column>元素中使用filter-byfilter-value属性,但是您也可以直接访问filter属性.

Normally, you would go about using filter-by and filter-value properties in <data-table-column> elements, but you can also access the filter property directly.

在过滤items数据源时,只有包含"类型的过滤可用.因此,您几乎无法像在Plnkr中那样基于字符串长度进行过滤.要获得更多的自定义过滤功能,您需要使用函数dataSource,在该函数中,您可以使用作为数据源函数的参数提供的过滤器来执行所需的任何操作.

When it comes to filtering items data source, there is only "contains" kind of filtering available. So, you pretty much can't do filtering based on string length like in your Plnkr with those. For more custom filtering functionality, you need to go using a function dataSource where you can do anything you want using the filters provided as arguments for the data source function.

无论如何,如果仍然要直接访问filter,例如提供默认的过滤值,则需要将该值设置为对象数组,这些对象具有pathfilter属性:

Anyways, in case you want still to access filter directly and for example provide a default filtering value, you need to set the value to be an array of objects, which have a path and filter property:

this.filter = [{path: 'user.name.first', filter: 'donna'}];

this.filter = [{path: 'user.name.first', filter: 'donna'}];

这里是一个示例: http://plnkr.co/edit/KIefwLNHeinkOgERWOvZ?p=preview

这篇关于聚合物1.x:如何过滤铁数据表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆