114

My website has always run smoothly with IE8, IE7, FF, Chrome and Safari. Now I'm testing it on IE9 and I'm experiencing a strange problem: in some pages, some tabular data renders incorrectly.

The HTML source is correct and all, and the row giving the problem changes every time I refresh the page (to tell the truth, the problem itself appears only in some refresh, not all).

Using the F12 Tool of IE, the table structure appears correct, there should be no empty TD after the TD containing M08000007448, but still it renders like this.

Moreover, if I use the F12 tool, with "select element by click" tool in the toolbar, and I try to click on the empty space between M08000007448 and 19 , it selects the TR, not a "hidden td".

I'm having this table rendering problem also in some other table in the application, anyone experiencing something like this? It happens only in IE9 :(

I don't know if it's important, but the page is made with ASPNET (webforms) and use Jquery and some other JS plugin.

I tried to save the page (with images) and open it in local with IE9, but the problem never occurs. (Of course I checked all the table structure and it's ok. Header and all rows have the eact same number of TD's, with the right number of colspan when necessary).

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
fgpx78
  • 1,270
  • 2
  • 10
  • 8
  • any code? maybe you have a mismatched tag somewhere? – Naftali Apr 27 '11 at 14:48
  • Are you able to validate the HTML using the IE9 F12 tools? Does IE9 tell you what mode it is rendering in? Quirks Mode, IE 7, IE 8, IE 9 Standards (default), etc... – Dan Sorensen Apr 27 '11 at 15:17
  • IE Blog mentions a new tool today to help troubleshoot IE 9 incompatibility: http://blogs.msdn.com/b/ie/archive/2011/04/27/ie9-compat-inspector.aspx – Dan Sorensen Apr 27 '11 at 16:37
  • The code is really long, I dont think the problem is there. No error found with the F12 tool, and the rendering mode is IE9. I try the Compat inspector and let you know ;) I checked also for tag mistmaches (first thing I did) but no luck – fgpx78 Apr 28 '11 at 14:46
  • BTW, i found the problem: it seems that some javascript code before the HEAD tag was causing the problem. IE9 does not seem to handle it well,...it's a problem since i slved an MVC problem doing that so..I'm back to the old one :) Thank you all. – fgpx78 May 29 '11 at 19:42
  • FYI: there is a fiddle that reproduces this issue on ie9: http://jsfiddle.net/kiranmn/kYRnV/4/embedded/result/ – mkoryak Nov 07 '12 at 21:00
  • duplicates [ie9-table-has-random-rows-which-are-offset-at-random-columns](http://stackoverflow.com/questions/7267014/ie9-table-has-random-rows-which-are-offset-at-random-columns) – Ravi Kadaboina Jan 30 '13 at 23:27
  • This issue is similar http://stackoverflow.com/questions/8474678/ie9-strange-table-issue – Sandeep Sep 19 '13 at 22:57

14 Answers14

72

enter image description hereI have exactly the same problem as well. you may want to read this https://connect.microsoft.com/IE/feedback/details/649949/innerhtml-formatting-issues-on-very-large-tables

YOu can remove the space inbetween td by using javascript if your html is returned from ajax, then from the response, you replace it with

response_html = response_html.replace(/td>\s+<td/g,'td><td');
$('#table').html(response_html);
Shanison
  • 2,295
  • 19
  • 26
  • This solution fixed my problem. It gave me quiet a puzzle before I found this solution. – Bearwulf Oct 28 '11 at 08:57
  • The link is no longer available. – Mason240 Mar 14 '13 at 20:57
  • It is still available. YOu must login to view the contents. I just took a screenshots. You can find the screenshot in my answer – Shanison Mar 15 '13 at 02:59
  • I also added   to the empty cells. – Bakudan Jul 25 '13 at 10:26
  • what if you are not returning from ajax but rather through a partial view – leora Jan 10 '14 at 20:03
  • @leora If it is not ajax, you can replace the whole table html again after the document is ready. – Shanison Jan 14 '14 at 06:47
  • @shanison . i got problem when appending table rows inside getjson. some time two rows combined . i tried to use your replace code but didn't fix the problem in firefox! Could you help me fix it ?var newRowContent = ''+count+')'+this.gsx$name.$t+''+this.gsx$category.$t+'\n'; $("#tblEntAttributes tbody").append(newRowContent); – user1788736 Oct 01 '15 at 23:42
33

I had the same exact issue populating a table using jquery templates. I kept having 'ghost' <td>'s on larger datasets (300+) only in IE9. These <td>'s would push the outer columns outside the boundries of my table.

I fixed this by doing something really silly; removing all the spaces betwen the <td> start and end tags and left justifying the HTML markup pertaining to my table. Basically, you want all of your <td> </td> on the same line, no spaces.

Example:

<table>
<tr class="grid_customer_normal">
<td>${primary}</td>
<td>${secondary}</td>
<td>${phone}</td>
<td>${address}</td>
</tr>
</table>
Jon
  • 2,932
  • 2
  • 23
  • 30
Jorge
  • 331
  • 3
  • 3
14

The solution given @Shanison helps only partially but the problem persists if there are spaces between any of the other elements that can be part of the table content model like thead, th etc.

Here is a better regex devised by my Lead at work.

if (jQuery.browser.msie && jQuery.browser.version === '9.0')
{
    data = data.replace(/>\s+(?=<\/?(t|c)[hardfob])/gm,'>');
}

covering all table, caption, colgroup, col, tbody, thead, tfoot, tr, td, th elements.

Note: jQuery.browser was removed in jQuery 1.9 and is available only through the jQuery.migrate plugin. Please try to use feature detection instead.

