Sorting a list of HtmlElements by Text
I haven't tried it but I think it should work when you add .toList()
. I think this should copy it to a standard list which is sortable.
this.onClick.listen((e){ this.parent.nextElementSibling.children.toList().sort((Row a,Row b)=> num.parse(a.children[this.visibleIndex].text). compareTo(num.parse(b.children[this.visibleIndex].text))); });
import 'dart:html';UListElement list;ButtonInputElement boton;main() { list = querySelector('#list'); boton.onClick.listen( (e) => sort() );}void sort(){ list.children = list.children.toList() ..sort((LIElement x, LIElement y)=> y.text.length.compareTo(x.text.length) ); }