Skip to content

Instantly share code, notes, and snippets.

@dtaalbers
Last active February 24, 2018 14:03
Show Gist options
  • Save dtaalbers/8ba4a3e86f1ee87ee49e48763d6eb2bf to your computer and use it in GitHub Desktop.
Save dtaalbers/8ba4a3e86f1ee87ee49e48763d6eb2bf to your computer and use it in GitHub Desktop.
Update checked status
<template>
<div if.bind="selected_rows.length > 0">
Selection (${ selected_rows.length })
</div>
<input type="text" value.bind="query" keyup.delegate="search()" placeholder="Search..">
<table>
<thead>
<tr>
<td></td>
<th>Id</th>
<th>Name</th>
</tr>
</thead>
<tbody>
<tr repeat.for="row of rows">
<th><input type="checkbox" model.bind="row" checked.bind="selected_rows"></th>
<td>${ row.id }</td>
<td>${ row.name }</td>
</tr>
</tbody>
</table>
</template>
export class App {
query;
rows;
selected_rows = [];
data = [
{
id: 0,
name: 'Amazing row'
},
{
id: 1,
name: 'Less amazing row'
},
{
id: 2,
name: 'avarage row'
},
{
id: 3,
name: 'less than average row'
},
{
id: 4,
name: 'are you sure this is even a row?'
},
{
id: 5,
name: 'this is not a row, i am sure of it'
},
];
attached() {
this.rows = this.data;
}
search() {
if(!this.query || this.query.trim() == '') {
this.rows = this.data
} else {
this.rows = this.data.filter(x => x.name.includes(this.query));
}
}
}
<!doctype html>
<html>
<head>
<title>Aurelia</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.panel {
border: 1px solid black;
}
.panel-heading {
background: lightblue;
color: white;
border-bottom: 1px solid black;
padding: 3px;
font-size: 20px;
}
.panel-body {
padding: 3px;
}
</style>
</head>
<body aurelia-app>
<h1>Loading...</h1>
<script src="https://jdanyow.github.io/rjs-bundle/node_modules/requirejs/require.js"></script>
<script src="https://jdanyow.github.io/rjs-bundle/config.js"></script>
<script src="https://jdanyow.github.io/rjs-bundle/bundles/aurelia.js"></script>
<script src="https://jdanyow.github.io/rjs-bundle/bundles/babel.js"></script>
<script>
require(['aurelia-bootstrapper']);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment