0

How can I rerun sort and render element when something changed in my element or whenever I want from code or automatically? Thank you

<template is="dom-repeat" items="[[attachments]]" as="attach_item" sort="_sortItems"></template>
misterzorgy
  • 123
  • 9

1 Answers1

2

You need to set an observer for the fields you want to watch.

Quoted from polymer docs:

By default, the filter and sort functions only run when the array itself is mutated (for example, by adding or removing items).

To re-run the filter or sort functions when certain sub-fields of items change, set the observe property to a space-separated list of item sub-fields that should cause the list to be re-filtered or re-sorted.

Example:

<template is="dom-repeat" items="{{employees}}"
filter="isEngineer" observe="type manager.type">

More info here: https://www.polymer-project.org/1.0/docs/devguide/templates.html#filtering-and-sorting-lists

PS: you need to set your field using this.set("array.index.field", value), otherwise your observer won't be notified

David Rissato Cruz
  • 3,347
  • 2
  • 17
  • 17