views:

2272

answers:

4

I'm having problems getting UI code to perform at all well in IE.

I have a table - a matrix of values. Each cell can be empty or hold a list of items.

I want users to be able to drag items between cells.

So my HTML looks something like this:

<table>
    <tr><td></td><th scope="col">col 1</th><th scope="col">col 2</th></tr>
    <tr><th scope="row">row 1</th>
        <td class="droppable-cell">
            <div class="draggable-item">item A</div>
            <div class="draggable-item">item B</div>
        </td>
        <td class="droppable-cell"></td>
    </tr>
    <tr><th scope="row">row 2</th>
        <td class="droppable-cell"></td>
        <td class="droppable-cell">
            <div class="draggable-item">item C</div>
            <div class="draggable-item">item D</div>
        </td>
    </tr>
</table>

Then I'm using jQuery 1.3.1 and jQuery UI 1.6rc6:

$j('.draggable-item').each(function()
{
    $j(this).draggable({
       addClasses: false,
       revert: true, 
       zIndex: 2000,
       cursor: 'move'
    });
});

$j('.droppable-cell').each(function()
{
    $j(this).droppable({
        addClasses: false,
        activeClass: 'droppable-cell-candrop',
        hoverClass: 'droppable-cell-hover',
        tolerance: 'pointer',

        drop: function(event, ui)
        {
            //function to save change
        });
    });
});

Note that this is simplified, truncated and unfinished code.

My problem is that in FX, Safari, Chrome, etc (i.e. all the decent browsers) this works fine.

IE really struggles though. With a 5x5 table IE's delay on the start of a drag is noticeable. On a 10x10 table with maybe 100 items the start of the drag hangs the browser.

I want to be able to support up to round 20x15 cells and maybe up to 500 items - is this just impossible? It doesn't seem like it should be.

Am I doing something wrong? Is there a way to do this that doesn't slow the page in IE like this?

+2  A: 

This exact issue is why iGoogle and other simliar apps use a transparent box with a dotted line around the edge. IE is unable to drag full objects, because of the issue you have outlined above.

Nick Berardi
Do you mean http://www.google.com/ig ? Even in IE that page drags the actual content. I'm only trying to drag small divs.
Keith
+1  A: 

It could be the table rendering... Can you try without the table?

If your cells are the same size you can achieve the table-like display floating them:

<style>
.droppable-cell{
  float:left; width: 50%; height: 20px; border: 1px solid black;
}
</style>

<div class="droppable-cell">
        <div class="draggable-item">item A</div>
        <div class="draggable-item">item B</div>
</div>
<div class="droppable-cell"></div>
<div class="droppable-cell"></div>
<div class="droppable-cell">
        <div class="draggable-item">item C</div>
        <div class="draggable-item">item D</div>
</div>

If using a table is a must setting the table-layout style to 'fixed' and specifying the cells size may help.

Serhii
Thanks, nice idea - but this is really tabular data. The row and column headers are hierarchical with spans. I also don't think I could fix the cell size.
Keith
+2  A: 

Narrowing the portion of the DOM that jQuery has to search may help. Add an id to the containing DOM element

<table id="myTable">

Then alter your jQuery selector to find elements within this container

$j('#myTable .draggable-item').each(function() { ...
Jaysen Marais
Thanks - I'll try that.
Keith
I thought this was $('#myTable,.draggable-item') according to the documentation.
Jay
@Jay. Nope, I was refering to 'Ancestor Descendent' selectors (http://docs.jquery.com/Selectors/descendant#ancestordescendant). A comma would be an 'n' selector (http://docs.jquery.com/Selectors/multiple#selector1selector2selectorN) which is useful in some cases but not this one
Jaysen Marais
That helps a little, though it's still crushingly slow in IE
Keith
disapointing improovement. the main problem seems to be ie's very very very slow rendering. I watched it flog one of the cpu's at 100% to render a table with 56 columns, and 34 rows for 7 and a half minutes. dragging and dropping took a good 30 seconds to start and stop. there are only 80 odd divisons to drag around amongst all those cells.
Bingy
A: 

Even i have the same issue and i had a work around of attaching the droppable events on mouseover of each items instead of binding it to all events at beginning.

But still i see a delay in creating the custom helper in the beginning. Can anybody help me in this?