var table = $('#cash_outs_table').DataTable(); $('#cash_outs_table').dataTable().fnClearTable(); <% @cash_outs.each_with_index do |cash_out, key| %> var index = '<%= key +1 %>' var row = $('<%= j render (cash_out) %>'); row.find('td:eq(0)').text(index); table.row.add(row).draw(); <% end %>