ydn-js origin

YUI version 2.5.2

Factory function for enhancing tables from markup

Challenge

A page has several tables on it that need to be enhanced into DataTables.

Solution

Create a static factory method DataTable.enhanceTable(tbl,config) to encapsulate typical progressive enhancement cases. The function replaces the table element with a div assigned the same id and class attributes and uses that div as the new DataTable's container.

Caveats: The function has no column level configuration available. All columns are made sortable. Also, it is assumed that there are no nested column headers.

Your average table of foo

Foo Bar Baz
Foo 1 Bar 1 Baz 1
Foo 2 Bar 2 Baz 2
Foo 3 Bar 3 Baz 3
Foo 4 Bar 4 Baz 4
Foo 5 Bar 5 Baz 5

Table of colorful shapes

Color Shape Size
green cube small
blue sphere medium
purple cone small
black taurus large
red pyramid large

Scrabble tiles (English)

Letter Quantity Score
(blank)20
A91
B23
C23
D42
E121
F24
G32
H24
I91
J18
K15
L41
M23
N61
O81
P23
Q110
R61
S41
T61
U41
V24
W24
X18
Y24
Z110