使用子元素編輯行詳細資訊
此示例使用單獨的元素將繫結資料編輯到 row-detail
模板。
<!DOCTYPE html>
<html>
<head>
<base href="https://polygit.org/polymer+:master/iron-data-table+Saulis+:master/components/">
<link rel="import" href="polymer/polymer.html">
<script src="webcomponentsjs/webcomponents-lite.min.js"></script>
<link rel="import" href="iron-ajax/iron-ajax.html">
<link rel="import" href="paper-button/paper-button.html">
<link rel="import" href="paper-input/paper-input.html">
<link rel="import" href="iron-data-table/iron-data-table.html">
<link rel="import" href="iron-data-table/default-styles.html">
</head>
<body>
<dom-module id="row-detail">
<template>
<img src="[[item.user.picture.medium]]">
<span>[[item.user.username]]</span>
<span>[[item.user.email]]</span>
<paper-input></paper-input>
</template>
<script>
(function() {
'use strict';
Polymer({
is: 'row-detail',
properties: {
item: Object,
},
});
})();
</script>
</dom-module>
<dom-module id="x-foo">
<template>
<style>
#grid1 data-table-row-detail {
height: 150px;
}
#grid1 .detail {
width: 100%;
display: flex;
justify-content: space-around;
align-items: center;
border: 2px solid #aaa;
}
</style>
<paper-button on-tap="msg">Click Me</paper-button>
<iron-ajax auto
url="https://saulis.github.io/iron-data-table/demo/users.json"
last-response="{{users}}"
>
</iron-ajax>
<iron-data-table id="grid1" details-enabled items="[[users.results]]">
<template is="row-detail">
<div class="detail">
<row-detail item="{{item}}"></row-detail>
</div>
</template>
<data-table-column name="First Name">
<template>[[item.user.name.first]]</template>
</data-table-column>
<data-table-column name="Last Name">
<template>[[item.user.name.last]]</template>
</data-table-column>
</iron-data-table>
</template>
<script>
(function(){
'use strict';
Polymer({
is: 'x-foo',
msg: function() {
console.log('This proves Polymer is working!');
},
});
})();
</script>
</dom-module>
<x-foo></x-foo>
</body>
</html>
注意
目前,此處描述的問題會導致行詳細資訊部分在包含子元素時摺疊。補丁包括 tabindex="0"
如下。 ( 請參閱此 Stack Overflow 答案 。)
X-foo.html
<template is="row-detail">
<div class="detail">
<row-detail item="{{item}}" tabindex="0"></row-detail>
</div>
</template>