PDA

View Full Version : Another innerHTML in IE problem - works for DIV but not TABLE



extbio
9 Jul 2009, 12:43 PM
I've searched and couldn't find solution (although similar cases abound), so here's the problem: my code was working in FF but not IE, and although I found a version that worked in both, I'd like to know why the other 2 versions do not work. Thanks in advance!



<html>
<head>
<title>Test</title>
<!-- Include Ext and app-specific scripts: -->
<script type="text/javascript" src="/ext-2.2.1/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="/ext-2.2.1/ext-all-debug.js"></script>

<!-- Include Ext and app-specific stylesheets here: -->
<link rel="stylesheet" type="text/css" href="/ext-2.2.1/resources/css/ext-all.css">
<script>
Ext.BLANK_IMAGE_URL = '/ext-2.2.1/resources/images/default/s.gif';
// version 1, everything works in FF and IE
Ext.onReady(function()
{
var div = Ext.get('mydiv');
var tmpstr = '<table id="mytable">';
for(var i = 0; i < 10; i++)
{
tmpstr += '<tr>';
for(var j = 0; j < 50; j++)
tmpstr += '<td>a</td>';
tmpstr += '</tr>\n';
}
tmpstr += '</table>';
div.dom.innerHTML = tmpstr;
});

// version 2, innerHTML fails in IE
Ext.onReady(function()
{
var table = Ext.get('mytable');
var tmpstr = '';
for(var i = 0; i < 10; i++)
{
tmpstr += '<tr>';
for(var j = 0; j < 50; j++)
tmpstr += '<td>a</td>';
tmpstr += '</tr>\n';
}
table.dom.innerHTML = tmpstr;
});

// version 3, 'el.innerHTML = createHtml(o);' in DomHelper.overwrite() fails in IE
Ext.onReady(function()
{
var tmpstr = '';
for(var i = 0; i < 10; i++)
{
tmpstr += '<tr>';
for(var j = 0; j < 50; j++)
tmpstr += '<td>a</td>';
tmpstr += '</tr>\n';
}
var dh = Ext.DomHelper;
var table = dh.overwrite('mytable', tmpstr);
});
</script>
</head>
<body>
<div id="mydiv"><table id="mytable"></table></div>
</body>
</html>

tryanDLS
9 Jul 2009, 2:47 PM
Might be related to IEs goofy table handling - probably need to add tbody tags. Also take a look at the source of DomHelper which has specific code to handle IE tables.

extbio
9 Jul 2009, 4:00 PM
tbody doesn't help. I did try adding tr, td tags before I posted the question and it didn't work either. Even with all 3 tags and content within td did not help as I just tested.