Skip to content

Instantly share code, notes, and snippets.

@gabrielmontagne
Last active October 11, 2016 12:35
Show Gist options
  • Save gabrielmontagne/8a1179c4496a587a3e731734e03b7fbe to your computer and use it in GitHub Desktop.
Save gabrielmontagne/8a1179c4496a587a3e731734e03b7fbe to your computer and use it in GitHub Desktop.
Zambezi Grid -- Simple custom column component
<!doctype html>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="https://npmcdn.com/[email protected]">
<div class="grid-target"></div>
<script src="https://npmcdn.com/[email protected]"></script>
<script src="https://d3js.org/d3.v4.js"></script>
<script src="https://npmcdn.com/[email protected]/faker.js"></script>
<script src="https://npmcdn.com/@zambezi/fun"></script>
<script src="https://npmcdn.com/@zambezi/d3-utils"></script>
<script src="https://npmcdn.com/@zambezi/grid" ></script>
<script>
var table = grid.createGrid()
.columns(
[
{ key: 'name'}
, { key: 'username'}
, {
key: 'email'
, components: [ someFancyMarkupComponent ]
}
]
)
, rows = _.range(1, 5000).map(faker.Helpers.createCard)
d3.select('.grid-target')
.style('height', '500px')
.datum(rows)
.call(table)
function someFancyMarkupComponent(d, i) {
const startsWithA = d.row.email[0].toLowerCase() == 'a'
, cell = d3.select(this)
cell.html(
startsWithA
? '<strong>email starts with "a" ▓▒<span class="formatted-text"></span></strong>'
: '<span class="formatted-text"></span>'
).select('.formatted-text').text(d => d.column.format(d.value))
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment