mirror of
https://github.com/simonw/datasette-vega.git
synced 2026-09-20 15:34:10 +02:00
Respect _labels=on even if first row has a null, closes #5
This commit is contained in:
parent
267bdbbf58
commit
64205f3333
1 changed files with 8 additions and 3 deletions
|
|
@ -72,9 +72,14 @@ class DatasetteVega extends Component {
|
|||
fetch(url).then(r => r.json()).then(data => {
|
||||
if (data.length > 1) {
|
||||
// Set columns to first item's keys
|
||||
const columns = Object.keys(data[0]).map(
|
||||
key => (data[0][key] && data[0][key].label) ? `${key}.label` : key
|
||||
);
|
||||
const columns = Object.keys(data[0]).map(key => {
|
||||
// Do ANY of these rows have a .label property?
|
||||
if (data.filter(d => (d[key] || '').label !== undefined).length) {
|
||||
return `${key}.label`;
|
||||
} else {
|
||||
return key;
|
||||
}
|
||||
});
|
||||
this.setState({
|
||||
columns: columns,
|
||||
x_column: columns[0],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue