2

I am rendering rows to make my web page look like a spreadsheet. The way I add rows is like this and it works fine:

var StockRow = React.createClass({
    unwatch: function() {
        this.props.unwatchStockHandler(this.props.stock.symbol);
    },
    render: function () {
        var lastClass = '',
            changeClass = 'change-positive',
            iconClass = 'glyphicon glyphicon-triangle-top';
        if (this.props.stock === this.props.last) {
            lastClass = this.props.stock.change < 0 ? 'last-negative' : 'last-positive';
        }
        if (this.props.stock.change < 0) {
            changeClass = 'change-negative';
            iconClass = 'glyphicon glyphicon-triangle-bottom';
        }
        return (
            <tr>
                <td><button type="button" className="btn btn-default btn-sm" onClick={this.unwatch}>
                <span className="glyphicon glyphicon glyphicon-plus" aria-hidden="true"></span>
                </button></td>
                <td>{}</td>
                <td>{}</td>
                <td>{}</td>
                <td>{}</td>
                <td>{}</td>
                <td>{}</td>
                <td>{}</td>
                <td>{}</td>
                <td>{}</td>
                <td>{this.props.stock.symbol}</td>                
                <td className={lastClass}>{this.props.stock.last}</td>
                <td className={changeClass}>{this.props.stock.change} <span className={iconClass} aria-hidden="true"></span></td>
                <td>{this.props.stock.high}</td>
                <td>{this.props.stock.low}</td>
                <td>{}</td>
                <td>{}</td>
                <td>{}</td>
                <td>{}</td>
                <td>{}</td>
                <td>{}</td>
                <td>{}</td>
                <td>{}</td>
                <td>{}</td>
                <td>{}</td>
            </tr>
            //See edit below to add hidden row here. This part doesn't work.
            <tr style="display: none;" class="subRow">
                <td {5} </td>
            </tr>
        );
    }
});

The initial items on the row(s) contains a button with a plus sign icon. What I would like to do is simulate a tree-like view so that when the user clicks on the button, the icon changes to a minus sign on the parent row, and a set number of new child rows are added underneath between the parent item and the next parent item. The child row items don't have a button on it.

Is this too hard to do without a dedicated web control? If it is not, if someone can show me a simple example that would be great.

EDIT

CSS

.offscreen {
  position: absolute;
  left: -1000px;
  top: 0px;
  overflow:hidden;
  width:0;
}

.subRow {
    background-color: #CFCFCF; 
}

If I try to add a hidden row in the code above where it says "See edit below to add hidden row here", it doesn't work:

<tr style="display: none;" class="subRow">
     <td {5} </td>
</tr>
Ivan
  • 7,448
  • 14
  • 69
  • 134
  • Do you have to add / remove rows? Could you simply hide the child rows and display them when the button is clicked? You can use `style="display:none;"` to hide a `` element and `style="display:table-row"` to show it. See this SO thread for more info: http://stackoverflow.com/questions/30901174/how-to-show-hide-hidden-html-table-rows-using-javascript-no-jquery – Jeff Kilbride Feb 08 '17 at 21:45
  • That would work fine. In fact, I see this http://stackoverflow.com/questions/1144123/how-can-i-hide-an-html-table-row-tr-so-that-it-takes-up-no-space I just don't know how to mix visible rows and invisible rows using CSS and how it would work with the above "return" (the values) statement. – Ivan Feb 08 '17 at 21:54
  • See EDIT on original post. – Ivan Feb 08 '17 at 22:24

0 Answers0