How To Handle Items Data Binding With Vaadin Grid When Using DataProvider
I am using the following example from vaadin docs with polymer3
<vaadin-grid id="grid" aria-label="Remote Data Example">
<vaadin-grid-column path="firstName"></vaadin-grid-column>
<vaadin-grid-column path="lastName"></vaadin-grid-column>
<vaadin-grid-column path="email"></vaadin-grid-column>
</vaadin-grid>
<script>
window.addEventListener('WebComponentsReady', function() {
const grid = document.querySelector('vaadin-grid');
grid.size = 200;
grid.dataProvider = function(params, callback) {
var xhr = new XMLHttpRequest();
xhr.onload = function() {
callback(JSON.parse(xhr.responseText).result);
};
var index = params.page * params.pageSize;
xhr.open('GET', 'https://demo.vaadin.com/demo-data/1.0/people?index=' + index + '&count=' + params.pageSize, true);
xhr.send();
};
});
</script>
I could not figure out how to update a row from the loaded items using polymer data binding
I have tried to access the items
property in the grid using this.$.grid.items
but this always returns the number of items
I want to be able to do something like
this.$.grid.items[0].firstName = 'changed'
and refelct the change into the grid
Any help is appreciated
Answer
currently, there's no API for updating a single item when dataProvider
is used. One option is to use grid.clearCache()
that makes grid request data for the visible rows again. Of course, storing the items in an additional cache would be useful in this case to avoid unnecessary server requests. If you use path
or renderer
, you can also invoke grid.render()
after changing an item sub-property.
see vaadin/vaadin-grid#1526 and the related forum thread
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM