csv_to_datatables.php


Quell Code


<link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.13/css/jquery.dataTables.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="//cdn.datatables.net/1.10.13/js/jquery.dataTables.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/PapaParse/4.2.0/papaparse.min.js"></script>

<input type="file" id="input">
<hr/>
<table id="example">
</table>
<script>
  let inputElement = document.getElementById("input"),
    csvs = ["text/csv", "application/vnd.ms-excel"],
    example = null;

inputElement.addEventListener("change", handleFiles, false);

function handleFiles() {
    let file = this.files[0];
    Papa.parse(file, {
         "download": true,
         "header": true,
         "complete": results => {
              $("#example").DataTable({
                   "columns": results.meta.fields.map(c => ({
                   "title": c,
                   "data": c,
                   "visible": c.toLowerCase() !== "id",
                   "default": ""
                    })),
                    "data": results.data,
              });
          }
     });
}
</script>

Add Comment

* Required information
1000
Drag & drop images (max 1)
Powered by Commentics

Comments

No comments yet. Be the first!

Deprecated: Directive 'allow_url_include' is deprecated in Unknown on line 0