Skip to content

Commit

Permalink
fix #259
Browse files Browse the repository at this point in the history
  • Loading branch information
samussiah committed Dec 12, 2019
1 parent 08f8c74 commit 351f306
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
5 changes: 4 additions & 1 deletion build/webcharts.js
Original file line number Diff line number Diff line change
Expand Up @@ -4508,6 +4508,7 @@
}
});

var tableCount = 0;
function createTable() {
var element = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'body';
var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
Expand Down Expand Up @@ -4540,8 +4541,10 @@
if (callback) {
thisTable.events['on' + event.charAt(0).toUpperCase() + event.slice(1)] = callback;
}
};
}; //increment thisChart count to get unique thisChart id

tableCount++;
thisTable.id = tableCount;
return thisTable;
}

Expand Down
2 changes: 1 addition & 1 deletion build/webcharts.min.js

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions src/createTable.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import table from './table/index';
import { select } from 'd3';

export var tableCount = 0;

export default function createTable(element = 'body', config = {}, controls = null) {
let thisTable = Object.create(table);

Expand Down Expand Up @@ -36,5 +38,10 @@ export default function createTable(element = 'body', config = {}, controls = nu
}
};

//increment thisChart count to get unique thisChart id
tableCount++;

thisTable.id = tableCount;

return thisTable;
}
16 changes: 8 additions & 8 deletions test-page/createTable/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
function createTable(element, settings) {
var controls = webCharts.createControls(
const controls = webCharts.createControls(
element,
{
inputs: [
{type: 'subsetter', value_col: 'Period', label: 'Filter by Period'},
{type: 'subsetter', value_col: 'Group', label: 'Filter by Group'}
{type: 'subsetter', value_col: 'Group', label: 'Filter by Group'},
]
}
);

return webCharts.createTable(element, settings, controls);
}

var table = createTable(
const table = createTable(
'.table',
{
'sortable': true,
Expand All @@ -27,7 +27,7 @@ var table = createTable(
);

d3.csv(
'https://cdn.jsdelivr.net/gh/RhoInc/data-library/data/miscellaneous/elements.csv',
'https://raw.githubusercontent.com/RhoInc/data-library/master/data/miscellaneous/elements.csv',
function(d) {
return d;
},
Expand All @@ -37,7 +37,7 @@ d3.csv(
//Update settings.
d3.selectAll('.controls input')
.on('change',function(){
var settings = {
const settings = {
sortable: d3.select('input.sortable').property('checked'),
searchable: d3.select('input.searchable').property('checked'),
nRowsPerPage: +d3.select('input.items').node().value,
Expand All @@ -50,7 +50,7 @@ d3.csv(
console.log(settings);

d3.select('.table').selectAll('*').remove()
var table = createTable(
const table = createTable(
'.table',
settings
);
Expand All @@ -62,7 +62,7 @@ d3.csv(
//Randomize columns.
d3.select('button.randomize-columns')
.on('click', function() {
var table = d3.select('.wc-table').datum();
const table = d3.select('.wc-table').datum();
table.config.cols = Object.keys(table.data.raw[0])
.reverse()
.filter(function(d) {
Expand All @@ -76,7 +76,7 @@ d3.select('button.randomize-columns')
//Randomize headers.
d3.select('button.randomize-headers')
.on('click', function() {
var table = d3.select('.wc-table').datum();
const table = d3.select('.wc-table').datum();
table.config.headers = table.config.cols
.map(function(key) {
const strArr = [];
Expand Down

0 comments on commit 351f306

Please sign in to comment.