Copying jQuery events from one element to another

I dug around for way too long today trying to figure out how to copy jQuery event handlers from one element to another.

I finally found the solution..

    function copyEvents(source, target) {
        var evs = $._data(source[0], 'events');  
        for (var ev in evs) {
            for (var i = 0; i < evs[ev].length; i++)
                $.fn[ev].apply(target, [evs[ev][i].handler]);

I’ve left a demo here ->

MVC Tables


Update 12-Sep-2013:

As part of an MVC portal/admin app we’ve been working on recently, we required HTML Table rendering functionality that supported AJAXy paging/sorting/filtering etc.

We initially tried using the awesome¬†MVC classes for jquery DataTables, but this didn’t quite fit our needs. We didn’t need a lot of in-line editing, but what we did need was the ability to render cells from display/editor templates and partial views etc.

What we came up with was a fluently configurable table framework that used all that MVC goodness to easily generate highly customisable tables. These tables are sortable, pagable and filterable all on the server side via AJAX.
Continue reading