Click here to Skip to main content
15,887,175 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I have a pretty unique (i hope) situation:
I have a UserControl that I can use to create a table with sortable columns and add context menus to each row.

The column sort works by taking each row from the tbody, sorting them in an array, removing the original rows and appending the newly sorted rows.

The context menu works on $(document).ready by reading the items from a JSON string in a hidden column for each row, and translating the details from those objects into context menu items (third party context menu code from www.javascripttoolbox.com[^]).

The problem is that the context menu item functions apply to the rows that are removed when the table is sorted.

So, to the question: How can I either A) better apply the context menu function or B) sort the table tbody section without losing the functions applied.

I don't have to worry about whether there are other row or cell functions at this stage as I will be the only one using the user control for a while.

many thanks in advance
Posted

1 solution

Ok, I didn't get any real interest in this issue so I'll post my work-around:


instead of applying the context menu to each rows onclick event I instead apply a must more efficient function that creates the context menu when you click on the row:

JavaScript
    function ApplyContextMenu() {
        if(jsonCellIndex>=0) {
            $("table[id$='CarmaTable_Body']").find("tbody").find("tr").each(function() {
                $(this).mousedown(function() {
                    ApplyContextMenuRow(this);
//                    $(this).trigger({
//                        type: 'mousedown';,
//                        which: 3
//                    });
                });
            });
        }
    }


I commented out the bit I didn't need as I thought I might have to trigger the event again to get the context menu to show. This would have been awkwardly and unintentionally recursive. Fortunately, the events stacked in my favour and the context menu triggers after this. I'm not sure how this worked but I'm glad it did :D

If you have a better idea then please post and I'll get around to reviewing / accepting it later

Thanks ;)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900