JSFiddle - React, Tailwind, and code Playground
by kman007_us
HTML
<table>
<tr>
<td class='allCat'>all</td>
<td class='editableCE2'><input></td>
</tr>
<tr class='single'>
<td class='abcedf'>blah</td>
<td class='editableCE2'><input class="newCE2" value="foobar"></td>
</tr>
<tr class='single2'>
<td class='abcedf'>blah 2</td>
<td class='editableCE2'><input class="newCE2" value="bippy"></td>
</tr>
<tr class='metacat'>
<td class='here'>suite</td>
<td class='editableCE2'><input class="newCE2" value="should not change"></td>
</tr>
<tr class='metacat'>
<td class='here'>balcony</td>
<td class='editableCE2'><input class="newCE2" value="should not change"></td>
</tr>
<tr class='allCat'>
<td class='here'>all</td>
<td class='editableCE2'><input class="newCE2" value="should not change"></td>
</tr>
</table>
CoffeeScript
# Given an 'All' Row, i.e. representing all prices of a single sailing,
# replace the price of each of its children, excluding 'meta' cells.
# Per the Business Analyst, M. Benaim, there's a single price of a child
# ticket per sailing.
replaceNonMetaChildrenPrice = (cell, tdName, newChildPrice) ->
if(typeof newChildPrice is 'number')
row = $(cell).closest('tr')
$.each row.nextUntil('.allCat'), () ->
r = $(this)
if (isMetaRow r)
# nothing to do - only change child's price
else
replaceSingleRowPrice r, tdName, newChildPrice
else
console.log 'Expecing "number" for "newChildPrice", but got:', newChildPrice, 'of type:', typeof newChildPrice
# Replace a non-meta row's child price
replaceSingleRowPrice = (nonMetaRow, tdName, newChildPrice) ->
priceCell = nonMetaRow.find('.' + tdName).find('input')
priceCell.val(Number(newChildPrice))
# Given a 'tr', return a Boolean indicating
# whether it's a Meta Row or not, i.e. excluding
# the 'All' row.
isMetaRow = (row) ->
row.hasClass('metacat')
replaceNonMetaChildrenPrice $('.editableCE2'), 'editableCE2', 555