Datatables can be made to scroll along the x and y axes. Include "`datatable-scroll`" in your `use()` line to enable the feature.

This example shows the basic scrolling configurations available.

Note: Scrolling is not currently supported on the Android WebKit browser.

Vertically Scrolling Table

Enable vertical scrolling by setting `scrollable` to "y" and assigning the `height`.

``` YUI().use('datatable-scroll', function (Y) { var state_census_data = [ ... ], table; {{>datatable-scroll-y-source}} }); ```

Horizontally Scrolling Table

Enable horizontal scrolling by setting `scrollable` to "x" and assigning the `width`.

``` YUI().use('datatable-scroll', function (Y) { var state_census_data = [ ... ], table; {{>datatable-scroll-x-source}} }); ```

Fully Scrolling Datatable

Enable scrolling along both axes by setting `scrollable` to `true` or "xy" and assigning both `height` and `width`.

``` YUI().use('datatable-scroll', function (Y) { var state_census_data = [ ... ], table; {{>datatable-scroll-xy-source}} }); ```

Using Percentage Widths

Scrolling DataTables support percentage `width`s. The table above is configured to scroll vertically with a `width` of "100%".

``` YUI().use('datatable-scroll', function (Y) { var state_census_data = [ ... ], table; {{>datatable-scroll-pct-source}} }); ```

The Data

This is the data that is used for each example table. The keys in each tables' `columns` correspond with the keys in the data.

``` var sampleData = [ { ANSI: "00000", STATE: "UNITED STATES", TOTAL_POP: 307006550, LAND_AREA: 3537438.44, POP_PER_SQ_MILE: 79.6 }, { ANSI: "01000", STATE: "ALABAMA", TOTAL_POP: 4708708, LAND_AREA: 50744, POP_PER_SQ_MILE: 87.6 }, { ANSI: "02000", STATE: "ALASKA", TOTAL_POP: 698473, LAND_AREA: 571951.26, POP_PER_SQ_MILE: 1.1 }, { ANSI: "04000", STATE: "ARIZONA", TOTAL_POP: 6595778, LAND_AREA: 113634.57, POP_PER_SQ_MILE: 45.2 }, ... ]; ```

Setting scrolling direction and dimensions

The values of `scrollable` and the respective dimensional attribute determine the scrolling direction(s) of each datatable instance.

Other things to consider are:

  1. If a DataTable is configured with `scrollable` of "y", but the `height` is not set, it will not be made scrollable. Likewise for "x" and `width`. The respective dimension attribute is required.
  2. If the configured `width` of an "x" or "xy" scrolling table is wider than necessary to fit the data, the table width will be expanded to the assigned `width`.
  3. If a DataTable is configured with `scrollable` of "y", but the `width` attribute is also set, DataTable will attempt to make the table that wide. But if the table data doesn't fit within the configured width, the table will expand naturally to fit the data.

Full Code Listing

{{>need-skin-note}} ``` {{>need-skin-comment}} ``` ``` {{>datatable-scroll-source}} ```