Instantly share code, notes, and snippets.

Embed
What would you like to do?
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