bootstrap-sortable icon indicating copy to clipboard operation
bootstrap-sortable copied to clipboard

Navigating to #hash link on table row leads to wrong row

Open hv15 opened this issue 5 years ago • 0 comments

Hi, first off thanks @drvic10k so much for this plugin!!! The sorting works perfectly for my datasets!

Just an FYI for other with the same problem, if you are using id attribute on table rows, it can happen that upon navigating to via link, that the pages scrolls to some random point (not the row you wanted).

The reason is that the browser tries to resolve the link before the DOM is updated by the plugin sorting the table. So actually the link does resolve to the correct table row, but the plugin moves as part of its sorting.

The fix I came up with listens on the sorted event, and iff there is a hash link (e.g. #some-id), moves to the element with that id.

$(window).on('sorted', function(){
            if( location.hash && location.hash.length ) {
                var hash = decodeURIComponent(location.hash.substr(1));
                $("#"+hash).get(0).scrollIntoView();
            }
        });

Works well for me. Hope it useful for others :)

hv15 avatar Jun 05 '20 16:06 hv15