var table = $('#products_table').DataTable(); var newRow = $('<%= j render (@product_waste) %>'); x = $('#products_table').dataTable(); newRow.find('td:eq(0)').html(newRow.find('td:eq(0)').html().replace('#', x.fnGetData().length + 1)); table.row.add(newRow).draw();