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
});

wholly's People

Contributors

gajus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wholly's Issues

Problem with wholly table which contains a datepicker table

I have a table which is highlighted by wholly, and that's great. However, inside some of the table cells, I am using the bootstrap datepicker, which generates its own table. If I click the datepicker, and then mouse-over the datepicker's tooltip, then every one of these cells generates this unhelpful console.log:

  • Uncaught TypeError: Cannot read property '1' of undefined at HTMLTableCellElement.

I don't actually need wholly to work within the embedded datepicker (indeed, it's best that it doesn't), but it would be nice to get rid of the error messages. Maybe we need a way to tell wholly that a table within a table should not be treated as inheriting the highlightable class?

Documentation: how to turn it off again

If you are scrolling a wholly-highlighted table, and there is a position:sticky first-row or first column, then
a side-effect of wholly is that the table cells that are supposed to slide "under" the hidden row/col always show-through.
So we need a way to undo wholly after it has been applied. How?

Include unit tests

Include unit tests to cover the most fundamental logic components, such as matrix building.

Add row selector

When a table is nested in a cell, selecting cells gives unexpected results. For example:

<table id="main">
    <tr>
        <td>Main Cell</td>
    </tr>
    <tr>
        <td>
            <table id="child">
                <tr>
                    <td>Child cell</td>
                </tr>
            </table>
        </td>
    </tr>
</table>

To be able to distinguish between the rows of the main table and the rows of the nested table, an option can be added to select rows (with tr as default):

Wholly.DEFAULTS = {
    rowSelector: 'tr',
    ...
}

The rows selection is set as:

wholly.indexTable = function (table) {
    var tableIndex = wholly.generateTableMatrix(table),
        rows = table.find(this.options.rowSelector);
    ...
}

And for the example above:

<table id="main">
    <tr>
        <td>Main Cell</td>
    </tr>
    <tr>
        <td>
            <table id="child">
                <tr class="skip">
                    <td>Child cell</td>
                </tr>
            </table>
        </td>
    </tr>
</table>
$('#main')wholly({
    rowSelector: 'tr:not(.skip)',
    ...
});

td with display:none should be treated as rowspan=0,colspan=0

Consider a table where some of the are switched on and off by having "style='display:none'".
For a of this type, it is removed entirely from the table, and the HTML treats it as never existing (effectively a zero rowspan/colspan).

However, wholly still counts these cells as if they were there with a normal colspan/rowspan of 1.

As a result, the vertical/horizontal highlighting goes completely crooked.

Add selection option

This will be good if the cells selection is set as an option. For example:

 defaultOptions = {
     highlightHorizontal: null,
     highlightVertical: null,
     selection: 'td, th'
 };

And in code:

table.on('mouseenter', options.selection, function () {
...
}

table.on('mouseleave', options.selection, mouseleave);

So user can decide wich cells are processed.

$('table').wholly({
    highlightHorizontal: 'horizontal-class-name',
    highlightVertical: 'vertical-class-name',
    selection: 'td:not(".skip")'
})

Tables within Tables

If the table.highlightable contains another table, some really weird things occur.

  • The highlighting mechanism binds the x,y of the outer-table to the x,y of the inner table, so both sets of highlights trigger each other.
  • If we're unlucky, the columns in the outer table can get a "kink" in which cells are highlighted.

There may be a better way, but here is my fix.

  1. Change wholly.js:

var tableIndex = wholly.generateTableMatrix(table),
//If the table contains another table, some 'bad' things happen with the counters.
//Add .fixhighlightable to the tr of the inner table.
//rows = table.find('tr');
rows = table.find('tr:not(.fixhighlightable)');

  1. In the html, edit the inner table, and add .fixhighlightable on every <tr>.

This fix would be neater if wholly could either scan for and ignore the inner table, or if the fixhighlightable class were applied to the inner table.

Supporting selected column/row events

Thanks for developing a slick plugin, I like it!

Any chance in providing some additional wholly events for selected (via mousedown/mouseup) column/row so that a class could be toggled? Maybe there is a way to do this already?

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.