row-selection
is a simple component that will automatically highlight the active row; that is, the row you have clicked.
Last active
February 16, 2020 07:05
-
-
Save gabrielmontagne/7902566377f8ede777bb3cf493237c6e to your computer and use it in GitHub Desktop.
Zambezi Grid -- active row component
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 | |
height: 1000 |
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> | |
<meta charset="utf-8" /> | |
<link rel="stylesheet" type="text/css" href="https://npmcdn.com/normalize.css@4"> | |
<div class="grid-target"></div> | |
<button id="set-active-random-row">set active to random row</button> | |
<pre id="output"></pre> | |
<script src="https://npmcdn.com/underscore@1"></script> | |
<script src="https://npmcdn.com/[email protected]/faker.js"></script> | |
<script src="https://d3js.org/d3.v4.js"></script> | |
<script src="https://npmcdn.com/@zambezi/fun@2"></script> | |
<script src="https://npmcdn.com/@zambezi/d3-utils@3"></script> | |
<script src="https://npmcdn.com/@zambezi/grid@0"></script> | |
<script src="https://npmcdn.com/@zambezi/[email protected]"></script> | |
<script> | |
const rows = _.range(1, 100).map(faker.Helpers.createCard) | |
, rowSelection = gridComponents.createRowSelection() | |
.on('row-active-change.log', r => console.log('row active change', r)) | |
, out = d3.select('#output') | |
, setActiveRandomRow = d3.select('#set-active-random-row') | |
.on('click.configure', () => rowSelection.active(_.sample(rows))) | |
.on('click.redraw', draw) | |
, table = grid.createGrid() | |
.columns( | |
[ | |
{ key: 'name', locked: 'left', width: 200 } | |
, { key: 'username' } | |
, { key: 'email' } | |
, { | |
label: 'synth column' | |
, format: r => `${r.name} ${r.email}`.split('').sort().reverse().join('').toUpperCase() | |
, sort: (a, b) => d3.ascending(a.name, b.name) | |
} | |
, { key: 'phone' } | |
] | |
) | |
.usePre(rowSelection) | |
.on('draw.log', () => out.text('active row:\n' + JSON.stringify(rowSelection.active(), null, 2))) | |
, target = d3.select('.grid-target') | |
.datum(rows) | |
.style('height', '600px') | |
draw() | |
function draw() { | |
target.call(table) | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi , this is very helpful, i know i am late but is there anyway to change the color of the highlight?