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