ydn-js origin

YUI version 2.5.1

Changing columns in a server side DataTable

Challenge

Create a single DataTable, but support multiple column configurations per a managed "viewing mode".

Solution

Create one DataSource with field declarations for all possible columns. Create a state collection for the various viewing modes containing the appropriate column configuration for that mode. Use YAHOO.util.Cookie to remember the last state across page refreshes. Create a custom method to manually handle the DataSource interaction, passing the mode in the request payload for storage in a custom doBeforeLoadData method on the DataTable. In this method, use the DataTable methods _initColumnSet and _initTheadEls to refresh the DataTable ColumnSet object and header display.

Viewing mode