Last active
September 8, 2016 06:50
-
-
Save httpJunkie/23f8afaf37b5e35f027dfcbb0d8bee91 to your computer and use it in GitHub Desktop.
Aurelia ValueConverter - Array Filter by Text Input
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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