gajus/wholly

Add row selector

Open

#10 opened on Jan 21, 2020

View on GitHub
 (1 comment) (0 reactions) (0 assignees)JavaScript (29 forks)github user discovery
bughelp wanted

Repository metrics

Stars
 (201 stars)
PR merge metrics
 (PR metrics pending)

Description

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)',
    ...
});

Contributor guide