2

In the following code, my dataset is {1,2,3,4}.

With no filter, DTLiffirstrow will return true at "1" and DTLiflastrow will return true at "4". This is what I expect from these functions.

When I filter the dataset to {2,3}, DTLiffisrtrow returns true at "2". Perfect.

But DTLiflastrow is always false. I would expect it to return true for the value "3".

\documentclass{article}

\usepackage{datatool}

\DTLnewdb{table}
\DTLnewrow{table}
\DTLnewdbentry{table}{C1}{1}
\DTLnewrow{table}
\DTLnewdbentry{table}{C1}{2}
\DTLnewrow{table}
\DTLnewdbentry{table}{C1}{3}
\DTLnewrow{table}
\DTLnewdbentry{table}{C1}{4}


\begin{document}


\DTLforeach*%
[\DTLisclosedbetween{\COne}{2}{3}]%
{table}%
{\COne=C1}%
{%
    \COne%
    \DTLiffirstrow{FIRST}{}%
    \DTLiflastrow{LAST}{}%
    \\%
}%

\end{document}

How could I detect the last row of a filtered set of data?

2
  • 1
    There's no way for datatool to know it's on the last filtered row on a single pass. It would require two passes: first to find out which is the last row of the filtered set and the second to compare the current row with that value. (datatool knows how many rows the database has but the last row may be filtered. \DTLiflastrow can only compare the current row index with the total number of rows.) Apr 1, 2019 at 15:23
  • @NicolaTalbot Could you provide an example? Apr 21, 2020 at 20:02

1 Answer 1

2

This is not a bug, it's a feature !

See the doc (datatool-code.pdf, around page 199):

\DTLiflastrow{〈true part 〉}{〈false part 〉}

Checks if the current row is the last row of the database. It doesn’t take the condition (the optional argument of \DTLforeach) into account, so its possible it may never do 〈true part〉, as the last row of the database may not meet the condition.

It is therefore not very useful and is confusing since it behaves differently to \DTLiffirstrow which does take the condition ...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .