score:1
<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
* {
box-sizing: border-box;
}
#myinput {
background-image: url('/css/searchicon.png');
background-position: 10px 10px;
background-repeat: no-repeat;
width: 100%;
font-size: 16px;
padding: 12px 20px 12px 40px;
border: 1px solid #ddd;
margin-bottom: 12px;
}
#mytable {
border-collapse: collapse;
width: 100%;
border: 1px solid #ddd;
font-size: 18px;
}
#mytable th,
#mytable td {
text-align: left;
padding: 12px;
}
#mytable tr {
border-bottom: 1px solid #ddd;
}
#mytable tr.header,
#mytable tr:hover {
background-color: #f1f1f1;
}
</style>
</head>
<body>
<h2>my customers</h2>
<input type="text" id="myinput" onkeyup="myfunction()" placeholder="search for names.." title="type in a name">
<input type="file" id="fileupload" />
<input type="button" id="upload" value="upload" onclick="upload()" />
<hr />
<div id="dvcsv">
</div>
<table id="mytable">
<tr class="header">
<th style="width:60%;">name</th>
<th style="width:40%;">country</th>
</tr>
<tr>
<td>alfreds futterkiste</td>
<td>germany</td>
</tr>
<tr>
<td>berglunds snabbkop</td>
<td>sweden</td>
</tr>
<tr>
<td>island trading</td>
<td>uk</td>
</tr>
<tr>
<td>koniglich essen</td>
<td>germany</td>
</tr>
<tr>
<td>laughing bacchus winecellars</td>
<td>canada</td>
</tr>
<tr>
<td>magazzini alimentari riuniti</td>
<td>italy</td>
</tr>
<tr>
<td>north/south</td>
<td>uk</td>
</tr>
<tr>
<td>paris specialites</td>
<td>france</td>
</tr>
</table>
<script>
function myfunction() {
var input, filter, table, tr, td, i, txtvalue;
input = document.getelementbyid("myinput");
filter = input.value.touppercase();
table = document.getelementbyid("mytable");
tr = table.getelementsbytagname("tr");
for (i = 0; i < tr.length; i++) {
td = tr[i].getelementsbytagname("td")[0];
if (td) {
txtvalue = td.textcontent || td.innertext;
if (txtvalue.touppercase().indexof(filter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}
</script>
<script type="text/javascript">
function upload() {
var fileupload = document.getelementbyid("fileupload");
var regex = /^([a-za-z0-9\s_\\.\-:])+(.csv|.txt)$/;
if (regex.test(fileupload.value.tolowercase())) {
if (typeof (filereader) != "undefined") {
var reader = new filereader();
reader.onload = function (e) {
var table = document.createelement("table");
var rows = e.target.result.split("\n");
for (var i = 0; i < rows.length; i++) {
var cells = rows[i].split(",");
if (cells.length > 1) {
var row = table.insertrow(-1);
for (var j = 0; j < cells.length; j++) {
var cell = row.insertcell(-1);
cell.innerhtml = cells[j];
}
}
}
var dvcsv = document.getelementbyid("dvcsv");
dvcsv.innerhtml = "";
dvcsv.appendchild(table);
}
reader.readastext(fileupload.files[0]);
} else {
alert("this browser does not support html5.");
}
} else {
alert("please upload a valid csv file.");
}
}
</script>
</body>
</html>
i tried your issue, and found solution on this page: https://www.aspsnippets.com/articles/import-csv-file-to-html-table-using-javascript.aspx
its working, i tried importing a sample csv file. this is how your page looks on using the code given on the shared page, i have uploaded a sample 10 row csv data, and kept your html code as it is.
score:1
you could use the datatable.js plugin. it supports importing/exporting csv-files and gives you a searchable and sortable table.
Source: stackoverflow.com
Related Query
- Making a search box using javascript and incorporate a CSV
- Upload csv file using javascript and d3
- Django: create csv file and load it in view using Javascript
- Read a huge csv file and populate a Map in Javascript using d3
- CSV to HTML table using d3 and an external javascript file
- Making bar widths and gaps consistent in dc.js when using a large dataset and d3.scale.linear()
- reading nodes and edges from two distinct csv files using Force Layout
- Trying to find a way to get the row and column names of csv in html/js by using d3 , any other ways?
- Vertical alignment between an SVG rect and SVG text using D3 and javascript
- How to add all but a few columns using javascript and d3
- hide nodes and children in D3.js using JavaScript or jQuery
- Using d3.layout.stack() and parsing csv for bar chart
- d3.js import csv using accessor function and callback
- How would I import a single column CSV file into a pie chart using Javascript D3?
- How to select and deselect a svg line and change its color on selection and deselection using d3.js and javascript , jquery?
- Javascript D3 How to access and manipulate dataset from CSV
- Making a colored box plot without whiskers using D3
- How to parse a csv into a dataTable quickly and efficiently using D3 v6
- Merging json and csv using topojson
- Combine multiple csv files in javascript using filtering
- D3 : Loading multiple CSV files, and visualizing them using parallel coordinates
- D3 JS - Making a Polygon Draggable using hard coded Bounding Box Attributes Does Not Work
- Finding min and max values of an array of arrays using D3.JS not plain Javascript
- Box plot with dual dimension and dual x-axis using dc.js
- Is there a way to parse times and be able to plot them directly using javascript and d3?
- JavaScript , D3 bar graph error using CSV
- Is this JSON I made using jsonify with flask and python 3 formatted correctly for making a D3 graph? And if not, how should I format it?
- d3.js maps: using a geojson file AND CSV data
- Filtering nodes and its corresponding edges in D3js using javascript
- How to load a CSV and a JSON file and combine both datsets to one dataset using d3.json, d3.csv and d3.zip
More Query from same tag
- nvd3 Bubble chart with log scale
- How do I apply two svgs on one html page?
- fetch is not defined in D3 csv call
- on click event D3.js only works first time
- Moving <text> around within an svg element
- D3 Horizontal Bar Chart X-Axis Range shorter than in Data via AngularJs
- Using two different Versions of jQuery in Angular 4 Project results in conflict (ngrx & visual sedimentation)
- Best way to arrange data in a csv for multiline chart in d3 that has categories
- How can I get d3 server-side in Meteor?
- How do I dynamically update nested lists with d3?
- Putting an arrow (marker) at specific point on a path when using the d3 javascript library
- radio button in conjunction with c3 does not show text
- D3 - why is this sort function not updating all the elements in its selection?
- How do you change the interpolation for a zoom behavior in d3.js
- Unable to implement sample d3.js flle
- Adding new paths to D3 Globe
- How to change transition duration globally in NVD3?
- SVG Group Translation Issue - Wrong Units?
- How to make a HTML div draggable using d3
- D3: event functions with concatenated transitions
- In D3, how does one place text inside shapes that already have text attached to them?
- How to modify axis labels in d3 for a stacked bar chart when the axis labels are mapped as part of the scale's domain
- Sum Of count in D3
- Delay to the next data item, appending one by one, time after time
- d3-fetch and UTF-16 LE
- d3.request on(error) callback not triggering for 401 response
- Trying to transition d3v4 linegraph data from one dataset to a dataset with a different scale
- Dimple.js barGap function not working
- d3.js trying to animate data, but changed data always treated as new
- D3: Select SVG attribute and change it