Ravi Kadaboina
  • 8,494
  • 3
  • 30
  • 42
11

I fixed this issue by removing the whitespace:

var expr = new RegExp('>[ \t\r\n\v\f]*<', 'g');
var response_html_fixed = data.replace(expr, '><'); //A disgusting hack for ie9. Removes space between open and close <td> tags
$('#treegrid-data').replaceWith(response_html_fixed);
Will Liska
  • 111
  • 1
  • 2
2

Found a very useful script to prevent unwanted cells in your html table while rendering.

function removeWhiteSpaces()
{
   $('#myTable').html(function(i, el) {
      return el.replace(/>\s*</g, '><');
   });
}

This javascript function you should call when the page loads (i.e. onload event)

Rish
  • 1,303
  • 9
  • 22
2

IE Blog mentions a new tool today called the Compat Inspector script to help troubleshoot IE 9 rendering incompatibility. It may help troubleshoot your issue.

http://blogs.msdn.com/b/ie/archive/2011/04/27/ie9-compat-inspector.aspx

Dan Sorensen
  • 11,403
  • 19
  • 67
  • 100
  • Couldn't find anything with the tool. Just a lot of validating problem all due to the aspnet engine rendering (missing end / for some meta and link tag in the header). – fgpx78 Apr 28 '11 at 15:25
2

I was having that problem too.

It occured to me, that width attribute in td/th tags causng this problem.

Changed it to style="width: XXpx" and problem is solved :)

TAURI
  • 21
  • 2
2

I ran into this problem as well and I realized that it happened when I was directly putting text in <td> elements. I'm not certain whether it's a standard or not but after wrapping any text in <span> elements, the rendering issues disappeared.

So instead of:

<td>gibberish</td>

try:

<td><span>gibberish</span></td>
Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
  • I like this solution. It is more straight-forward than stripping white-space from between all elements. Moreover, it worked for me :-) – R. Schreurs Jan 27 '15 at 19:05
1

Late answer, but hopefully I can help someone with this. I experienced the same problem when debugging in IE9. The solution was removing all whitespaces in the HTML code. Instead of

<tr> <td>...</td> <td>...</td> </tr>

I had to do

<tr><td>...</td><td>...</td></tr>

This seemed to solve the problem!

anneleenw
  • 26
  • 4
0

This is the very serious bug in IE9. In my case removing only white spaces between different td was not sufficient, So i have removed spaces between different tr also. And it is working fine.

Vikas Pawar
  • 135
  • 1
  • 2
  • 11
0

I had similar problem with ie-9 when rendering dynamic table.

var table = $('<table><tr><td style="width :100"></td></tr></table>');

when rendered translates to...

<table><tbody><tr><td style="width :100px"></td></tr></tbody></table>

this works perfectly fine in ie=10 chrome safari...

 //   but for ie-8 it renders to... with a style attr in my case

 <table><tbody><tr><td ></td></tr></tbody></table>

you need to write 100px instead of 100.

Arun Pratap Singh
  • 3,428
  • 30
  • 23
0

Having same formatting issue with ie9, and a new issue in ie11 where it formats correctly but takes 25-40 seconds to render a table of about 400 rows and 9 columns. It has the same cause, whitespace inside the tr or td tags.

I'm displaying a table that is created by the rendering of a partial view from an AJAX call. I decided to BFH it on the server by removing the whitespace from the rendered partial view, using a method posted here: http://optimizeasp.net/remove-whitespace-from-html

This is his solution copied in-toto:

    private static readonly Regex RegexBetweenTags = new Regex(@">(?! )\s+",     RegexOptions.Compiled);
    private static readonly Regex RegexLineBreaks = new Regex(@"([\n\s])+?(?<= {2,})<", RegexOptions.Compiled);
    private static string RemoveWhitespaceFromHtml(string html)
    {

        html = RegexBetweenTags.Replace(html, ">");
        html = RegexLineBreaks.Replace(html, "<");
        return html.Trim();

    }

And here is a method that returns a partial view as a string, stolen from another SO answer:

public string RenderPartialViewToString(string viewName, object model)
    {
        this.ViewData.Model = model;
        try
        {
            using (StringWriter sw = new StringWriter())
            {
                ViewEngineResult viewResult = ViewEngines.Engines.FindPartialView(this.ControllerContext, viewName);
                ViewContext viewContext = new ViewContext(this.ControllerContext, viewResult.View, this.ViewData, this.TempData, sw);
                viewResult.View.Render(viewContext, sw);
                return RemoveWhitespaceFromHtml(sw.ToString());
            }
        }
        catch (Exception ex)
        {
            //logger here
        }
    }

It takes a bit of time, but less than a second to render a table of about 400 rows, which for my purposes is good enough.

Tom Regan
  • 3,580
  • 4
  • 42
  • 71
0

I had this problem sometimes on tables generated by Knockout. In my case I fixed it using the jQuery solution found here

jQuery.fn.htmlClean = function() {
    this.contents().filter(function() {
        if (this.nodeType != 3) {
            $(this).htmlClean();
            return false;
        }
        else {
            this.textContent = $.trim(this.textContent);
            return !/\S/.test(this.nodeValue);
        }
    }).remove();
    return this;
}
Community
  • 1
  • 1
Homer
  • 7,594
  • 14
  • 69
  • 109
-1

I had the same issue with KendoUI grid in IE10. I was able to force IE to rerender missing table cells with this hack:

htmlTableElement.appendChild(document.createTextNode(''));

Appending an empty textNode makes IE to rerender the whole table.

dfsq
  • 191,768
  • 25
  • 236
  • 258