15

FIXED HEADER TABLE ____When Clicking on scrollbar icon in ie11 flickers when using positioning as i cannot change the structure as it is dynamically coming from different sources and gets in table body structure

<tbody><tr></tr><tr></tr></tbody>

here is the fiddle attached works fine in chrome but when i check in ie it flickers horriblly when clicking on div vertical scrollbar below or above icon

Any Css or html solution is also acceptable until if there is no change in html structure

DEMOJs Fiddle Demo enter image description here JQUERY

   $(document).ready(function() {
$('#theDiv').on('scroll', function () { 
                $('#headerRow td,#headerRow th').css({'position':'relative','background':'red','top':$('#theDiv').scrollTop()-1});
});
    });
Nadeemmnn Mohd
  • 713
  • 5
  • 14

5 Answers5

1

First we wrap #theDiv in a #theDivWrap (using jQuery) and use the css to style it...

The idea is to duplicate header row into a new div appended to #theDivWrap via JS

Now loop through table heading elements and create a div based similar styled heading which will come over table and is prepended to #theDivWrap and stays there forever even on scroll because wrap is not overflow auto...

https://jsfiddle.net/5dqnumh6/39/

Adjust negative margin bottom of .headerRow to suit your needs ;)

shramee
  • 5,030
  • 1
  • 22
  • 46
  • just add `$('
    ').addClass('headerRow').css({'width': tableWidth,'position':'relative'});` in div id `'#headerRow` it will work
    – aditya shrivastava Jun 14 '17 at 08:17
  • Well, options are limited coz we can't change HTML of table, try setting setting `visibility:hidden` inline style on `#theDiv` and remove it in JS after duplicate header is set up... ;) To avoid partially rendered display... – shramee Jun 14 '17 at 11:02
  • https://jsfiddle.net/5dqnumh6/39/ Try this one, it will show original header until new one is loaded ;) – shramee Jun 14 '17 at 11:06
  • Two issues still persist. issue 1 little flicker on header,as it is taking time and secondly my vertical scroll goes inside where as in the above screenshot in the example vertical scroll is visible..http://jsfiddle.net/nadeemmnn2007/5dqnumh6/40/ – Nadeemmnn Mohd Jun 14 '17 at 12:45
  • Well appreciate your efforts, and can we have something small like i wrote without creating new header on top, as if network is slow or records or more then loading performance issues raises – Nadeemmnn Mohd Jun 14 '17 at 12:48
  • @shramee this is not working if we are using dynamic localization, clonned header is not fetching latest language – Swati Singh Aug 29 '20 at 08:32
1

As Ie doesn't support overflow property for table group elements. So we can add a workaround to support the required behaviour. Add this css to your fiddle and try it will work.

tbody{display:block;height:auto;}

This will make your flicker go away in ie older versions. Although its a hack to make it work but there is no other pure css way. For more details and explanation you may want to read this link. Updated fiddle is here. But as you told me flickering not goes away.A workaround exists but it requires changing in ie settings. Go to internet options, navigate to advanced and scroll down until you see browsing section and uncheck "enable smooth scrolling". But I don't know whether it suits your requirement or not

breakit
  • 356
  • 2
  • 8
  • on scroll flickerring goes in ie but on click of up arrow and down arrow still flickers in ie – Nadeemmnn Mohd Jun 15 '17 at 09:33
  • Unfortunately this bug is not solved yet for ie. You have to experience flickering issue as on scrolling it takes time to update scrollbar transition in ie. you can remove your border-collapse property for better visual representations. i have updated my answer to remove smooth scrolling in ie which will help but you have to manually reset it from ie options – breakit Jun 15 '17 at 13:33
  • my badluck cannot say individual user to do settings for ie,one bad news is in ie5 it works like charm becoz of expressions without using any jquery also, – Nadeemmnn Mohd Jun 15 '17 at 15:02
0

This has been noted to be an IE11 bug, and according to this other SO question from 2014, shows up under the following conditions:

Three things can cause IE 11 flickering/choppy/delay for fixed position element while scrolling:

  1. If you have an "overflow: auto;" on the parent container element, remove it.
  2. Remove background-attachment:fixed; from the fixed position element.
  3. Remove border-radius from the fixed position element (mobile IE only).

    (Accepted answer by @Adamy)

Well, removing auto-overflow from your code takes away the whole purpose, so it's not the best solution here, and the others don't apply. What seems to work however (according to this MS Connect bug) is some HTML changes, separating the header row, and adding a custom scroll function to the actual table body. This JsFiddle page (kindly provided by folks that responded to the MS bug) has a working example:

https://jsfiddle.net/84y0vtyx/

(Including only part of the example with relevant comment. Full explanation requires reviewing the JsFiddle example.)

/* Only WinIE will fire this function. All other browsers scroll the TBODY element and not the DIV */
/* This is to hide the SELECT elements from scrolling over the fixed Header. WinIE only.           */
/* toggleSelectBoxes added on 2005-01-28 */
/* Terence Ordona, portal[AT]imaputz[DOT]com         */


window.onload = function() { addIEonScroll(); }
Cahit
  • 2,484
  • 19
  • 23
  • i cannot saperate the structure.. like thead and row content. that is where i have a problem. as that code is nested jsp code which is generated in tbody – Nadeemmnn Mohd Jun 12 '17 at 07:43
0

Hi here is my update based on your comment. I copied the HTML part from your js Fiddle and just added this style tag to the above the table div and it works perfectly in microsoft edge and other browsers with no Jquery needed:

<style>

 #headerRow
 {  
   position: fixed !important;
   top:0px;
   background:Red;
 }

</style>

////OLD

I apologies as you have mentioned that you cannot change the html table structure that comes down however see my old answer below which i wrote without this consideration. Can you consider using css to traverse the fixed table that comes down and apply a fixed position to the top header row? I have read that you can give a fixed position and a background color to a table row so that it remains fixed and the background prevents the text from overlapping How to make table row fixed at the top

You can use css to select the top row of the table: Css:

 table tr:first-child
 {  
   position: fixed;
   top:0px;
   background:#FFF;
 }

/// old answer:

Please may i suggest that you forget about using a document scroll event and just create a header with an absolute position if it is a div with an overflow scroll or a fixed position if it is just to remain fixed as the window scrolls. you can specify widths for your colums so that the fixed header lines up. so something along these lines (im just typing on my phone):

 <table style="position:fixed; width:100% ">
    <tr>
       <th width="50%">
        Test1
       </th>
       <th width="50%">
         Test2
        </th>
    </tr>
 </table>
 <table style="margin-top:25px; width:100% ">
      <tr>
          <td width="50%">
             a
          </td>
          <td width="50%">
           b
          </td>
          </tr>
          <tr>
          <td width="50%">
             c
           </td>
         <td width="50%">
          d
         </td>
       </tr>
   </table>

Especialy if we are talking cross browser compatibilty here- the simpler and most basic html/ css implementation the better. Css has provided us with a fixed class. There is no need to use jquery to watch your documents scroll.

Harry
  • 3,930
  • 2
  • 14
  • 31
0

I use this one my site:

https://raw.githubusercontent.com/jmosbech/StickyTableHeaders/master/js/jquery.stickytableheaders.min.js

Simply load it in your <head></head> section of the page and it will float the header of any table loaded on that page. It's cross-browser and gets the job done with no additional tricks, just plug & play.

Ivan
  • 1,274
  • 16
  • 22