\documentclass{article}
% MWE from http://tex.stackexchange.com/questions/40411/import-files-with-pgfplotstable-and-split-tables-across-multiple-pages
\usepackage{pgfplotstable}
\usepackage{fr-longtable}
\usepackage{booktabs}
\usepackage{array}
\usepackage[a4paper]{geometry} %%% change the margins in your file suitably.
\usepackage{filecontents}

\newcolumntype{C}{>{\centering\arraybackslash}p}

\begin{document}

\pgfplotstableset{
begin table=\begin{longtable},
end table=\end{longtable},
}

\pgfplotstabletypeset[
col sep=space,
header=true,
columns={Idx,Nam,Dim,Grd},      % display specified columns
columns/Idx/.style={precision=2,column type=|C{40mm}},
columns/Nam/.style={column type=|C{40mm},string type},
columns/Dim/.style={precision=1,column type=|r},
columns/Grd/.style={column type=|l|,string type},
every even row/.style={after row=\hline},
every odd row/.style={after row=\hline},
% requires booktabs to place horiz rules
every head row/.style={before row=\toprule, after row=\midrule\endhead},
every head row/.style={
  before row={%
    \caption{The caption}
    \endfirsthead
    \multicolumn{4}{c}{{\tablename\ \thetable{}: continued from previous page}} \\
    \endhead
    \multicolumn{4}{c}{{\tablename\ \thetable{}: last page}} \\
    \endlasthead
    \hline
  },
  after row=\hline
}
]{test.dat}

\end{document}

