Git Product home page Git Product logo

wholly's Introduction

Wholly

Build Status Bower version Tweet Button

jQuery plugin used to select the entire table row and column in response to mouseenter and mouseleave events. Wholly supports table layouts that utilize colspan and rowspan.

Interactive demo.

How does it work?

If you want to support colspan and rowspan, then first you need to build table index, ie. matrix that identifies cell position in every row regardless of the markup. Then you need to track events of all the table cells and calculate their offset in the matrix and the columns that share the horizontal and vertical index.

The resulting lookup is illustrated in the following animation:

Wholly highlighting a matrix

Why not CSS?

There are at least a few ways to achieve column highlighting using just CSS or with little JavaScript, e.g.

Neither of the above solutions support rowspan or colspan. In essence, neither of the above will work if you have header groups, merged columns or a summarizing table footer. Wholly supports colspan and rowspan anywhere in the <table>.

Use case

Most often you'd use Wholly to highlight the entire column of the selected cell.

Table using Wholly

Wholly is not limited to setting a particular style. The custom event hooks allow you to select the entire row and column and can be used to copy the data, for selecting multiple columns, etc.

Usage

There are two options that automate highlighting:

$('table').wholly({
    highlightHorizontal: 'horizontal-class-name',
    highlightVertical: 'vertical-class-name'
});

The following events are available:

Event Name Description
wholly.mouseenter-horizontal Fired on the individual table cells.
wholly.mouseleave-horizontal Fired on the individual table cells.
wholly.mouseenter-vertical Fired on the individual table cells.
wholly.mouseleave-vertical Fired on the individual table cells.
wholly.mouseenter Fired on the whole table.
wholly.mouseleave Fired on the whole table.

To get the affected cells, use the the above events as such:

$('table').on('wholly.mouseenter-horizontal wholly.mouseleave-horizontal mouseenter-vertical mouseleave-vertical', function (e) {
    // e.target
});

$('table').on('wholly.mouseenter wholly.mouseleave', function (e, affectedAxes) {
    // affectedAxes.horizontal
    // affectedAxes.vertical
});

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.