该表大约有10,000行。页面加载时需要很长时间。
我想为其添加排序,过滤和分页功能。我该怎么做?
我想要一些有关如何在Javascript和Ajax中使用数据表的知识。
答案 0 :(得分:0)
您可以考虑使用此解决方案。它需要一些Python知识,尤其是Pandas(一个Python库)和Flask( microframework)。
使用此代码片段读取csv并转换为html表。
Python代码
@app.route("/")
def show_tables():
data = pd.read_csv("myfile.csv")
return render_template('index.html',tables=[re.sub(' mytable', '" id="example', data.to_html(classes='mytable'))],
titles = ['Excel Data to Flask'])
index.html
<!doctype html>
<head>
<link rel=stylesheet type=text/css href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel=stylesheet type=text/css href="https://cdn.datatables.net/plug-ins/f2c75b7247b/integration/bootstrap/3/dataTables.bootstrap.css">
<!--<link rel=stylesheet type=text/css href="https://cdn.datatables.net/responsive/1.0.4/css/dataTables.responsive.css"> -->
</head>
<body>
<div class=page>
{% for table in tables %}
<h2>{{titles[loop.index]}}</h2>
{{ table|safe }}
{% endfor %}
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"> </script>
<script src="https://cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js"> </script>
</body>
</html>
上阅读有关该主题的更多信息。
这将使您可以更轻松,更快速地读取csv文件,以及使用javascript datable。