Skip to content

Instantly share code, notes, and snippets.

@eralston
Created April 17, 2012 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eralston/2407521 to your computer and use it in GitHub Desktop.
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
//
// .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