You can specify one or more column components by adding them in the components
array field of the column
configuration.
Each component will receive the datum d
and index i
for every cell in the column.
this
will be pointing to the cell DOM node on invocation.
Last active
October 12, 2016 13:09
-
-
Save cristiano-belloni/a98988b5a6cccf8bff4eb1bd7c0331af to your computer and use it in GitHub Desktop.
Zambezi Grid -- Column components
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
license: mit |
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> | |
<head> | |
<meta charset="utf-8"> | |
<link rel="stylesheet" type="text/css" href="https://npmcdn.com/[email protected]"> | |
<style> | |
.custom-element { | |
border: 0; | |
background: transparent; | |
color: #008a4b; | |
font-weight: bolder; | |
} | |
.info-box p { | |
margin-top: 20px; | |
margin-left: 8px; | |
} | |
</style> | |
</head> | |
<div class="grid-target"></div> | |
<div class="info-box"> | |
<p>Click one of the ✓ buttons.</p> | |
</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/[email protected]"></script> | |
<script src="https://npmcdn.com/@zambezi/[email protected]"></script> | |
<script src="https://npmcdn.com/@zambezi/[email protected]"></script> | |
<script> | |
const table = grid.createGrid() | |
.columns([ | |
{ sortable: false, width: 50, components: [buttonColumnComponent], label: 'Button' } | |
, { key: 'name'} | |
, { key: 'email' } | |
, { key: 'username' } | |
]) | |
, rows = _.range(1, 5000).map(faker.Helpers.createCard) | |
d3.select('.grid-target') | |
.style('height', '400px') | |
.datum(rows) | |
.call(table) | |
function buttonColumnComponent(d, i) { | |
d3.select(this) | |
.select(d3Utils.appendIfMissing('button.custom-element')) | |
.text('✓') | |
.on('click.custom-component-click', customHandler) | |
} | |
function customHandler(d) { | |
d3.select('.info-box p').text(`Clicked button for ${d.row.name}.`) | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment