python - HTML 表格——在标题中放置链接进行排序? (无 JavaScript)

标签 python html django hyperlink

我正在动态生成一个表格以及列标题。

如何使列可点击(NO JavaScript!),以便在单击它们时,它们会向查询添加 sort=columnNameHere 条目,并且使用该查询重新加载当前页面?

最佳答案

了解您的服务器端语言会很有帮助,但由于您没有包含该语言,因此您需要代码输出 html,如下所示...

<table>
   <thead>
      <th><a href="test.html?sort=Name">Name</a></th>
      <th><a href="test.html?sort=Location">Location</a></th>
   </thead>
   <tr>
      <td>Bob</td>
      <td>Canada</td>
   </tr>
</table>

在服务器上,您需要确保从获取变量集合中获取排序变量并将其应用于源查询。在伪代码中,这将类似于:

   currentSort = Request["sort"] 
   data = db.Execute("select * from customersorder by " + sqlescape(currentSort))

  //write table header 
  foreach col in columns
    write("<th><a href='test.html?sort=" + col + "'>" + col + "</a>")

  //close header, start data 
  for each row in data    
    write...

关于python - HTML 表格——在标题中放置链接进行排序? (无 JavaScript),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6297149/

相关文章:

python - 使用 PdfMiner 和 PyPDF2 合并列提取文本

python - 在django中单页上传两个文件

django - 当 DEBUG = True 时,为什么断言会记录在 Sentry 中?

python - Hive查询使用Python返回空白,但直接查询时没有问题

python - 将列表中的项目添加到另一个列表中的字典

python - 使用 pandas 在依赖于另一列的一列上有效地应用操作

html - 在 HTML/CSS 中对齐导航栏中的文本?

html - div 上的不透明度过渡是随机的 "blocky"

javascript - 为什么使用JavaScript提交表单时,表单中没有提交输入和提交按钮?

django post_save 信号和 ManyToManyField(和 Django Admin)