Skip to content

Instantly share code, notes, and snippets.

@httpJunkie
Last active September 8, 2016 06:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save httpJunkie/23f8afaf37b5e35f027dfcbb0d8bee91 to your computer and use it in GitHub Desktop.
Save httpJunkie/23f8afaf37b5e35f027dfcbb0d8bee91 to your computer and use it in GitHub Desktop.
Aurelia ValueConverter - Array Filter by Text Input
//aurelia ValueConverter
export class GenericFilterValueConverter {
toView(array, value, cols, showResults=false) {
if (!value) { return showResults ? array : []; };
var arrayOut = array.filter(
function(arrayIn) {
for (var col in arrayIn) {
if (arrayIn.hasOwnProperty(col)) {
if (cols.indexOf(col) != -1 && arrayIn[col].toLowerCase()
.indexOf(value.toLowerCase()) != -1) {
return true;
}
}
};
return false;
});
return arrayOut;
}
}
<!--aurelia view-->
<template>
<require from="../services/genericFilter"></require>
<input type="text" placeholder="Search Product Name" name="searchValue" value.bind="searchValue & debounce:500"/>
<div class="grid">
<div repeat.for="product of products | genericFilter:searchValue:definedColumns:true">
<div class="col-1-2">
<!--product.html repeats for each product-->
<compose model.bind="product" view="products/product.html"></compose>
</div>
</div>
</div>
</template>
//aurelia module
export class Products {
constructor(utilityNameData, router) {
this.products = [];
//this view will sort size, cost, produtName
this.definedColumns = ["size","cost","productName"];
}
activate() {
return this.data.getAllProducts()
.then(products => {
this.products = products;
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment