<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">\documentclass[a4paper]{ltxdoc}

\usepackage[ocgtabular]{ocg-p}
\usepackage{tikz}
\usepackage{datatool} 
\usepackage{booktabs}

%\usepackage{array}

\newcommand*{\pkg}[1]{\textsf{#1}}

\title{\pkg{OCG-P} package, example 4}

\begin{document}

% generate database with data for the table 
\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}

\maketitle

\section{Without using the ocgtabular environment}
This table can be sorted by clicking on the headers: 

\begin{tikzpicture}
\begin{ocg}{First Name}{ocfirstid}{1}
  \node[] (p1)  {
\begin{tabular}{llc}
\toprule
\bfseries \setocgs{}{ocfirstid}{oclastid ocgradeid}{First name} 
&amp; \bfseries \setocgs{}{oclastid}{ocfirstid ocgradeid}{Last name} 
&amp; \bfseries \setocgs{}{ocgradeid}{ocfirstid oclastid}{Grade}
\DTLsort*{Firstname}{sdata}% sorted on the first name
\DTLforeach{sdata}{\first=Firstname, \last=Lastname,\grade=Grade}{%
\DTLiffirstrow{\\ \midrule}{\\}
\first &amp; \last &amp; \grade
}
\\ \bottomrule
\end{tabular}
};
\end{ocg}

\begin{ocg}{First Name}{oclastid}{0}
  \node[overlay]  (p2)  {
\begin{tabular}{llc}
\toprule
\bfseries \setocgs{}{ocfirstid}{oclastid ocgradeid}{First name} 
&amp; \bfseries \setocgs{}{oclastid}{ocfirstid ocgradeid}{Last name} 
&amp; \bfseries \setocgs{}{ocgradeid}{ocfirstid oclastid}{Grade}
\DTLsort*{Lastname}{sdata}% sorted on the last name
\DTLforeach{sdata}{\first=Firstname, \last=Lastname,\grade=Grade}{%
\DTLiffirstrow{\\ \midrule}{\\}
\first &amp; \last &amp; \grade 
}
\\ \bottomrule
\end{tabular}
};
\end{ocg}

\begin{ocg}{First Name}{ocgradeid}{0}
  \node[overlay] (p3)  {
\begin{tabular}{llc}
\toprule
\bfseries \setocgs{}{ocfirstid}{oclastid ocgradeid}{First name} 
&amp; \bfseries \setocgs{}{oclastid}{ocfirstid ocgradeid}{Last name} 
&amp; \bfseries \setocgs{}{ocgradeid}{ocfirstid oclastid}{Grade}
\DTLsort*{Grade}{sdata}% sorted on the grade
\DTLforeach{sdata}{\first=Firstname, \last=Lastname,\grade=Grade}{%
\DTLiffirstrow{\\ \midrule}{\\}
\first &amp; \last &amp; \grade
}
\\ \bottomrule
\end{tabular}
};
\end{ocg}

\end{tikzpicture}

\section{Using the ocgtabular environment}

This table can be sorted by clicking on the headers: 

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



\end{document}</pre></body></html>