Chaining together two slickgrids for sorting

16 views
Skip to first unread message

Lorant Dobrondi

unread,
Jul 29, 2015, 6:19:29 AM7/29/15
to SlickGrid
I have two slickgrids on my page, side by side.

            slickgrid1                    slickgrid2
    |ID    Col1     Col2   |     |ID    Col3    Col4    | 
    |1                          |     |1                           |
    |2                          |     |2                           |
    |3                          |     |3                           |
    |4                          |     |4                           |
    |5                          |     |5                           |

I use two instead of one, to let the user separate them, position them freely.

The sorting is only enabled on slickgrid1's columns, and slickgrid2's ID column.

I would like to sort both of the slickgrids at the same time, when I click a header in slickgrid1. (basically let the two slickgrids act like they are one)

Is there a way to chain the sort event so the second grids rows are paired by the ID column to the first slickgrids ID column?


Here is the onsort event that I use for slickgrid1: 

    slickgrid1.onSort.subscribe(function (e, args) {
        var cols = args.sortCols;
        resourcedata.sort(function (dataRow1, dataRow2) {
            for (var i = 0, l = cols.length; i < l; i++) {
                var field = cols[i].sortCol.field;
                var sign = cols[i].sortAsc ? 1 : -1;
                var value1 = dataRow1[field], value2 = dataRow2[field];
                var result = (value1 == value2 ? 0 : (value1 > value2 ? 1 : -1)) * sign;
                if (result != 0) {
                    return result;
                }
            }
            return 0;
        });
        slickgrid1.invalidate();
        slickgrid1.render();
    });

Steve Zlamany

unread,
Jul 29, 2015, 6:54:21 AM7/29/15
to slic...@googlegroups.com
After your sort finishes on the first gird you could take the "order sequence" of those rows and copy that number to a column in the other grid   That column in the other grid would be used only for this special you have.

Once you get that 1...n value into that column in the other grid you simply sort on that column - the order will match the first grid.

--
You received this message because you are subscribed to the Google Groups "SlickGrid" group.
To unsubscribe from this group and stop receiving emails from it, send an email to slickgrid+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages