Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
搜索HTML数据表_Html_File_Csv_Search - Fatal编程技术网

搜索HTML数据表

搜索HTML数据表,html,file,csv,search,Html,File,Csv,Search,我有一些代码(如下所示),允许我从硬盘上的某个位置在Firefox中打开和显示csv文件。我想添加一个搜索框,以便在输入文本时过滤列表。我见过一些其他的工作示例,它们将表数据存储在标记之间,但当它从外部文件位置提取数据时,我无法使其工作。我对JavaScript非常陌生,这有点让我不知所措,所以如果有人有任何建议,我将不胜感激 <!DOCTYPE html> <html> <head> <title>CSV File to HTML Tabl

我有一些代码(如下所示),允许我从硬盘上的某个位置在Firefox中打开和显示csv文件。我想添加一个搜索框,以便在输入文本时过滤列表。我见过一些其他的工作示例,它们将表数据存储在标记之间,但当它从外部文件位置提取数据时,我无法使其工作。我对JavaScript非常陌生,这有点让我不知所措,所以如果有人有任何建议,我将不胜感激

<!DOCTYPE html>
<html>
 <head>
  <title>CSV File to HTML Table Using AJAX jQuery</title>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  <style>
    table {
  border-collapse: collapse;
  width: 75%;
  border: 1px solid #ddd;
  font-size: 12px;
}
    tr:hover {background-color:#87CEEB;}
  </style>
 </head>
 <body>
  <div class="container">
   <div class="table-responsive">
    <h1 align="center">Adult Nursing - Absences Informed</h1>
    <input type="text" id="myInput" onkeyup="myFunction()" placeholder="Search for names..">

    <table id="table">
    <tr class="tr">


    <br />
    <div align="center">
     <button type="button" name="load_data" id="load_data" class="btn btn-info">Load Data</button>
    </div>
    <br />
    <div id="employee_table">
    </div>
   </div>
  </div>
 </body>
</html>

<script>

$(document).ready(function(){
 $('#load_data').click(function(){
  $.ajax({
   url:"all_absences.csv",
   dataType:"text",
   success:function(data)
   {
    var employee_data = data.split(/\r?\n|\r/);
    var table_data = '<table class="table table-bordered table-striped">';
    for(var count = 0; count<employee_data.length; count++)
    {
     var cell_data = employee_data[count].split(",");
     table_data += '<tr>';
     for(var cell_count=0; cell_count<cell_data.length; cell_count++)
     {
      if(count === 0)
      {
       table_data += '<th>'+cell_data[cell_count]+'</th>';
      }
      else
      {
       table_data += '<td>'+cell_data[cell_count]+'</td>';
      }
     }
     table_data += '</tr>';
    }
    table_data += '</table>';
    $('#employee_table').html(table_data);
   }
  });
 });

});

</script>

使用AJAX jQuery将CSV文件转换为HTML表
桌子{
边界塌陷:塌陷;
宽度:75%;
边框:1px实心#ddd;
字体大小:12px;
}
tr:hover{背景色:#87CEEB;}
成人护理-通知缺勤

加载数据
$(文档).ready(函数(){ $(“#加载_数据”)。单击(函数(){ $.ajax({ url:“所有缺勤.csv”, 数据类型:“文本”, 成功:功能(数据) { var employee_data=data.split(/\r?\n | \r/); var表_数据=“”; 对于(var count=0;count请尝试以下解决方案:

    <!DOCTYPE html>
<html>
 <head>
  <title>CSV File to HTML Table Using AJAX jQuery</title>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  <style>
    table {
  border-collapse: collapse;
  width: 75%;
  border: 1px solid #ddd;
  font-size: 12px;
}
    tr:hover {background-color:#87CEEB;}
  </style>
 </head>
 <body>
  <div class="container">
   <div class="table-responsive">
    <h1 align="center">Adult Nursing - Absences Informed</h1>
    <input type="text" id="myInput" onkeyup="myFunction(this)" placeholder="Search for names..">

    <table id="table">
    <tr class="tr">


    <br />
    <div align="center">
     <button type="button" name="load_data" id="load_data" class="btn btn-info">Load Data</button>
    </div>
    <br />
    <div id="employee_table">
    </div>
   </div>
  </div>
 </body>
</html>

<script>
var searchKey = "";
function myFunction(e){
    searchKey = e.value;
}

$(document).ready(function(){
 $('#load_data').click(function(){
  $.ajax({
   url:"all_absences.csv",
   dataType:"text",
   success:function(data)
   {
    var employee_data = data.split(/\r?\n|\r/);
    var table_data = '<table class="table table-bordered table-striped">';
    for(var count = 0; count<employee_data.length; count++)
    {
     var cell_data = employee_data[count].split(",");
     table_data += '<tr>';
     for(var cell_count=0; cell_count<cell_data.length; cell_count++)
     {
      if(count === 0)
      {
       table_data += '<th>'+cell_data[cell_count]+'</th>';
      }
      else
      {
        if(!cell_data[cell_count].includes(searchKey) && cell_count == 0){
          break;
        }
          table_data += '<td>'+cell_data[cell_count]+'</td>';
      }
     }
     table_data += '</tr>';
    }
    table_data += '</table>';
    $('#employee_table').html(table_data);
   }
  });
 });

});

</script>

使用AJAX jQuery将CSV文件转换为HTML表
桌子{
边界塌陷:塌陷;
宽度:75%;
边框:1px实心#ddd;
字体大小:12px;
}
tr:hover{背景色:#87CEEB;}
成人护理-通知缺勤

加载数据
var searchKey=“”; 函数myFunction(e){ searchKey=e.value; } $(文档).ready(函数(){ $(“#加载_数据”)。单击(函数(){ $.ajax({ url:“所有缺勤.csv”, 数据类型:“文本”, 成功:功能(数据) { var employee_data=data.split(/\r?\n | \r/); var表_数据=“”;
对于(var count=0;countHi,谢谢,这真的很有帮助。:)理想情况下,我想尝试通过Id或姓氏进行搜索,但我会尝试自己尝试添加。如果您可以做到这一点,请在添加后发布代码,这样可以,但可能需要一段时间:)实际上,我刚刚遇到了一个问题……我在工作中使用的电脑没有像在家(最新版本)那样通过Firefox(旧版本)运行代码。相反,我收到了一个错误:TypeError:cell_data[cell_count]。includes不是一个函数。有什么想法吗?尝试使用xampp或wamp在本地主机上运行它