Detect TR clicked pass by REACT function

0

How to detect the TH that I clicked and go through parameter in React?

I wanted to do an ordering, but I'm having difficulty going through a parameter in a function that I clicked on, can anyone help me with this?

ordertableBy = async(ev) => {
    console.log(ev.target.value);
    alert('orderby' + ev.target.value);
}
<tr>
    <th onClick={ev => this.ordertableBy(ev)}>Nome</th>
    <th onClick={ev => this.ordertableBy(ev)}>Email</th>
    <th onClick={ev => this.ordertableBy(ev)}>Telefone</th>
</tr>

Returning orderby undefined

    
asked by anonymous 30.12.2018 / 22:49

1 answer

0

In a very simple way you can do this

<th onClick={ev => this.ordertableBy("headerNome")}>Nome</th>
<th onClick={ev => this.ordertableBy("headerEmail")}>Email</th>
<th onClick={ev => this.ordertableBy("headerTelefone")}>Telefone</th>

so your ordertableby would simply be

ordertableBy = async(value) => {
    console.log(value);
    alert('orderby' + value);
}

If you want to use the event, it would be something of the genre

<th value="headerNome" onClick={ev => this.ordertableBy(ev)}>Nome</th>
<th value="headerEmail" onClick={ev => this.ordertableBy(ev)}>Email</th>
<th value="headerTelefone" onClick={ev => this.ordertableBy(ev)}>Telefone</th>

ordertableBy = async(ev) => {
    console.log(ev.target.value);
    alert('orderby' + ev.target.value);
}

PS: Usually used and not when it comes to the table header

    
03.01.2019 / 14:15