-
-
Save fkleuver/42ea5b81feb5fc9e39b610d362c227b1 to your computer and use it in GitHub Desktop.
Modify a template and rerender
This file contains hidden or 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
<template> | |
<require from="custom-table"></require> | |
<custom-table items.bind="data"> | |
<template replace-part="row"> | |
<tr> | |
<th>${item.v}</th> | |
<th>${item.a}</th> | |
<th>${item.k}</th> | |
</tr> | |
</template> | |
</custom-table> | |
</template> |
This file contains hidden or 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
export class App { | |
data = [ | |
{ v: 1, a: 1, k: 2 }, | |
{ v: 3, a: 5, k: 8 }, | |
{ v: 13, a: 22, k: 35 } | |
] | |
} |
This file contains hidden or 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
<template> | |
<style>th,td { border: 1px solid }</style> | |
<table> | |
<thead> | |
<th>one <button click.delegate="reorder()">></button></th> | |
<th>two</th> | |
<th>three</th> | |
</thead> | |
<tbody> | |
<tr repeat.for="item of items" part="row"></tr> | |
</tbody> | |
</table> | |
</template> |
This file contains hidden or 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
import { inject, bindable, TargetInstruction, ViewResources, ViewCompiler, TaskQueue } from 'aurelia-framework'; | |
@inject(TargetInstruction, ViewResources, ViewCompiler, TaskQueue) | |
export class CustomTableCustomElement { | |
@bindable items = []; | |
constructor(inst, resources, compiler, tq) { | |
this.inst = inst.behaviorInstructions[0]; | |
this.resources = resources; | |
this.compiler = compiler; | |
this.tq = tq; | |
} | |
reorder() { | |
const { inst, resources, compiler, tq } = this; | |
const template = inst.partReplacements.row.template; | |
const first = template.querySelector('th:first-child'); | |
first.nextElementSibling.insertAdjacentElement('afterend', first); | |
inst.partReplacements.row = compiler.compile(template, resources); | |
const items = this.items.splice(0); | |
tq.queueMicroTask(() => { | |
this.items = items; | |
}); | |
} | |
} |
This file contains hidden or 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
<!doctype html> | |
<html> | |
<head> | |
<title>Aurelia</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
</head> | |
<body aurelia-app> | |
<h1>Loading...</h1> | |
<script src="https://cdn.rawgit.com/jdanyow/aurelia-bundle/v1.0.3/jspm_packages/system.js"></script> | |
<script src="https://cdn.rawgit.com/jdanyow/aurelia-bundle/v1.0.3/config.js"></script> | |
<script> | |
System.import('aurelia-bootstrapper'); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment