YUI Library Home

Site Search (YDN & YUIBlog):

# YUI Library Examples: DataTable Control: Skinning Model

# DataTable Control: Skinning Model

This example demonstrates the CSS applied to an implementation of the DataTable control that uses the "Sam Skin". You can read more about the general approach to skinning YUI components in this in-depth article. Change any or all of the skin CSS (but not the core CSS) for a more customized look and feel.

Please note that as of version 2.6.0, all state-related CSS classes, such as "yui-dt-resizeable", "yui-dt-sortable", "yui-dt-first", or "yui-dt-odd" are now assigned directly on TH and TD elements, not on liner DIV elements.

## Sample Code

DOM Overview:

<div id="myContainer" class="yui-dt"> <div class="yui-dt-mask" style="display: none;"/> <table summary=""> <colgroup> <col/> <col/> <col/> <col/> <col/> </colgroup> <thead> <tr class="yui-dt-first yui-dt-last"> <th id="yui-dt0-th-{sanitizedkey}" rowspan="1" colspan="1" class="yui-dt0-col-{sanitizedkey} yui-dt-col-{sanitizedkey} yui-dt-sortable yui-dt-resizeable yui-dt-first yui-dt-asc"> <div class="yui-dt-resizerliner"> <div id="yui-dt0-th-{sanitizedkey}-liner" class="yui-dt-liner"> <span class="yui-dt-label"> <a class="yui-dt-sortable" title="Click to sort ascending" href="yui-dt0-href-{sanitizedkey}">Header A</a> </span> </div> <div id="yui-dt0-th-{sanitizedkey}-resizer" class="yui-dt-resizer" style="left: auto; right: 0pt; top: auto; bottom: 0pt; height: 24px;"/> </div> </th> <th id="yui-dt0-th-{sanitizedkey}" rowspan="1" colspan="1" class="yui-dt0-col-{sanitizedkey} yui-dt-col-{sanitizedkey} yui-dt-sortable yui-dt-resizeable"> <div class="yui-dt-resizerliner"> <div id="yui-dt0-th-{sanitizedkey}-liner" class="yui-dt-liner"> <span class="yui-dt-label"> <a class="yui-dt-sortable" title="Click to sort descending" href="yui-dt0-href-{sanitizedkey}">Header B</a> </span> </div> <div id="yui-dt0-th-{sanitizedkey}-resizer" class="yui-dt-resizer" style="left: auto; right: 0pt; top: auto; bottom: 0pt; height: 24px;"/> </div> </th> <th id="yui-dt0-th-{sanitizedkey}" rowspan="1" colspan="1" class="yui-dt0-col-{sanitizedkey} yui-dt-col-{sanitizedkey} yui-dt-sortable yui-dt-resizeable"> <div class="yui-dt-resizerliner"> <div id="yui-dt0-th-{sanitizedkey}-liner" class="yui-dt-liner"> <span class="yui-dt-label"> <a class="yui-dt-sortable" title="Click to sort ascending" href="yui-dt0-href-{sanitizedkey}">Header C</a> </span> </div> <div id="yui-dt0-th-{sanitizedkey}-resizer" class="yui-dt-resizer" style="left: auto; right: 0pt; top: auto; bottom: 0pt; height: 24px;"/> </div> </th> <th id="yui-dt0-th-{sanitizedkey}" rowspan="1" colspan="1" class="yui-dt0-col-{sanitizedkey} yui-dt-col-{sanitizedkey} yui-dt-sortable yui-dt-resizeable"> <div class="yui-dt-resizerliner"> <div id="yui-dt0-th-{sanitizedkey}-liner" class="yui-dt-liner"> <span class="yui-dt-label"> <a class="yui-dt-sortable" title="Click to sort ascending" href="yui-dt0-href-{sanitizedkey}">Header D</a> </span> </div> <div id="yui-dt0-th-{sanitizedkey}-resizer" class="yui-dt-resizer" style="left: auto; right: 0pt; top: auto; bottom: 0pt; height: 24px;"/> </div> </th> <th id="yui-dt0-th-{sanitizedkey}" rowspan="1" colspan="1" class="yui-dt0-col-{sanitizedkey} yui-dt-col-{sanitizedkey} yui-dt-sortable yui-dt-resizeable yui-dt-last"> <div class="yui-dt-resizerliner"> <div id="yui-dt0-th-{sanitizedkey}-liner" class="yui-dt-liner"> <span class="yui-dt-label"> <a class="yui-dt-sortable" title="Click to sort ascending" href="yui-dt0-href-{sanitizedkey}">Header E</a> </span> </div> <div id="yui-dt0-th-{sanitizedkey}-resizer" class="yui-dt-resizer" style="left: auto; right: 0pt; top: auto; bottom: 0pt; height: 24px;"/> </div> </th> </tr> </thead> <caption> DataTable Caption </caption> <tbody class="yui-dt-message" style="display: none;"> <tr class="yui-dt-first yui-dt-last"> <td colspan="5" class="yui-dt-loading"> <div class="yui-dt-liner"> Loading... </div> </td> </tr> </tbody> <tbody tabindex="0" class="yui-dt-data" style=""> <tr style="" id="yui-rec0" class="yui-dt-first yui-dt-even"> <td headers="yui-dt0-th-{sanitizedkey} " class="yui-dt0-col-{sanitizedkey} yui-dt-col-{sanitizedkey} yui-dt-sortable yui-dt-resizeable yui-dt-first yui-dt-asc"> <div class="yui-dt-liner"> Cell A </div> </td> <td headers="yui-dt0-th-{sanitizedkey} " class="yui-dt0-col-{sanitizedkey} yui-dt-col-{sanitizedkey} yui-dt-sortable yui-dt-resizeable"> <div class="yui-dt-liner"> Cell B </div> </td> <td headers="yui-dt0-th-{sanitizedkey} " class="yui-dt0-col-{sanitizedkey} yui-dt-col-{sanitizedkey} yui-dt-sortable yui-dt-resizeable"> <div class="yui-dt-liner"> Cell C </div> </td> <td headers="yui-dt0-th-{sanitizedkey} " class="yui-dt0-col-{sanitizedkey} yui-dt-col-{sanitizedkey} yui-dt-sortable yui-dt-resizeable"> <div class="yui-dt-liner"> Cell D </div> </td> <td headers="yui-dt0-th-{sanitizedkey} " class="yui-dt0-col-{sanitizedkey} yui-dt-col-{sanitizedkey} yui-dt-sortable yui-dt-resizeable yui-dt-last"> <div class="yui-dt-liner"> Cell E </div> </td> </tr> ... <tr style="" id="yui-rec3" class="yui-dt-last yui-dt-odd"> <td headers="yui-dt0-th-{sanitizedkey} " class="yui-dt0-col-{sanitizedkey} yui-dt-col-{sanitizedkey} yui-dt-sortable yui-dt-resizeable yui-dt-first yui-dt-asc"> <div class="yui-dt-liner"> Cell A </div> </td> <td headers="yui-dt0-th-{sanitizedkey} " class="yui-dt0-col-{sanitizedkey} yui-dt-col-{sanitizedkey} yui-dt-sortable yui-dt-resizeable"> <div class="yui-dt-liner"> Cell B </div> </td> <td headers="yui-dt0-th-{sanitizedkey} " class="yui-dt0-col-{sanitizedkey} yui-dt-col-{sanitizedkey} yui-dt-sortable yui-dt-resizeable"> <div class="yui-dt-liner"> Cell C </div> </td> <td headers="yui-dt0-th-{sanitizedkey} " class="yui-dt0-col-{sanitizedkey} yui-dt-col-{sanitizedkey} yui-dt-sortable yui-dt-resizeable"> <div class="yui-dt-liner"> Cell D </div> </td> <td headers="yui-dt0-th-{sanitizedkey} " class="yui-dt0-col-{sanitizedkey} yui-dt-col-{sanitizedkey} yui-dt-sortable yui-dt-resizeable yui-dt-last"> <div class="yui-dt-liner"> Cell E </div> </td> </tr> </tbody> </table> </div>

