Created
April 17, 2012 17:07
-
-
Save eralston/2407521 to your computer and use it in GitHub Desktop.
jQuery Plug-In to fix .Net DataGrid Output into Something DataTables Can Accept
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// .Net DataGrid spits out only a tbody for the entire table, but http://datatables.net/ needs thead as well | |
// This yanks out the first row of the table, assumed to be the header row, then places it within a new thead | |
// Should be called like this: #("#dot_net_table_id").convertFirstTableRowToHeader().dataTable(); | |
// | |
(function ($) { | |
$.fn.convertFirstTableRowToHeader = function () { | |
return this.each(function () { | |
var table = $(this); | |
if (!table.is("table")) | |
return; | |
var firstRow = table.find("tr").first().detach(); | |
$("<thead></thead>").append(firstRow).insertBefore(table.find("tbody")); | |
}); | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment