Thursday, July 11, 2013

Bootstrap add affix to first row in table .net DataGrid, GridView

This is one way to affix the first row of a table.

 var firstRow = $('#<%= ProductDataGrid.ClientID %> tr').eq(0); 
 var start = $(firstRow).offset().top; 

 //set the CSS width of each td in the first row so things line up when you scroll 

 firstRow.children().each(function () { 
      $(this).css("width", $(this).width()); 
      $(this).css("border-bottom", '1px solid'); 
 }); 

$(firstRow).css('background-color', 'white'); $(firstRow).attr('data-offset-top', start); $(firstRow).attr('data-spy', 'affix'); });