@@ -, +, @@ --- .../prog/en/modules/admin/cities.tt | 26 ------------ koha-tmpl/intranet-tmpl/prog/js/datatables.js | 40 +++++++++++++++---- 2 files changed, 33 insertions(+), 33 deletions(-) --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/cities.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/cities.tt @@ -181,14 +181,10 @@ cities_table_url += 'q='+ encodeURIComponent(JSON.stringify(city_name_filter)); [% END %] - $('#table_cities thead tr').clone(true).appendTo( '#table_cities thead' ); - - var cities_table = $("#table_cities").api({ "ajax": { "url": cities_table_url }, - orderCellsTop: true, "order": [[ 1, "asc" ]], "columnDefs": [ { "targets": [0,1,2,3,4], @@ -239,28 +235,6 @@ ] }, [], 1); - - var table = cities_table.DataTable(); - $('#table_cities thead tr:eq(1) th').each( function (i) { - var is_searchable = table.settings()[0].aoColumns[i].bSearchable; - if ( is_searchable ) { - var title = $(this).text(); - var search_title = _("Search %s").format(title); - $(this).html( ''.format(search_title) ); - - $( 'input', this ).on( 'keyup change', function () { - if ( table.column(i).search() !== this.value ) { - table - .column(i) - .search( this.value ) - .draw(); - } - } ); - } else { - $(this).html(''); - } - } ); - }); [% END %] --- a/koha-tmpl/intranet-tmpl/prog/js/datatables.js +++ a/koha-tmpl/intranet-tmpl/prog/js/datatables.js @@ -511,6 +511,11 @@ jQuery.fn.dataTable.ext.errMode = function(settings, note, message) { $.fn.api = function(options, columns_settings, add_filters) { var settings = null; + + if ( add_filters ) { + $(this).find('thead tr').clone(true).appendTo( $(this).find('thead') ); + } + if(options) { if(!options.criteria || ['contains', 'starts_with', 'ends_with', 'exact'].indexOf(options.criteria.toLowerCase()) === -1) options.criteria = 'contains'; options.criteria = options.criteria.toLowerCase(); @@ -714,17 +719,38 @@ jQuery.fn.dataTable.ext.errMode = function(settings, note, message) { } ); + $(".dt_button_clear_filter, .columns_controls, .export_controls").tooltip(); + if ( add_filters ) { - // Duplicate the table header row for columnFilter - thead_row = this.find('thead tr'); - clone = thead_row.clone().addClass('filters_row'); - clone.find("th.NoSort").html(''); - thead_row.before(clone); + settings['orderCellsTop'] = true; } - $(".dt_button_clear_filter, .columns_controls, .export_controls").tooltip(); + var table = $(this).dataTable(settings); + + if ( add_filters ) { + var table_dt = table.DataTable(); + $(this).find('thead tr:eq(1) th').each( function (i) { + var is_searchable = table_dt.settings()[0].aoColumns[i].bSearchable; + if ( is_searchable ) { + var title = $(this).text(); + var search_title = _("Search %s").format(title); + $(this).html( ''.format(search_title) ); + + $( 'input', this ).on( 'keyup change', function () { + if ( table_dt.column(i).search() !== this.value ) { + table_dt + .column(i) + .search( this.value ) + .draw(); + } + } ); + } else { + $(this).html(''); + } + } ); + } - return $(this).dataTable(settings); + return table; }; })(jQuery); --