2017-04-06 45 views
1

我试图将我的vaadin网格转换为v2,因此我可以使用selectionMethods将选定的行提取为json或csv。聚合物Vaadin Grid v2迁移

评论我的工作v1 vaadin网格,这将导入一个JSON。

进口被包括在导入文件:

  • vaadin-grid.html
  • vaadin栅选择-column.html
  • vaadin-grid.html
  • 纸元件/paper-elements.html
  • 列表项

我vaadin包含人 https://github.com/vaadin/vaadin-grid

示例文件我的工作:从L-文件 https://jsfiddle.net/Saulis/sse7d93h/

<!-- 
@license 
Copyright (c) 2016 The Polymer Project Authors. All rights reserved. 
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt 
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt 
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt 
Code distributed by Google as part of the polymer project is also 
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt 
--> 

<link rel="import" href="../../bower_components/polymer/polymer.html"> 

<dom-module id="my-afmelden-test"> 

    <script> 
    var grid = document.getElementById('afmelden-grid'); 
    grid.items = window.employees; 
    var data = window.employees[index]; 
    </script> 

    <template> 
    <!-- <iron-ajax 
     auto 
     url = "../../signups.json" 
     handle-as="json" 
     last-response="{{gridData}}" ></iron-ajax> --> 
<!-- <vaadin-grid id="afmelden-grid" items="{{gridData}}" visible-rows="0" selection-mode="multi"> 
    <table> 
    <colgroup> 
     <col name="user.name.first" /> 
     <col name="user.name.last" /> 
     <col name="user.email" /> 
     <col name="user.phone" /> 
    </colgroup> 
    </table> 
    <button>derpdiederp</button> 
    <paper-button>derp</paper-button> 
</vaadin-grid> --> 
<iron-ajax url="https://randomuser.me/api?results=100&inc=name,email,picture" last-response="{{users}}" auto></iron-ajax> 
    <vaadin-grid id="grid" items="[[users.results]]"> 
     <vaadin-grid-selection-column auto-select="[[autoSelect]]"></vaadin-grid-selection-column> 
     <vaadin-grid-column width="50px" flex-grow="0"> 
     <template class="header">#</template> 
     <template>[[index]]</template> 
     </vaadin-grid-column> 
     <vaadin-grid-column width="50px" flex-grow="0"> 
     <template class="header"></template> 
     <template> 
      <img src="[[item.picture.thumbnail]]"></img> 
     </template> 
     </vaadin-grid-column> 
     <vaadin-grid-column> 
     <template class="header">First Name</template> 
     <template> 
      <div class="capitalized">[[item.name.first]]</div> 
     </template> 
     </vaadin-grid-column> 
     <vaadin-grid-column> 
     <template class="header">Last Name</template> 
     <template> 
      <div class="capitalized">[[item.name.last]]</div> 
     </template> 
     </vaadin-grid-column> 
     <vaadin-grid-column> 
     <template class="header">Custom Selection</template> 
     <template> 
     <div style="display: flex; align-items: center"> 
      <paper-button raised on-tap="_deselect" hidden="[[!selected]]">Deselect</paper-button> 
      <paper-button raised on-tap="_select" hidden="[[selected]]">Select</paper-button> 
      <paper-checkbox checked="{{selected}}">Selected</paper-checkbox> 
     </div> 
     </template> 
     </vaadin-grid-column> 
    </vaadin-grid> 
<paper-button on-tap="myAfmelden">Afmelden</paper-button> 
</template> 

<iron-ajax 
id="ajax_my_afmelden" 
method="POST" 
url="/cgi-bin/gerecht-toevoegen.py" 
handle-as="json" 
on-response="myAfmelden_ResponseHandler"> 
</iron-ajax> 

</template> 

<script> 
    var grid = document.getElementById('afmelden-grid'); 
    grid.items = window.employees; 

    // Log selected designers list on select event 
    grid.addEventListener('selected-items-changed', function() { 
    console.log('Selected designers:'); 
    gridData.selection.selected(function(index) { 
     var data = window.employees[index]; 
     console.log('- ' + data[0] + ' ' + data[1]); 

    }); 
    }.bind(grid)); 
</script> 

    <script> 
    Polymer({ 
     is: 'my-afmelden-test', 

     properties: { 
     gridData: { 
      type: Array,   /* array<student-info>: student-info = {id, firstName, lastName, sameGroup} 
        array is constant groepnr is changable */ 
     }, 
     }, 

     myAfmelden: function() { 
     // console.log(Selected); 
     console.log("nu moet die komen..."); 
     this.$.ajax_my_afmelden.contentType="application/json" 
     this.$.ajax_my_afmelden.body={ 
      users: this.gridData[0] 
     }; 
     this.$.ajax_my_afmelden.generateRequest(); 
     console.log("Afmelden: " + this.gridData[0]); 
     // console.log('Selected: ' + this.selection.selected()); 
     // console.log('- ' + data[0] + ' ' + data[1]); 
     }, 
     myAfmelden_ResponseHandler:function(request_confirm) { 
     console.log("Response: " + request_confirm); 
     } 
    }); 
    </script> 
</dom-module> 

回答