Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

191
Visualizações
I want to get row Id from Table

In my application I have loaded some information's to the table.

Now I want to get the item id of that row when user clicks.

Here Item.Id is the one I want to get it, but here I didn't assigned to any table row. (I thought it doesn't need to).

So far I have created the JavaScript also, but I'm stuck within getting id in the click event.

Can you help me here?

This is how I done so far:

<div class="table-full-width table-responsive">
<table class="table" id="tblParts">
   <tr>
      <th>
         @Html.DisplayNameFor(model => model.First().PartNo)
      </th>
      <th>
         @Html.DisplayNameFor(model => model.First().PartDescription)
      </th>
      <th>
         @Html.DisplayNameFor(model => model.First().PartModel)
      </th>
      <th>
         @Html.DisplayNameFor(model => model.First().AvaQty)
      </th>
      <th>
         @Html.DisplayNameFor(model => model.First().ReOrderQty)
      </th>
      <th>
         @Html.DisplayNameFor(model => model.First().PartCatogary)
      </th>
      <th>
         @Html.DisplayNameFor(model => model.First().LastUpdated)
      </th>
      <th></th>
   </tr>
   @foreach (var item in Model)
   {
   <tr>
      <td>
         <a href="#">
         @Html.DisplayFor(modelItem => item.PartNo)
      </td>
      <td>
         <a href="#">
         @Html.DisplayFor(modelItem => item.PartDescription)
      </td>
      <td>
         <a href="#">
         @Html.DisplayFor(modelItem => item.PartModel)
      </td>
      <td>
         <a href="#">
         @Html.DisplayFor(modelItem => item.AvaQty)
      </td>
      <td>
         <a href="#">
         @Html.DisplayFor(modelItem => item.ReOrderQty)
      </td>
      <td>
         <a href="#">
         @Html.DisplayFor(modelItem => item.PartCatogary)
      </td>
      <td>
         <a href="#">
         @Html.DisplayFor(modelItem => item.LastUpdated)
      </td>
   </tr>
   }
</table>

This is the script. It triggers when clicks, but I want to get the item id, when user click the certain row.

<script type="text/javascript">
   $("#tblParts tr").click(function (event) {
       alert("Row Clicked");
   });
</script>
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

To get the id From target you have to do this on the code of click and if it has an id it will grab it

function(event){  
  alert(event.target.id)
}

about 4 years ago · Juan Pablo Isaza Relatório

0

One of the solutions is:

<script type="text/javascript">
    $("#tblParts tr").click(function (event) {            
            var cell = this.getElementsByTagName("td")[0];
            alert("PartNo: " + cell.innerText);           
        });
</script>
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda