点击标题可排序表格

时间:2014-04-01 12:28:36

标签: javascript pdf tabular

是否可以在TeX中创建一个表并编译成PDF,其中有列标题,点击它们会按该列对(数字)表内容进行排序?

我知道你可以在PDF中以某种方式使用Javascript,这可能会允许这样的事情。

有没有人做过这样的事情?

1 个答案:

答案 0 :(得分:4)

在我的评论之后,对于OCG图层应该是可行的,我发现ocg-p包提供了ocgtabular环境,这完全符合您的要求。

取自ocg-p doc:

的示例
\documentclass{article}
\usepackage[ocgtabular]{ocg-p}
\usepackage{datatool} % will be needed for this example
\usepackage{booktabs} % will be needed for this example
\DTLnewdb{sdata}
\DTLnewrow{sdata}
\DTLnewdbentry{sdata}{Firstname}{John}
\DTLnewdbentry{sdata}{Lastname}{Doe}
\DTLnewdbentry{sdata}{Grade}{5}
\DTLnewrow{sdata}
\DTLnewdbentry{sdata}{Firstname}{Paul}
\DTLnewdbentry{sdata}{Lastname}{Bauer}
\DTLnewdbentry{sdata}{Grade}{1}
\DTLnewrow{sdata}
\DTLnewdbentry{sdata}{Firstname}{Peggy}
\DTLnewdbentry{sdata}{Lastname}{Sue}
\DTLnewdbentry{sdata}{Grade}{3}
\DTLnewrow{sdata}
\DTLnewdbentry{sdata}{Firstname}{Ever}
\DTLnewdbentry{sdata}{Lastname}{Last}
\DTLnewdbentry{sdata}{Grade}{4}
\DTLnewrow{sdata}
\DTLnewdbentry{sdata}{Firstname}{Werner}
\DTLnewdbentry{sdata}{Lastname}{Moshammer}
\DTLnewdbentry{sdata}{Grade}{1}
\begin{document}
This table can be sorted by clicking on the headers:

\begin{ocgtabular}{llc}{sdata}{}
\toprule%
\bfseries \setocgtabularheader{Firstname}{First name}
& \bfseries \setocgtabularheader{Lastname}{Last name}
& \bfseries \setocgtabularheader{Grade}{Grade}
\DTLforeach{sdata}{\first=Firstname, \last=Lastname,\grade=Grade}{%
\DTLiffirstrow{\\ \midrule}{\\}
\first & \last & \grade
}
\\ \bottomrule%
\end{ocgtabular}
\end{document}

sorted by Firstname sorted by Lastname sorted by Grade