This example builds a DataTable based on the columns information taken from the server. Instead of building a statically defined DataTable it will build it on what the server says. It has been based on the server-side pagination and server-side sorting examples. They have both been changed in that they do not use the DataSource to communicate with the server but use a plain Connection Manager request to fetch the information and then pass it as a local source to the DataSource.
All the fetching of information is done in the
getPage method which establishes
the communication with the server and on return, if the DataTable already exists it refreshes it,
otherwise it creates it. In order to do that, if the DataTable does not exists, it adds a
meta=true argument to the URL so that the server provides the extra 'meta' information
for the client to build the DataTable. This information is not requested on further communications
as the table, at that point, is built and cannot be changed.
The YUI Loader part was skipped, since it added too many extra and confusing lines of code to the example. Instead the required files are loaded statically which is the way stated in the documentation of each of those components.
The paginator object within the DataTable has not been used. For all the DataTable knows, it has just a one-page table and is completely unaware that the table is any longer. The DataTable automatically updates the paginator based on this knowledge, no matter what you want to force it to believe, and it is pointless to fight it. See the Source Forge bug report about this. Besides, it seems to me far less obscure to keep those variables in plain view rather than using the paginator for what it was not designed to do.
The server is the same used in the examples mentioned above, except that it is now also capable
of adding the meta information if the URL argument 'meta' is true.
Just as the data it provides is taken from a static array contained in the source itself,
the meta information is also static and is basically a PHP array that will turn into a standard
DataTable columns definition array. In real cases, just as the data will probably be fetched from
a database, the meta information will also be read from it and properly processed into
column definitions. A hint of that is one of the fields that has been declared as of
'type' => 'number' in PHP parlance and on the client side this will add
parseNumber parser in the DataSource field declaration.
The source files for this sample are available for download in a zip file. The PHP server script requires an active PHP interpreter. The YUI compoments are fetched from the YUI site.