所以這是一個例子來響應我的請求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>
用於複選框列。