app/assets/javascripts/effective_datatables/initialize.js.coffee.erb in effective_datatables-2.2.1 vs app/assets/javascripts/effective_datatables/initialize.js.coffee.erb in effective_datatables-2.2.2

- old
+ new

@@ -1,10 +1,12 @@ initializeDataTables = -> - $('table[data-effective-datatables-table]').each -> + $('table.effective-datatable').each -> return if $.fn.DataTable.fnIsDataTable(this) datatable = $(this) + simple = (datatable.data('simple') == true) + input_js_options = datatable.data('input-js-options') || {} init_options = ajax: { url: datatable.data('source'), type: 'POST' } autoWidth: false buttons: [ @@ -43,11 +45,11 @@ format: header: (str) -> str.substring(0, str.indexOf('<')) columns: ':visible:not(.col-actions)' }, ] - colReorder: true + colReorder: !simple columns: datatable.data('columns') deferLoading: [datatable.data('display-records'), datatable.data('total-records')] deferRender: true iDisplayLength: datatable.data('display-entries') language: { 'lengthMenu': 'Show _MENU_ per page'} @@ -77,14 +79,10 @@ $th.append('<br>' + settings.filterHtml) initializeFilterEvents($th) $th.addClass('initialized') - if datatable.data('effective-datatables-table') == 'simple' - init_options['lengthMenu'] = [-1] # Show all results - init_options['dom'] = "<'row'r>t" # Just show the table - # Sets up the proper events for each input initializeFilterEvents = (th) -> th.find('input,select').each (_, input) -> $input = $(input) $input.parent().on 'click', (event) -> false # Dont order columns when you click inside the input @@ -99,11 +97,15 @@ dataTableSearch = (event) -> # This is the function called by a select or input to run the search obj = $(event.currentTarget) table = obj.closest('table.dataTable') table.DataTable().column("#{obj.data('column-name')}:name").search(obj.val()).draw() + if simple + init_options['dom'] = "<'row'<'col-sm-12'tr>>" # Just show the table + datatable.addClass('sort-hidden') + # Let's actually initialize the table now - table = datatable.dataTable(init_options) + table = datatable.dataTable(jQuery.extend(init_options, input_js_options)) # Apply EffectiveFormInputs to the Show x per page dropdown if datatable.data('effective-form-inputs') table.closest('.dataTables_wrapper').find('.dataTables_length select').select2()