[英]Sort HTML Table
I had created html table dynamically like this. 我已经像这样动态创建了html表。 Now I want to sort the table based on Name while clicking the Name Header in client side.
现在,我想在客户端上单击“名称标题”时根据名称对表进行排序。 How can I achieve this?
我该如何实现?
StringBuilder sb = new StringBuilder();
sb.Append("<table border='1' id='tblCustomers'>");
sb.Append("<tr>");
sb.Append("<th>");
sb.Append("Name");
sb.Append("</th>");
sb.Append("<th>");
sb.Append("City");
sb.Append("</th>");
sb.Append("</tr>");
for(int i=0; i< dtcustomers.count;i++)
{
sb.Append("<tr>");
sb.Append("<td>");
sb.Append(dtcustomers.Rows[i]["Name"]);
sb.Append("</td>");
sb.Append("<td>");
sb.Append(dtcustomers.Rows[i]["City"]);
sb.Append("</td>");
sb.Append("</tr>");
}
sb.Append("</table>");
this.mydiv.InnerHtml = sb.ToString();
由于您正在使用jQuery并希望在客户端完成此操作,因此可以尝试使用此方便的插件 。
This is also really useful: https://www.kryogenix.org/code/browser/sorttable/ 这也真的很有用: https : //www.kryogenix.org/code/browser/sorttable/
It gives you a js library to install and from there all you have to do is link it to your project with <script src="sorttable.js"></script>
and add a class to your table. 它为您提供了一个js库来安装,然后您只需使用
<script src="sorttable.js"></script>
将其链接到您的项目,然后将一个类添加到表中即可。 Really easy. 真的很容易
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.