# tablesorter

## Lazyload widget

### Flexible client-side table sorting

Back to documentation

### Notes

Warning Binding the `lazyload_event` to `'scroll'` may cause excessive lag.

- This widget, added in v2.24.0, integrates the popular jQuery lazyload plugin & jQuery scrollstop.
- This widget will only work if:
  - The image class, set by the `lazyload_imageClass` option is included.
  - The image `width` & `height` attributes are set.
  - The url to the image is added to the data-attribute, set by the `lazyload_data_attribute` option, and not the image `src` attribute.

      <img class="lazy" data-original="images/logo.png" width="300" height="300">

- The images will load only if:
  - The image is inside the viewport.
  - When the user has stoped scrolling; this is because the `lazyload_event` option is set by default to use the "scrollstop" event, which is added by the jQuery scrollstop plugin (see `lazyload_event` option for more details).
- In this demo, scroll down the page to see the lazyload plugin in action.
- This widget will not work with the original tablesorter plugin (v2.0.5).

### Options

#### Lazyload widget default options (added inside of tablesorter `widgetOptions`)

TIP! Click on the link in the option column to reveal full details (or toggle|show|hide all) or double click to update the browser location.

Option | Default | Description
--- | --- | ---
Lazyload widget options
lazyload_imageClass | `'lazy'` | This option contains the image class name targeted by the lazyload widget. This option is set up to add a period to the beginning of this option, to make a jQuery class name selector.
lazyload_update | `'lazyloadUpdate'` | This option sets the event name that can be triggered to update the lazy load on newly loaded images. This widget will work with the pager and columnSelector widget, so you shouldn't need to trigger this event, but you may need to use it if new rows are added or a cell with an image is updated.
jQuery scrollstop plugin option
lazyload_latency | `250` | Latency is the minimum time (in milliseconds) between the last scroll event and when the scrollstop event fires. For more details, see the main plugin page.
jQuery lazyload plugin options
lazyload_threshold | `0` | By default images are loaded when they appear on the screen. If you want images to load earlier use threshold parameter. Setting threshold to `200` causes image to load 200 pixels before it appears on viewport. For more details, see the main documentation.
lazyload_failure_limit | `0` | Setting failure_limit to 10 causes plugin to stop searching for images to load after finding 10 images below the fold. If you have a funky layout set this number to something high. Worst case being the actual number of images. For more details, see the main documentation.
lazyload_event | `'scrollstop'` | Event to trigger image loading. In the original plugin, the default for this option is `'scroll'`. It was changed to `'scrollstop'` in this widget to only load images after scrolling stops. Alternative settings include `'click'` (user clicks on image to load it) or `'mouseover'`. If this option is not set to `'scrollstop'`, then the scrollstop plugin will not be initialized. Warning If the option is set to `'scroll'`, the plugin may cause excessive lag. For more details, see the main documentation.
lazyload_effect | `'show'` | By default plugin waits for image to fully load and calls `show()`. You can use any effect you want, e.g. `'fadeIn'` effect. For more details, see the main documentation.
lazyload_container | `window` | You can also use plugin for images inside scrolling container, such as div with scrollbar. Just pass the container as jQuery object. For more details, see the main documentation.
lazyload_data_attribute | `'original'` | You must alter your image tags. Address of the image must be put into `data-original` attribute. Use this option to set a different attribute. If you have a higher quality image that you want to load under certain conditions, use the `lazyload_appear` callback to change this setting. Here is an example that switches to load retina images:
    $(function() {
    	$( 'table' ).tablesorter({
    		theme : 'blue',
    		widgets : [ 'lazyload' ],
    		widgetOptions : {
    			lazyload_appear : function( elements_left, settings ) {
    				// elements_left = number of images left to load
    				// settings = lazyload plugin settings; not the widgetOptions setting which don't matter at this point
    				settings.data_attribute = window.devicePixelRatio > 1 && $( this ).attr( 'retina' ) ?
    					// use "data-retina" for higher resolution images
    					'retina' :
    					// fallback to "data-original" for non-retina displays
    					'original';
    			}
    		}
    	});
    });
For more details, see the main documentation.
lazyload_skip_invisible | `true` | There are cases when you have images which are in viewport but not `:visible` (v2.25.6). In v2.25.6, change this default value to `true` to better work with the filter widget. To improve performance you can ignore `.not(":visible")` images by setting this option to `true`. For more details, see the main documentation.
lazyload_appear | `null` | This function is called when image appears in the viewport, but before it is loaded. Use this callback function as follows:
    $(function() {
    	$( 'table' ).tablesorter({
    		theme : 'blue',
    		widgets : [ 'lazyload' ],
    		widgetOptions : {
    			lazyload_appear : function( elements_left, settings ) {
    				// elements_left = number of images left to load
    				// settings = plugin settings; not the widgetOptions
    				$( this ).parent().addClass( 'loading' );
    			}
    		}
    	});
    });
There doesn't appear to be any documentation for this callback in the main documentation.
lazyload_load | `null` | This function is called after the image has completed loading. Use this callback function as follows:
    $(function() {
    	$( 'table' ).tablesorter({
    		theme : 'blue',
    		widgets : [ 'lazyload' ],
    		widgetOptions : {
    			lazyload_load : function( elements_left, settings ) {
    				// elements_left = number of images left to load
    				// settings = plugin settings; not the widgetOptions
    				$( this ).parent().removeClass( 'loading' );
    			}
    		}
    	});
    });
There doesn't appear to be any documentation for this callback in the main documentation.
lazyload_placeholder | See description | This placeholder replaces the image until it gets loaded. By default, this setting is an encoded gif of a 1x1 transparent pixel. Default: `'data:image/gif;base64,R0lGODlhAQABAIABAP///wAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=='` For more details, see the main documentation.

### Method

### Force lazyload widget update

If you need to programmically force the lazyload widget to update, trigger a `'lazyloadUpdate'` event on the table:

    $( 'table' ).trigger( 'lazyloadUpdate' );

You can change this event name by setting the `lazyload_update` option.

# Demo

First Name | Last Name | Image
--- | --- | ---
Bill | Murray |
Joyce | Young |
John | Hood |
Clark | Kent |
Beverly | Pyle |
Bruce | Almighty |
Billy | Murray |
Frank | Bedlam |
Harry | Sally |

# Javascript

# HTML