How to set the row size in vaardin-grid v2.0 polymer element? - vaadin-grid

How do I set the row size in vaardin-grid v2.0 polymer element? Is it possible to auto set the row size to fit the size of the items automatically?

You can set the row to be dynamic by setting the 'items' property of the vaadin-grid element.
<vaadin-grid
id="grid"
aria-label="Remote Data Example"
items="[[data]]"
loading="{{loading}}"
style="height: auto;"
active-item="{{activeItem}}">
<!--<vaadin-grid-selection-column auto-select></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>
<template class="header">Process</template>
<template>[[item.name]]</template>
</vaadin-grid-column>
<vaadin-grid-column>
<template class="header">Start Time</template>
<template>[[item.startTime]]</template>
</vaadin-grid-column>
<vaadin-grid-column>
<template class="header">Owner</template>
<template>[[item.group]]</template>
</vaadin-grid-column>
<vaadin-grid-column>
<template class="header">Reactor</template>
<template>[[item.reactor]]</template>
</vaadin-grid-column>
<vaadin-grid-column>
<template class="header">Host Name</template>
<template>[[item.hostName]]</template>
</vaadin-grid-column>
</vaadin-grid>
you can set the 'data' which is your payload from a response from an iron-ajax element.

Related

Quasar2 Vue3 q-popup-edit #save event never called

I have the following template:
<template>
<q-item tag="label" v-ripple>
<q-popup-edit
v-model="editedModel"
#before-show="onFieldClick"
#save="setValue"
:cover="false"
fit
buttons
>
<template v-slot:title>
<div class="text-mono">{{ name }}</div>
</template>
<q-select
dense
autofocus
emit-value
v-model="editedModel"
multiple
:options="options"
counter
/>
</q-popup-edit>
<q-item-section>
<q-item-label class="text-mono">{{ name }}</q-item-label>
<q-item-label caption>{{ description }}</q-item-label>
<q-item-label caption>{{ model }}</q-item-label>
</q-item-section>
</q-item>
</template>
The #save method is never called. What do I miss? Thanks.
For me worked the following:
I added: v-slot="scope" to the q-popup-edit
<q-popup-edit v-model="initialValue" v-slot="scope" buttons #save="save">
and then I replaced my v-model inside q-input to this:
<q-input v-model="scope.value" >

Badge added to treeview item is clipped

Here is the snippet from the template for my view:
<v-card>
<v-card-text>
<v-treeview selectable hoverable :items="items" :open.sync="open">
<template v-slot:prepend="{ item }">
<v-icon>{{item.icon}}</v-icon>
</template>
<template v-slot:label="{ item }">
<v-badge :content="item.count">{{item.name}}</v-badge>
</template>
</v-treeview>
</v-card-text>
</v-card>
The badge is clipped vertically.
Is there a way to prevent clipping?
Found an easy solution. Add the following to the vue file.
<style lang="scss">
.v-treeview-node__content {
line-height: 4;
}
</style>
<v-badge :content="item.count" inline>{{item.name}}</v-badge>
Adding inline prop to v-badge solves the problem. Please have a look here.

Getting v-text-field value with xpath in Vuejs (with nightwatch)

VueJS markup:
<v-menu
lazy
:close-on-content-click="false"
v-model="modal"
transition="scale-transition"
offset-y
full-width
:nudge-right="40"
max-width="290px"
min-width="290px">
<v-text-field
slot="activator"
label="Issue Date"
v-model="date"
append-icon="event"
readonly
>
</v-text-field>
<v-date-picker v-model="date" no-title scrollable actions>
<template scope="{ save, cancel }">
<v-card-actions>
<v-spacer></v-spacer>
<v-btn flat color="primary" #click="cancel">Cancel</v-btn>
<v-btn flat color="primary" #click="save">OK</v-btn>
</v-card-actions>
</template>
</v-date-picker>
</v-menu>
HTML:
`<div class="menu__activator">
<div data-v-386ef34c="" class="input-group input-group--dirty input-group--append-icon input-group--text-field">
<label>Issue Date</label>
<div class="input-group__input">
<input readonly="readonly" tabindex="0" aria-label="Issue Date" type="text">
<i aria-hidden="true" class="material-icons icon input-group__append-icon input-group__icon-cb">event</i>
</div>
<div class="input-group__details">
<div class="input-group__messages"></div>
</div>
</div>
</div>`
How it appears in browser:
I'd like to write e2e to assert some logic with the calendar date. Date is produced with moment to match current day. However I cannot figure out how to access that text value with xpath.
Xpath to get the element:
$x('//div[contains(#class, "input-group--text-field")]//input[#readonly]')
How the element appears in developer console:
With the attribute I need at the very bottom:
Xpaths I've tried which result in empty array:
$x('//div[contains(#class, "input-group--text-field")]//input[#readonly]//#value')
$x('//div[contains(#class, "input-group--text-field")]//input[#readonly]/#value')
$x('//div[contains(#class, "input-group--text-field")]//input[#readonly][0]//#value')
Edit:
Managed to get the value in chrome console:
$x('//div[contains(#class, "input-group--text-field")]//input[#aria-label="Issue Date"]')[0].value
But still struggling with Nightwatch
Any solutions with xpath or css are welcome! Thanks!
Had to import chai, but this finally worked:
.getValue('//div[contains(#class, "input-group--text-field")]//input[#aria-label="Issue Date"]', function(result) {
expect(result.value).to.equal('2017-10-17')
})

Polymer byutv-jsonp/iron-ajax no response

