app/assets/javascripts/effective_datatables/initialize.js.coffee.erb in effective_datatables-2.0.1 vs app/assets/javascripts/effective_datatables/initialize.js.coffee.erb in effective_datatables-2.0.2
- old
+ new
@@ -18,22 +18,34 @@
columnDefs: [
{ visible: false, targets: datatable.data('non-visible') },
{ sortable: false, targets: datatable.data('non-sortable') }
].concat(datatable.data('column-classes') || []).concat(datatable.data('column-names') || [])
order: datatable.data('default-order')
+ serverParams: (params) ->
+ table = this.DataTable()
+ table.columns().flatten().each (index) => # Pass which columns are visible back to server
+ params['columns'][index]['visible'] = table.column(index).visible()
colVis:
showAll: 'Show all'
restore: 'Show default'
activate: 'click'
align: 'right'
label: (index, title, th) -> $(th).prop('title')
+ stateChange: (iCol, bVisible) ->
+ timeout = $(this.dom.button).data('timeout')
+ clearTimeout(timeout) if timeout
+ timeout = setTimeout(
+ =>
+ $(this.dom.button).closest('.dataTables_wrapper').find('table').first().DataTable().draw()
+ $.event.trigger('page:change')
+ , 1000)
+ $(this.dom.button).data('timeout', timeout)
tableTools:
sSwfPath: "<%= asset_path('effective_datatables/copy_csv_xls_pdf.swf') %>",
aButtons: ['csv', {'sExtends': 'xls', 'sButtonText': 'Excel'}, 'print']
- simple = datatable.data('effective-datatables-table') == 'simple'
- if simple
+ if datatable.data('effective-datatables-table') == 'simple'
init_options['lengthMenu'] = [-1] # Show all results
init_options['dom'] = "<'row'r>t" # Just show the table
# Initialize Searching
dataTableSearch = (event) -> # This is the function called by a select or input to run the search
@@ -44,15 +56,17 @@
if table.parent().hasClass('dataTables_scrollHeadInner') # ScrollX support
table = table.closest('.dataTables_scroll').children('.dataTables_scrollBody').children('table.dataTable')
table.DataTable().column("#{obj.data('column-name')}:name").search(obj.val()).draw()
# For every existing Input, Set up the search events
- (search_inputs = datatable.find('thead').first().find('input,select')).each (index, input) ->
+ search_inputs = datatable.find('thead').first().find('input,select')
+
+ search_inputs.each (index, input) ->
$input = $(input)
if $input.data('column-name')
- $input.on 'click', (event) -> false # Dont order columns when you click inside the input
- $input.on 'mousedown', (event) -> event.stopPropagation() # Dont order columns when you click inside the input
+ $input.parent().on 'click', (event) -> false # Dont order columns when you click inside the input
+ $input.parent().on 'mousedown', (event) -> event.stopPropagation() # Dont order columns when you click inside the input
if $input.is('select')
$input.on 'change', (event) -> dataTableSearch(event)
else if $input.is('input')
$input.keyup($.debounce(300, dataTableSearch))