@@ -, +, @@ --- .../prog/js/elasticsearch-mappings.js | 34 +++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) --- a/koha-tmpl/intranet-tmpl/prog/js/elasticsearch-mappings.js +++ a/koha-tmpl/intranet-tmpl/prog/js/elasticsearch-mappings.js @@ -52,7 +52,9 @@ $(document).ready(function () { alert( __("This field is mandatory and must have at least one mapping") ); return; } else { - $(this).parents('tr').remove(); + var table = $(this).closest('table'); + let dt = $(table).DataTable(); + dt.row( $(this).closest('tr') ).remove().draw(); } }); @@ -62,15 +64,22 @@ $(document).ready(function () { $('.add').click(function () { var table = $(this).closest('table'); + let table_id = table.attr('id'); var index_name = $(table).attr('data-index_name'); var line = $(this).closest("tr"); var marc_field = $(line).find('input[data-id="mapping_marc_field"]').val(); if (marc_field.length > 0) { var new_line = clone_line(line); new_line.appendTo($('table[data-index_name="' + index_name + '"]>tbody')); - $('.delete').click(function () { - $(this).parents('tr').remove(); - }); + let dt = $('#' + table_id).DataTable(); + dt.row.add(new_line).draw(); + + $(table).on( 'click', '.delete', function () { + var table = $(this).closest('table'); + let dt = $(table).DataTable(); + dt.row( $(this).closest('tr') ).remove().draw(); + } ); + clean_line(line); $(table).tableDnD({ @@ -83,9 +92,20 @@ $(document).ready(function () { }); $("#es_mappings").on("submit", function(e){ - $("#search_fields_table").DataTable({ paging: false }).search('').draw(); - $("#mapping_biblios_table").DataTable({ paging: false }).search('').draw(); - $("#mapping_authorities_table").DataTable({ paging: false }).search('').draw(); + let table_ids = ['search_fields_table', 'mapping_biblios_table', 'mapping_authorities_table']; + $(table_ids).each(function(){ + let table; + // Remove warning "Cannot reinitialise DataTable" + if ( $.fn.dataTable.isDataTable( '#' + this ) ) { + table = $('#' + this).DataTable(); + } + else { + table = $('#' + this).DataTable( { + paging: false + } ); + } + table.search('').draw(); + }); return true; }); }); --