Skip to content

Commit

Permalink
Scroller widget: update to work with filter widget. Fixes #584 & 370
Browse files Browse the repository at this point in the history
  • Loading branch information
Mottie committed Apr 18, 2014
1 parent 7a52f96 commit 8f5a7a9
Showing 1 changed file with 16 additions and 41 deletions.
57 changes: 16 additions & 41 deletions js/widgets/widget-scroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
Resizable scroller widget for the jQuery tablesorter plugin
Version 2.0 - modified by Rob Garrison (4/12/2013)
Requires jQuery, v1.2.3 or higher
Requires the tablesorter plugin, v2.0 or higher, available at http://mottie.github.com/tablesorter/docs/
Version 2.0 - modified by Rob Garrison (4/12/2013; updated 4/18/2014 for tablesorter v2.16.0)
Requires jQuery v1.7+
Requires the tablesorter plugin, v2.8+, available at http://mottie.github.com/tablesorter/docs/
Usage:
Expand Down Expand Up @@ -109,11 +109,7 @@ ts.addWidget({

$cells = $hdr
.wrap('<div class="tablesorter-scroller-header" style="width:' + $tbl.width() + ';" />')
.find('.' + ts.css.header)
.bind('mousedown', function(){
this.onselectstart = function(){ return false; };
return false;
});
.find('.' + ts.css.header);

$tbl
.wrap('<div class="tablesorter-scroller-table" style="height:' + h + 'px;width:' + $tbl.width() + ';overflow-y:scroll;" />')
Expand All @@ -134,39 +130,12 @@ ts.addWidget({
});

// make scroller header sortable
c.$headers.find(c.selectorSort).add( c.$headers.filter(c.selectorSort) ).each(function(i){
var t = $(this);
$cells.eq(i)
// clicking on new header will trigger a sort
.bind('mouseup', function(e){
t.trigger(e, true); // external mouseup flag (click timer is ignored)
})
// prevent header text selection
.bind('mousedown', function(){
this.onselectstart = function(){ return false; };
return false;
});
});
ts.bindEvents(table, $cells);

// look for filter widget
$tbl.bind('filterEnd', function(){
if (flag) { return; }
$cells.each(function(i){
$(this).find(filterInputs).val( c.$filters.find(filterInputs).eq(i).val() );
});
});
$hdr.find(filterInputs).bind('keyup search', function(e){
// ignore arrow and meta keys; allow backspace
if ((e.which < 32 && e.which !== 8) || (e.which >= 37 && e.which <=40)) { return; }
flag = true;
var $f = $(this), col = $f.attr('data-column');
c.$filters.find(filterInputs).eq(col)
.val( $f.val() )
.trigger('search');
setTimeout(function(){
flag = false;
}, wo.filter_searchDelay);
});
if ($tbl.hasClass('hasFilters')) {
ts.filter.bindSearch( $tbl, $cells.find('.' + ts.css.filter) );
}

resize = function(){
var d,
Expand Down Expand Up @@ -234,8 +203,14 @@ ts.addWidget({

},
remove : function(table, c, wo){

var $table = c.$table;
$table.closest('.tablesorter-scroller').find('.tablesorter-scroller-header').remove();
$table
.unwrap()
.find('.tablesorter-filter-row').removeClass('hideme').end()
.find('thead').show().css('visibility', 'visible');
c.isScrolling = false;
}
});
});

})(jQuery);

0 comments on commit 8f5a7a9

Please sign in to comment.