pgfplotstable; longtable with caption and repeating header

For some reasons, if you want to keep using pgfplotstable, this is the solution. Otherwise you may adopt @David's answer above. I have given some dummy data in the file.

\documentclass{article}

\usepackage{pgfplotstable}
\usepackage{longtable}
\usepackage{booktabs}
\usepackage{array}
\usepackage[a4paper,top=4in,bottom=4in,right=1in,left=1in]{geometry} %%% change the margins in your file suitably.
\usepackage{filecontents}
\begin{filecontents}{data.csv}
column1,column2
5001,102
5002,75
5003,115
5004,45
5005,97
5036,110
5037,77
5038,147
5039,89
5040,62
5041,160
5042,102
5043,56
5044,86
5100,74
5101,65
5102,131
5103,90
5104,99
\end{filecontents}%

\begin{document}

%%% Code from Dr. Christian ------ for not using headers.----------------------
\pgfkeysifdefined{/pgfplots/table/output empty row/.@cmd}{
    % upcoming releases offer this more convenient option:
    \pgfplotstableset{
        empty header/.style={
          every head row/.style={output empty row},
        }
    }
}{
    % versions up to and including 1.5.1 need this:
    \pgfplotstableset{
        empty header/.style={
            typeset cell/.append code={%
                \ifnum\pgfplotstablerow=-1 %
                    \pgfkeyssetvalue{/pgfplots/table/@cell content}{}%
                \fi
            }
        }
    }
}
%%%-----------------------------------------------

\pgfplotstabletypeset[
    empty header,
    begin table=\begin{longtable},
    every first row/.append style={before row={%
    \caption{This is a Table with Data}%
    \label{tab:DataTable}\\\toprule
    \textbf{column 1} &\textbf{column 2} \\ \toprule    
    \endfirsthead
    %
    \multicolumn{2}{c}%
    {{\bfseries Table \thetable\ Continued from previous page}} \\
    \toprule 
    %
    \textbf{column 1} &\textbf{column 2} \\ \toprule  
    \endhead
    %
    \midrule \multicolumn{2}{r}{{Continued on next page}} \\ \bottomrule
    \endfoot
    %
    \midrule
    \multicolumn{2}{r}{{Concluded}} \\ \bottomrule
    \endlastfoot
    }},%
    %
    end table=\end{longtable},
    col sep=comma,
    string type,
    ]{data.csv}

\end{document}

enter image description here

I used booktabs for lines and avoided putting a line after each row as it improves readability.


I think the package is making it seem more complicated than it need be.

I'd just input the csv file into a longtable

enter image description here


1,2
3,4
5,6
7,8
9,10
11,12

\documentclass{article}

\textheight5\baselineskip
\usepackage{longtable}
\begin{document}

\begingroup
\obeylines%
\catcode`\,=4 %
\def^^M{\\}%
\makeatletter%
\begin{longtable}{rr}%
\caption{a table of data}
\textbf{Column 1}&\textbf{Column 2}\endfirsthead%
\textbf{Column 1}&\textbf{Column 2}\endhead%
\@@input data.csv %
\end{longtable}%
\endgroup%

\end{document}