Get line item except one column

1

Hello

I'd like a help regarding clicking a table.

When I clicked on the line the data would come from this row except when clicked on a specific column (column 3 for example), because I want to do another action in the column in question.

Bringing the table data I already have, just missing the column I'd like to save.

Thank you ...

$("tr").on('click',function() {
   var tableData = $(this).children("td").map(function(){
                    return $(this).text();
                }).get(); 
                var codigo =  $.trim(tableData[0]) ;
                alert('Codigo: '+codigo);
                
 })
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://code.jquery.com/jquery-3.2.1.js"></script><tableclass="table table-responsive table-hover">
  <thead>
    <th>ID</th>
    <th>Nome</th>
    <th>Status</th>
  </thead>
  <tbody>
    <tr>
      <td>1</td>
      <td>Carlos</td>
      <td>Ativo</td>
    </tr> 
    <tr>
       <td>2</td>
       <td>Charles</td>
       <td>Inativo</td>
    </tr> 
    <tr>
      <td>3</td>
      <td>Ozeias</td>
      <td>Ativo</td>
    </tr> 
  </tbody>
</table>
    
asked by anonymous 13.07.2017 / 22:54

2 answers

1

You can classify this column and delete it with

 if (e.target.classList.contains('excluir')) return;

Example:

$("tr").on('click', function(e) {
  if (e.target.classList.contains('excluir')) return;
  var tableData = $(this).find("td").map(function() {
    return $(this).text();
  }).get();
  var codigo = $.trim(tableData[0]);
  console.log('Codigo: ' + codigo);
})
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://code.jquery.com/jquery-3.2.1.js"></script><tableclass="table table-responsive table-hover">
  <tr>
    <td>1</td>
    <td>Carlos</td>
    <td class="excluir">Ativo</td>
  </tr>
  <tr>
    <td>2</td>
    <td>Charles</td>
    <td class="excluir">Inativo</td>
  </tr>
  <tr>
    <td>3</td>
    <td>Ozeias</td>
    <td class="excluir">Ativo</td>
  </tr>
</table>
    
13.07.2017 / 23:30
0

You can add a class to that particular row. For example let's put a class c1 .

The code would look like this.

HTML:

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://code.jquery.com/jquery-3.2.1.js"></script><tableclass="table table-responsive table-hover">
  <tr>
    <td>1</td>
    <td>Carlos</td>
    <td>Ativo</td>
  </tr> 
  <tr>
    <td>2</td>
    <td>Charles</td>
    <td>Inativo</td>
  </tr> 
  <tr class="c1">
    <td>3</td>
    <td>Ozeias</td>
    <td>Ativo</td>
  </tr> 
</table>

JavaScript:

 $("tr").on('click',function() {
   var className = $(this).attr('class');
   
   if(className == "c1"){
      alert("Ação diferenciada para esta linha");
      return;
   }

   var tableData = $(this).children("td").map(function(){
                    return $(this).text();
                }).get(); 
                var codigo =  $.trim(tableData[0]) ;
                alert('Codigo: '+codigo);
                
 })

So when you click on a table row it will be checked if it has class c1 , if yes it will perform that differentiated action. I just put an alert because I do not know what you intend to do.

    
13.07.2017 / 23:08