I've been trying to get json data from the GW2 server, which didn't work with iron-ajax due to cross-domain issues. Than I tried this byutv-jsonp and that worked.
The problem now is that I get a response with the right data, but it's not triggering the on-response handler. So the data is never put inside the variable :/
Anyone has a tip, hint or clue?!
Source of byutv
http://coderfin.github.io/byutv-jsonp/components/byutv-jsonp/
<dom-module id="about-pagina">
<template>
<style include="shared-styles">
:host {
display: block;
}
</style>
<h1>about-pagina</h1>
<vaadin-grid id="grid" items="[[_c_studenten]]" selected-items="{{selected}}">
<vaadin-grid-column>
<template class="header">Account Name</template>
<template>
<div class="capitalized">[[item.name]]</div>
</template>
</vaadin-grid-column>
<vaadin-grid-column>
<template class="header">Rank</template>
<template>
<div class="capitalized">[[item.rank]]</div>
</template>
</vaadin-grid-column>
<vaadin-grid-column>
<template class="header">Date Joined</template>
<template>
<div class="capitalized">[[item.joined]]</div>
</template>
</vaadin-grid-column>
<vaadin-grid-column>
<template class="header">Docent</template>
<template>
<div class="capitalized">[[item.docent]]</div>
</template>
</vaadin-grid-column>
<vaadin-grid-column>
<template class="header">Lokaal</template>
<template>
<div class="capitalized">[[item.locatie]]</div>
</template>
</vaadin-grid-column>
<vaadin-grid-column>
<template class="header">Klas</template>
<template>
<div class="capitalized">[[item.klas]]</div>
</template>
</vaadin-grid-column>
</vaadin-grid-column>
</vaadin-grid>
<paper-button on-tap="derp" raised>Annuleren</paper-button>
<byutv-jsonp
id="ajax_members_get"
method="GET"
url="https://api.guildwars2.com/v2/guild/secretcode/members"
params='{"access_token":"secretcode"}'
handle-as="json"
last-response="{{_c_studenten}}"
on-response="_members_get_response_handler">
</byutv-jsonp>
</template>
<script>
Polymer({
is: 'about-pagina',
properties: {
c_visible: {
type: Boolean, /* true when element is the active visible item */
value: false,
observer: '_initializing',
},
_c_studenten: {
type: Array,
},
},
_initializing : function() {
if (this.c_visible) {
console.log("about-pagina");
this._members_get_request_handler();
}
},
_members_get_request_handler: function() {
console.log("_members_get_request_handler");
this.$.ajax_members_get.contentType="application/json";
this.$.ajax_members_get.body={
};
this.$.ajax_members_get.generateRequest();
},
_members_get_response_handler: function(request) {
console.log("_members_get_response_handler aantal studenten="+request.detail.response.length);
this._c_studenten = request.detail.response;
},
derp: function(){
console.log([[_c_studenten]]);
}
});
</script>
</dom-module>
As you are specifying _c_studenten's value in _members_get_response_handler function, you can remove last-response="{{_c_studenten}}" from the iron-ajax. That prevents setting the value twice. Now you can make sure that your data is in Array and not as Object (vaadin-grid requires array data). That probably does the trick. If not, make sure the format of data that iron-ajax fetches.

Dynamically-generated paper-dropdown-menu initial selection issue

So I'm trying to dynamically generate a paper-dropdown-menu populated from an AJAX data source, which is working great using the code below:
<polymer-element name="my-element" attributes="selected">
<template>
<core-ajax auto url="/api/items/" response="{{items}}" handleAs="json"></core-ajax>
<paper-dropdown-menu selected="{{selected}}">
<template repeat="{{items}}">
<paper-item name="{{id}}" label="{{name}}"></paper-item>
</template>
</paper-dropdown-menu>
</template>
But if I set the initial selected item to be either the value of the published attribute, or a value that I set in the 'ready' callback, the dropdown menu item does not get selected when the items are loaded:
<script>
Polymer({
publish: {
selected: null
}
});
</script>
</polymer-element>
I understand that this is happening because the 'selected' property is being set before the template in the dropdown gets bound, but my question is whether there is a way to either 1) defer the 'selected' property change until after the template is bound or 2) otherwise reliably set an initially selected value for the dropdown menu?
One option would be to not render the dropdown until the data is available.
ex: http://jsbin.com/piyogo/13/edit
<polymer-element name="foo-drop">
<template>
<core-ajax auto
url="http://www.json-generator.com/api/json/get/bJMeMASvTm?indent=2"
response="{{items}}"
handleas="json">
</core-ajax>
<template if="{{items}}">
<paper-dropdown-menu selected="{{selected}}">
<template repeat="{{item in items}}">
<paper-item label="{{item.name}}"></paper-item>
</template>
</paper-dropdown-menu>
</template>
</template>
<script>
Polymer({
publish: {
selected: null
}
});
</script>
</polymer-element>
<foo-drop selected="2"></foo-drop>
For Polymer 1.0 (and later), the same can be achieved with the following code:
<iron-ajax auto url={{url}} handle-as="json" last-response="{{items}}"></iron-ajax>
<template is="dom-if" if="{{items}}">
<paper-dropdown-menu-light label="[[label]]" no-animations selected-item="{{selected}}">
<paper-listbox class="dropdown-content">
<template is="dom-repeat" items="[[items]]">
<paper-item>[[item.name]]</paper-item>
</template>
</paper-listbox>
</paper-dropdown-menu-light>
</template>

Resources