-
-
Save jdanyow/c32ec6bf58cce6b373ec to your computer and use it in GitHub Desktop.
Aurelia simple grid example
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
<template> | |
<require from="./grid/grid"></require> | |
<require from="./grid/column"></require> | |
<grid rows.bind="people"> | |
<column><template><td>index: ${$index}</td></template></column> | |
<column><template><td>firstName: ${firstName}</td></template></column> | |
<column><template><td>lastName: ${lastName}</td></template></column> | |
</grid> | |
</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
export class App { | |
people = [ | |
{ firstName: 'Rob', lastName: 'Eisenberg' }, | |
{ firstName: 'Jeremy', lastName: 'Danyow' }, | |
{ firstName: 'Matt', lastName: 'Broadstone' } | |
]; | |
} |
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
import {inject, bindable, processContent, noView, ViewCompiler} from 'aurelia-framework'; | |
@noView | |
@processContent(false) | |
@inject(Element, ViewCompiler) | |
export class Column { | |
@bindable header | |
constructor(element, viewCompiler) { | |
let template = element.firstElementChild; | |
this.viewFactory = viewCompiler.compile(template); | |
element.innerHTML = ''; | |
} | |
} |
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
<template> | |
<content></content> | |
<table ref="table" border="1"> | |
<thead><tr ref="header"></tr></thead> | |
<tbody ref="tbody"></tbody> | |
</table> | |
</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
import { | |
inject, bindable, children, createOverrideContext, | |
ViewSlot, ViewCompiler | |
} from 'aurelia-framework'; | |
@inject(ViewSlot, ViewCompiler) | |
export class Grid { | |
@children('column') columns; | |
@bindable rows; | |
columnViewFactories = []; | |
constructor(viewSlot, viewCompiler) { | |
this.viewSlot = viewSlot; | |
this.rowViewFactory = | |
viewCompiler.compile(`<template><content></content></template`); | |
} | |
bind(bindingContext, overrideContext) { | |
this.scrapeColumnViewFactories(); | |
this.render(this.bindingContext, this.overrideContext); | |
} | |
scrapeColumnViewFactories() { | |
for (let i = 0; i < this.columns.length; ++i) | |
this.columnViewFactories.push(this.columns[i].viewFactory); | |
} | |
render(bindingContext, overrideContext) { | |
let rows = this.rows; | |
for (let y = 0, yy = rows.length; y < yy; y++) { | |
let rowBindingContext = rows[y]; | |
let rowOverrideContext = createOverrideContext(rowBindingContext, overrideContext); | |
rowOverrideContext.$first = y === 0; | |
rowOverrideContext.$last = y === yy - 1; | |
rowOverrideContext.$index = y; | |
// add an actual row | |
let rowElement = document.createElement('tr'); | |
this.tbody.appendChild(rowElement); | |
let rowView = this.rowViewFactory.create(); | |
this.viewSlot.add(rowView); | |
let rowViewSlot = new ViewSlot(rowElement, true); | |
for (let x = 0, xx = this.columnViewFactories.length; x < xx; x++) { | |
let cellViewFactory = this.columnViewFactories[x]; | |
let cellView = cellViewFactory.create(); | |
rowViewSlot.add(cellView); | |
} | |
// bind the whole row at once | |
rowViewSlot.bind(rowBindingContext, rowOverrideContext); | |
} | |
} | |
} |
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
<!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