Update entire colum in datatable jquery

2.6k views Asked by At

I am using jquery datatable plugin and I want to update entire column values on click of button. How do i do that.

I tried using fnUpdate but here we need to specify row and column.

This my html code for table

<table id="regions" class="display" cellspacing="0" width="50%">
  <thead>
      <tr>
          <th>Region</th>  
          <th>Min Score</th>  // Want min max col editable
          <th>Max Score</th> //min < max                          
      </tr>                         
  </thead>

  <tbody>   
    <% for scores_row in scores_regions %>                                                   
    <tr>
            <td><%= label_tag 'regions[]',scores_row.at(0) %></td>  
            <td>1</td>
            <td>1000</td>
   </tr>

   <% end %>
  </tbody>      
</table>

This is my jquery code ,which applies to second row third column..I want all rows third column..

$('#button_max_apply').click(function(){ 
    oTable.fnUpdate("text to apply",1,2);
}); 

Thanks

1

There are 1 answers

1
Dhiraj On BEST ANSWER

You can do something like this

myTable.column(2).nodes().each(function(node, index, dt){
  myTable.cell(node).data('40');
});
  • myTable.column(2).nodes() will get the list of nodes of a particular column.
  • myTable.cell(node) will get a particular cell provided node is the DOM element.

Here is a demo http://jsfiddle.net/dhirajbodicherla/189Lp6u6/10/