点击标题可排序表格

mor*_*usg 8 javascript pdf tabular

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

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

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

小智 4

在我发表评论后,OCG 层应该可以做到这一点,我刚刚发现该ocg-p软件包提供了ocgtabular环境,它正是您想要的。

取自ocg-p文档的示例:

\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}
Run Code Online (Sandbox Code Playgroud)

按名字排序 按姓氏排序 按年级排序