d3.select("#table1_landing").call( d3.superTable() .table_data(data) // the only required parameter is the data itself, in the format of an array of objects: [{}, {}, {}] .num_rows_to_show(5) // limits to 5 rows. You can leave out this line to show all rows );
d3.select("#table2_landing").call( d3.superTable() .table_data(data) .table_header(["type","chrom","start","end","name","score"]) .num_rows_to_show(5) );
function choose_row(d) { d3.select("#table3_output").append("li").html("You clicked the row with name: " + d.name); } d3.select("#table3_landing").call( d3.superTable() .table_data(data) .table_header(["chrom","start","end","name","score","type"]) .num_rows_to_show(5) .click_function(choose_row) );The gray background comes from this code within d3-superTable.css that you can import or override with custom styling:
.d3-superTable-table .selected { background-color: #dddddd; } .d3-superTable-table .unselected { background-color: white; }
var finished_running = true; function ready() { return finished_running; } function run_something(d) { console.log("running " + d.name); finished_running = false; // Here we just use a 3-second time-out to simulate some action that takes time, like reading from a file window.setTimeout(function() {finished_running = true},3000); } d3.select("#table4_landing").call( d3.superTable() .table_data(data) .table_header(["chrom","start","end","name","score","type"]) .num_rows_to_show(5) .click_function(run_something) .check_ready_function(ready) );
Try entering =17 into the chrom column or >39000000 into the start column. The options are =, <, and > You can even apply multiple filters to the same row by entering them separated by spaces. Try in the score column entering: >20 <50
d3.select("#table5_landing").call( d3.superTable() .table_data(data) .table_header(["chrom","start","end","name","size","score","type"]) .num_rows_to_show(10) .show_advanced_filters(true) // Powerful filtering options .click_function(choose_row) );
Check the console each time you change the filtering by typing into the input boxes on the table below. It will tell you the total number of rows after filtering.
function count_rows(dataset) { console.log("Number of rows: ", dataset.length); } d3.select("#table6_landing").call( d3.superTable() .table_data(data) .table_header(["chrom","start","end","name","size","score","type"]) .num_rows_to_show(10) .show_advanced_filters(true) // Powerful filtering options .click_function(choose_row) .run_on_filtered_data_function(count_rows) );
Note: This page also uses bootstrap to change the fonts and make the code snippets look nicer.
.d3-superTable-table { border-spacing: 0px; margin: 5vmin 5vmin 5vmin 5vmin; } .d3-superTable-table th, .d3-superTable-table td { text-align: center; padding: 0.3vmin 0.3vmin 0.3vmin 0.3vmin; border: 0.1px solid #cccccc; } .d3-superTable-table input { width: 100%; } .d3-superTable-table .selected { background-color: #dddddd; } .d3-superTable-table .unselected { background-color: white; } .d3-superTable-table .d3-superTable-header-row { cursor: pointer; }