ducksboard / gridster.js

gridster.js is a jQuery plugin that makes building intuitive draggable layouts from elements spanning multiple columns
http://gridster.net/
MIT License
6.04k stars 1.2k forks source link

[IE11] Gridster.sort_by_row_and_col_asc #461

Open e-karim opened 9 years ago

e-karim commented 9 years ago

I have a strange behavior when my widgets have the same col/row:

<ul>
       <li data-row="1" data-col="1" data-sizex="1" data-sizey="1">A</li>
       <li data-row="1" data-col="1" data-sizex="1" data-sizey="1">B</li>
       <li data-row="1" data-col="1" data-sizex="1" data-sizey="1">C</li>
</ul>

With IE11, the order is reversed (C, B, A) and on Firefox or Chrome it does not alter the original order (A, B, C) in Gridster.sort_by_row_and_col_asc. In fn.get_widgets_from_DOM, the fn.register_widget do the necessary work to arrange the widgets.

I've solved my issue by changing the implementation like this:

Gridster.sort_by_row_and_col_asc = function (widgets) {
        widgets = widgets.sort(function (a, b) {
            if (a.row === b.row && a.col === b.col) {
                return 0;
            }
            if (a.row > b.row || a.row === b.row && a.col > b.col) {
                return 1;
            }
            return -1;
        });

        return widgets;
    };
romgen commented 9 years ago

Actually, Chrome got a similiar problem when having too many items. I have an 8 (columns) x 3 (rows) grid. When having more than 10 list items when calling gridster(), the order seems to be completely random.

Firefox and IE (with the patch from above) work fine.

satreix commented 8 years ago

This code also fixes the issue for Safari, but Chrome still sort the items like a drunk sailor.