Skip to content

Instantly share code, notes, and snippets.

@hamxiaoz
Created December 3, 2014 19:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hamxiaoz/d3029c9fba8d0faaaa0d to your computer and use it in GitHub Desktop.
Save hamxiaoz/d3029c9fba8d0faaaa0d to your computer and use it in GitHub Desktop.
Datatables init
$('#channels-table').dataTable
scrollX: true
scrollY: '600px'
scrollCollapse: true
paging: false
destroy: true
dom: 'lrtip' # remove filter but keep 'searching' option in order to make column filter work
# table row select effect
$('#channels-table tbody tr').on 'click', (e)->
$(e.currentTarget).parents('table').find('tr.warning').removeClass 'warning'
$(e.currentTarget).addClass 'warning'
$('.select2able').select2
allowClear: true
# search on channel name
$("#channel-select2").on "change", (e)->
if !!e.val
dt = $('#channels-table').DataTable()
if dt.rows().length != 0
# find tr and click
# http://datatables.net/reference/type/row-selector
indexes = dt.rows().eq( 0 ).filter (rowIdx)->
return dt.row(rowIdx).data()[0] == e.val
dt.rows( indexes ).nodes().to$().click()
# Scroll to make visible
# http://datatables.net/forums/discussion/2140/scroll-to-highlighted-row
# Uses JQuery.scrollTo.js
scrollArea = '.dataTables_scrollBody' #dt.fnSettings().nTable.parentNode
$(scrollArea).scrollTo('tr.warning',1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment