[英]How use vaadin-grid element selection as google drive selection?
这是我的问题。
我试图将<vaadin-grid>
元素用作文件浏览器,但是选择时遇到了问题。
这是我要复制的内容:
(对于CTRL键,我知道它与上下文无关,仅用于示例:))。
因此,它是单选和多选的混合。 目前,
您知道我该怎么做,还是更好的方法?
因此,这是一个响应我对jsfiddle的请求的示例 。 感谢Tomi Virkki和Jouni Koivuviita回答了我。
要解决我的问题,最好的办法是使用vaadin-grid(v2.0)的新版本。 当我单击一行时,这将使我能够获得所需的选择(CTRL键是我的要求中的一项奖励),选中该行并使用复选框来获得自定义选择。
为了使这是可行的代码:
<dom-module id="test-component">
<template>
<iron-media-query query="(max-width: 350px)" query-matches="{{narrow}}"></iron-media-query>
<vaadin-grid id="grid" items="[[users]]" on-active-item-changed="activeItemChanged" page-size="20" size="1000000">
<vaadin-grid-selection-column frozen>
</vaadin-grid-selection-column>
<vaadin-grid-column>
<template class="header">First</template>
<template>[[item.name.first]]</template>
</vaadin-grid-column>
<vaadin-grid-column hidden="[[narrow]]">
<template class="header">Last</template>
<template>[[item.name.last]]</template>
</vaadin-grid-column>
</vaadin-grid>
</template>
<script>
document.addEventListener('WebComponentsReady', function() {
Polymer({
is: 'test-component',
activeItemChanged: function(e) {
var activeItem = e.detail.value;
this.$.grid.selectedItems = [activeItem];
},
ready: function() {
this.$.grid.dataProvider = function(params, callback) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
callback(JSON.parse(this.responseText).results);
}
};
xhttp.open("GET", "https://randomuser.me/api?results=20", true);
xhttp.send();
};
}
});
});
</script>
调用此函数的on-active-item-changed="activeItemChanged"
属性将在选择单元格并且<vaadin-grid-selection-column frozen></vaadin-grid-selection-column>
on-active-item-changed="activeItemChanged"
仅选择行“ active” <vaadin-grid-selection-column frozen></vaadin-grid-selection-column>
用于复选框列。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.