JSFiddle - React, Tailwind, and code Playground

by kpwn243

HTML

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<p>
    Below you can use the option builder user interface that is what the data is used for on the page but also good for building the option string text that must be built.  Ignore the extra code as this is almost copy and paste from the current running site.
</p>

<div>Option String: <span id="optionPN"></span>

</div>
<br>
<table class="table table-bordered table-row-clickable" id="options">
    <thead>
        <tr>
            <th colspan="2">Valve Options</th>
        </tr>
    </thead>
    <tbody>
        <tr class="defaultOption active">
            <td style="width: 55px;">blank</td>
            <td>No options selected (click to clear options)</td>
        </tr>
        <tr class="popOption allowAll naWithOpON naWithOpOP" data-placement="left" data-popover-img="/res/files/images/options/SO.jpg" data-original-title="" title="">
            <td>O</td>
            <td>Twist locking solenoid override</td>
        </tr>
        <tr class="popOption allowAll naWithOpO naWithOpOP" data-placement="left" data-popover-img="/res/files/images/options/SON.jpg" data-original-title="" title="">
            <td>ON</td>
            <td>Twist non-locking solenoid override</td>
        </tr>
        <tr class="popOption allowAll naWithOpO naWithOpON" data-placement="left" data-popover-img="/res/files/images/options/SOP.jpg" data-original-title="" title="">
            <td>OP</td>
            <td>Push non-locking solenoid override</td>
        </tr>
        <tr class="popOption allowAll naWithOpL" data-placement="left" data-popover-img="/res/files/images/options/ST.jpg" data-original-title="" title="">
            <td>T</td>
            <td>Tapped exhaust</td>
        </tr>
        <tr class="popOption allowAll naWithOpT naWithCoilX" data-placement="left" data-popover-img="/res/files/images/options/SL.jpg" data-original-title="" title="">
            <td>L</td>
           ...

CSS

.table-row-clickable > tbody > tr {
    cursor: pointer;
}

JavaScript

$(".table-row-clickable").find('tbody tr').click(function () {
    var table = $(this).closest('table').attr('id');
    var row = $(this).closest('tr');
    if (!row.hasClass('titleIgnore') && !row.hasClass('danger')) {
        var lastActive = $("#" + table + " > tbody > tr.active");
        var partNumber = $(this).find('td:first').text().toUpperCase();
        if (partNumber == "BLANK" || partNumber == "NONE" || partNumber == "STD") {
            partNumber = "";
        }

        if (table == "options") {
            if (!row.hasClass('active')) {
                row.addClass('active');
            } else {
                row.removeClass('active');
            }
            /*multi-toggle*/
            if (partNumber == "") {
                resetOnDefault("#" + table);
            }
            /*reset table on default selection */
            $("#optionPN").text(GetTablePartNumber("#" + table));
            /*set part number portion */

        }
        refreshTables();
    }
});

function GetTablePartNumber(table) {
    var fullPN = "";
    $(table).find("tbody tr").each(function () {
        if ($(this).hasClass('active') && !$(this).hasClass('defaultOption')) {
            fullPN += $(this).find('td:first').text().toUpperCase();
        }
    });

    $(table).find("tbody tr").each(function () {
        if ($(this).hasClass('defaultOption')) {
            if (fullPN == "") {
                $(this).addClass('active');
            } else {
                $(this).removeClass('active');
            }
        }
    });
    return fullPN;
}

function resetOnDefault(table) {
    $(table).find("tbody tr").each(function () {
        if ($(this).hasClass('active') && $(this).hasClass('defaultOption')) {
            $(table).find("tbody tr").each(function () {
                if (!$(this).hasClass('defaultOption')) {
                    $(this).removeClass('active');
                }
            });
        }
    });
}

function refreshTables() {
    /*...