Core CSS:

/* foundational CSS */ /* mask */ .yui-skin-sam .yui-dt-mask { position:absolute; z-index:9500; } /* scrollable */ .yui-dt-tmp { position:absolute; left:-9000px; } .yui-dt-scrollable .yui-dt-bd { overflow:auto; } .yui-dt-scrollable .yui-dt-hd { overflow:hidden; position:relative; /* for ie overflow bug http://rowanw.com/bugs/overflow_relative.htm */ } .yui-dt-scrollable .yui-dt-bd thead tr, .yui-dt-scrollable .yui-dt-bd thead th { position:absolute; left:-1500px; } .yui-dt-scrollable tbody { -moz-outline:none; } /* draggable columns */ .yui-dt-draggable { cursor: move; } .yui-dt-coltarget { position: absolute; z-index: 999; } /* resizeable columns */ .yui-dt-hd { zoom:1; } th.yui-dt-resizeable .yui-dt-resizerliner { position:relative; } .yui-dt-resizer { position:absolute; right:0; bottom:0; height:100%; cursor:e-resize; cursor:col-resize; background-color:#CCC;opacity:0;filter: alpha(opacity=0); /* Bug 1952811: IE transparency z-index */ } .yui-dt-resizerproxy { visibility:hidden; position:absolute; z-index:9000; } /* hidden columns */ th.yui-dt-hidden .yui-dt-liner, td.yui-dt-hidden .yui-dt-liner, th.yui-dt-hidden .yui-dt-resizer { /*TODO: document change from 2.5.2 to 2.6 margin:0; padding:0; white-space:nowrap; width:1px; overflow:hidden;*/ display:none; } /* editing */ .yui-dt-editor { position:absolute;z-index:9000; }

Skin CSS:

/* basic skin styles */ .yui-skin-sam .yui-dt table { margin:0;padding:0; font-family:arial;font-size:inherit; border-collapse:separate;*border-collapse:collapse;border-spacing:0; /* since ie6 and ie7 behave differently */ border:1px solid #7F7F7F; } .yui-skin-sam .yui-dt thead {border-spacing:0;} /* for safari bug */ .yui-skin-sam .yui-dt caption { color:#000000; font-size:85%; font-weight:normal; font-style:italic; line-height:1; padding:1em 0pt; text-align:center; } .yui-skin-sam .yui-dt th { background:#D8D8DA url(../../../../assets/skins/sam/sprite.png) repeat-x 0 0; /* header gradient */ } .yui-skin-sam .yui-dt th, .yui-skin-sam .yui-dt th a { font-weight:normal;text-decoration:none;color:#000; /* header text */ vertical-align:bottom; } .yui-skin-sam .yui-dt th { margin:0;padding:0; border:none; border-right:1px solid #CBCBCB;/* inner column border */ } .yui-skin-sam .yui-dt tr.yui-dt-first td { border-top:1px solid #7F7F7F; /* tbody top border */ } .yui-skin-sam .yui-dt th .yui-dt-liner { white-space:nowrap; } .yui-skin-sam .yui-dt-liner { margin:0;padding:0; padding:4px 10px 4px 10px; /* cell padding */ } .yui-skin-sam .yui-dt-coltarget { width: 5px; background-color: red; } .yui-skin-sam .yui-dt td { margin:0;padding:0; border:none; border-right:1px solid #CBCBCB; /* inner column border */ text-align:left; } .yui-skin-sam .yui-dt-list td { border-right:none; /* disable inner column border in list mode */ } .yui-skin-sam .yui-dt-resizer { width:6px; } /* mask */ .yui-skin-sam .yui-dt-mask { background-color: #000; opacity: .25; *filter: alpha(opacity=25); /* Set opacity in IE */ } /* messaging */ .yui-skin-sam .yui-dt-message { background-color:#FFF; } /* scrolling */ .yui-skin-sam .yui-dt-scrollable table {border:none;} .yui-skin-sam .yui-dt-scrollable .yui-dt-hd {border-left:1px solid #7F7F7F;border-top:1px solid #7F7F7F;border-right:1px solid #7F7F7F;} .yui-skin-sam .yui-dt-scrollable .yui-dt-bd {border-left:1px solid #7F7F7F;border-bottom:1px solid #7F7F7F;border-right:1px solid #7F7F7F;background-color:#FFF;} .yui-skin-sam .yui-dt-scrollable .yui-dt-data tr.yui-dt-last td {border-bottom:1px solid #7F7F7F;} /* sortable columns */ .yui-skin-sam thead .yui-dt-sortable { cursor:pointer; } .yui-skin-sam th.yui-dt-asc, .yui-skin-sam th.yui-dt-desc { background:url(../../../../assets/skins/sam/sprite.png) repeat-x 0 -100px; /* sorted header gradient */ } .yui-skin-sam th.yui-dt-sortable .yui-dt-label { margin-right:10px; } .yui-skin-sam th.yui-dt-asc .yui-dt-liner { background:url(dt-arrow-up.png) no-repeat right; /* sorted header gradient */ } .yui-skin-sam th.yui-dt-desc .yui-dt-liner { background:url(dt-arrow-dn.png) no-repeat right; /* sorted header gradient */ } /* editing */ tbody .yui-dt-editable { cursor:pointer; } .yui-dt-editor { text-align:left; background-color:#F2F2F2; border:1px solid #808080; padding:6px; } .yui-dt-editor label { padding-left:4px;padding-right:6px; } .yui-dt-editor .yui-dt-button { padding-top:6px;text-align:right; } .yui-dt-editor .yui-dt-button button { background:url(../../../../assets/skins/sam/sprite.png) repeat-x 0 0; border:1px solid #999; width:4em;height:1.8em; margin-left:6px; } .yui-dt-editor .yui-dt-button button.yui-dt-default { background:url(../../../../assets/skins/sam/sprite.png) repeat-x 0 -1400px; background-color: #5584E0; border:1px solid #304369; color:#FFF } .yui-dt-editor .yui-dt-button button:hover { background:url(../../../../assets/skins/sam/sprite.png) repeat-x 0 -1300px; color:#000; } .yui-dt-editor .yui-dt-button button:active { background:url(../../../../assets/skins/sam/sprite.png) repeat-x 0 -1700px; color:#000; } /* striping */ .yui-skin-sam tr.yui-dt-even { background-color:#FFF; } /* white */ .yui-skin-sam tr.yui-dt-odd { background-color:#EDF5FF; } /* light blue */ .yui-skin-sam tr.yui-dt-even td.yui-dt-asc, .yui-skin-sam tr.yui-dt-even td.yui-dt-desc { background-color:#EDF5FF; } /* light blue sorted */ .yui-skin-sam tr.yui-dt-odd td.yui-dt-asc, .yui-skin-sam tr.yui-dt-odd td.yui-dt-desc { background-color:#DBEAFF; } /* dark blue sorted */ /* disable striping in list mode */ .yui-skin-sam .yui-dt-list tr.yui-dt-even { background-color:#FFF; } /* white */ .yui-skin-sam .yui-dt-list tr.yui-dt-odd { background-color:#FFF; } /* white */ .yui-skin-sam .yui-dt-list tr.yui-dt-even td.yui-dt-asc, .yui-skin-sam .yui-dt-list tr.yui-dt-even td.yui-dt-desc { background-color:#EDF5FF; } /* light blue sorted */ .yui-skin-sam .yui-dt-list tr.yui-dt-odd td.yui-dt-asc, .yui-skin-sam .yui-dt-list tr.yui-dt-odd td.yui-dt-desc { background-color:#EDF5FF; } /* light blue sorted */ /* highlighting */ .yui-skin-sam th.yui-dt-highlighted, .yui-skin-sam th.yui-dt-highlighted a { background-color:#B2D2FF; /* med blue hover */ } .yui-skin-sam tr.yui-dt-highlighted, .yui-skin-sam tr.yui-dt-highlighted td.yui-dt-asc, .yui-skin-sam tr.yui-dt-highlighted td.yui-dt-desc, .yui-skin-sam tr.yui-dt-even td.yui-dt-highlighted, .yui-skin-sam tr.yui-dt-odd td.yui-dt-highlighted { cursor:pointer; background-color:#B2D2FF; /* med blue hover */ } /* enable highlighting in list mode */ .yui-skin-sam .yui-dt-list th.yui-dt-highlighted, .yui-skin-sam .yui-dt-list th.yui-dt-highlighted a { background-color:#B2D2FF; /* med blue hover */ } .yui-skin-sam .yui-dt-list tr.yui-dt-highlighted, .yui-skin-sam .yui-dt-list tr.yui-dt-highlighted td.yui-dt-asc, .yui-skin-sam .yui-dt-list tr.yui-dt-highlighted td.yui-dt-desc, .yui-skin-sam .yui-dt-list tr.yui-dt-even td.yui-dt-highlighted, .yui-skin-sam .yui-dt-list tr.yui-dt-odd td.yui-dt-highlighted { cursor:pointer; background-color:#B2D2FF; /* med blue hover */ } /* selection */ .yui-skin-sam th.yui-dt-selected, .yui-skin-sam th.yui-dt-selected a { background-color:#446CD7; /* bright blue selected cell */ } .yui-skin-sam tr.yui-dt-selected td, .yui-skin-sam tr.yui-dt-selected td.yui-dt-asc, .yui-skin-sam tr.yui-dt-selected td.yui-dt-desc { background-color:#426FD9; /* bright blue selected row */ color:#FFF; } .yui-skin-sam tr.yui-dt-even td.yui-dt-selected, .yui-skin-sam tr.yui-dt-odd td.yui-dt-selected { background-color:#446CD7; /* bright blue selected cell */ color:#FFF; } /* enable selection in list mode */ .yui-skin-sam .yui-dt-list th.yui-dt-selected, .yui-skin-sam .yui-dt-list th.yui-dt-selected a { background-color:#446CD7; /* bright blue selected cell */ } .yui-skin-sam .yui-dt-list tr.yui-dt-selected td, .yui-skin-sam .yui-dt-list tr.yui-dt-selected td.yui-dt-asc, .yui-skin-sam .yui-dt-list tr.yui-dt-selected td.yui-dt-desc { background-color:#426FD9; /* bright blue selected row */ color:#FFF; } .yui-skin-sam .yui-dt-list tr.yui-dt-even td.yui-dt-selected, .yui-skin-sam .yui-dt-list tr.yui-dt-odd td.yui-dt-selected { background-color:#446CD7; /* bright blue selected cell */ color:#FFF; } /* pagination */ .yui-skin-sam .yui-dt-paginator { display:block;margin:6px 0;white-space:nowrap; } .yui-skin-sam .yui-dt-paginator .yui-dt-first, .yui-skin-sam .yui-dt-paginator .yui-dt-last, .yui-skin-sam .yui-dt-paginator .yui-dt-selected { padding:2px 6px; } .yui-skin-sam .yui-dt-paginator a.yui-dt-first, .yui-skin-sam .yui-dt-paginator a.yui-dt-last { text-decoration:none; } .yui-skin-sam .yui-dt-paginator .yui-dt-previous, .yui-skin-sam .yui-dt-paginator .yui-dt-next { display:none; } .yui-skin-sam a.yui-dt-page { border:1px solid #CBCBCB; padding:2px 6px; text-decoration:none; background-color:#fff } .yui-skin-sam .yui-dt-selected { border:1px solid #fff; background-color:#fff; }

### DataTable Control Examples:

- Basic Example
- Progressive Enhancement
- Custom Cell Formatting
- Conditional row coloring
- Nested Headers
- JSON Data Over XHR
- XML Data Over XHR With POST
- Textual Data Over XHR
- Local XML Data
- Adding and Deleting Rows
- Client-side Pagination
- Client-side Sorting
- Server-side Pagination and Sorting for Dynamic Data
- XY-scrolling, Y-scrolling, and X-scrolling
- Row Selection
- Cell Selection
- Inline Cell Editing
- Context Menu Integration
- Showing, Hiding, and Reordering Columns.
- Highlighting Cells, Rows, or Columns
- Complex Example of Multiple Features
- Datatable with Autocomplete
- Skinning Model
- Configuring the Paginator (included with examples for Paginator)
- Complex Application (included with examples for Layout Manager)

### More DataTable Control Resources:

- User's Guide (external)
- API Documentation
- Cheat Sheet PDF (external)

Copyright © 2008 Yahoo! Inc. All rights reserved.

Privacy Policy - Terms of Service - Copyright Policy - Job Openings