- function emulateTHead( $table ) {
- var $thead = $( '<thead>' );
- $table.find( 'tr' ).each( function() {
- if ( $(this).children( 'td' ).length > 0 ) {
- // This row contains a <td>, so it's not a header row
- // Stop here
- return false;
- }
- $thead.append( this );
- } );
- $table.prepend( $thead );
+ function emulateTHeadAndFoot( $table ) {
+ var $rows = $table.find( 'tr' );
+ if( !$table.get(0).tHead ) {
+ var $thead = $( '<thead>' );
+ $rows.each( function() {
+ if ( $(this).children( 'td' ).length > 0 ) {
+ // This row contains a <td>, so it's not a header row
+ // Stop here
+ return false;
+ }
+ $thead.append( this );
+ } );
+ $table.prepend( $thead );
+ }
+ if( !$table.get(0).tFoot ) {
+ var $tfoot = $( '<tfoot>' );
+ var len = $rows.length;
+ for ( var i = len-1; i >= 0; i-- ) {
+ if( $( $rows[i] ).children( 'td' ).length > 0 ){
+ break;
+ }
+ $tfoot.prepend( $( $rows[i] ));
+ }
+ $table.append( $tfoot );
+ }