How do I sort the data in this jsBin by item.order
.
(Documentation)
<html>
<head>
<title>My Element</title>
<script data-require="polymer@*" data-semver="1.0.0" src="http://www.polymer-project.org/1.0/samples/components/webcomponentsjs/webcomponents-lite.js"></script>
<script data-require="polymer@*" data-semver="1.0.0" src="http://www.polymer-project.org/1.0/samples/components/polymer/polymer.html"></script>
<base href="http://element-party.xyz/" />
<link rel="import" href="all-elements.html" />
</head>
<body>
<dom-module id="my-element">
<template>
<firebase-collection location="https://dinosaur-facts.firebaseio.com/dinosaurs"
data="{{items}}"></firebase-collection>
<paper-input label="Search"
value="{{searchString::input}}"></paper-input>
<div>[[searchString]]</div>
<div>[[sortby]]</div>
<paper-dropdown-menu label="Sort by">
<paper-menu class="dropdown-content"
selected="{{sortby}}"
attr-for-selected="data-sortby">
<paper-item data-sortby="none" >None </paper-item>
<paper-item data-sortby="order">Order</paper-item>
</paper-menu>
</paper-dropdown-menu>
<template is="dom-repeat" items="{{items}}" as="item"
filter="{{computeFilter(searchString)}}"
sort="{{computeSort(sortby)}}">
<div>[[item.__firebaseKey__]], [[item.order]]</div>
</template>
</template>
<script>
Polymer({
is: "my-element",
computeFilter: function(string) {
if (!string) {
// set filter to null to disable filtering
return null;
} else {
// return a filter function for the current search string
string = string.toLowerCase();
return function(item) {
var name = item.__firebaseKey__.toLowerCase();
var order = item.order.toLowerCase();
return (name.indexOf(string) != -1 ||
order.indexOf(string) != -1);
};
}
},
computeSort: function(string) {
/* What function goes here? To sort by 'item.order' in reverse.
function(a, b) {
return b[string] - a[string];
}
*/
},
properties: {
items: {
type: Array
}
}
});
</script>
</dom-module>
<my-element></my-element>
</body>
</html>