Show and hide columns dynamically (Rails app)
Show and hide columns dynamically (Rails app)
I'm new to Rails, Datatables, and programming in general, so I may just be making a dumb mistake.
I set up Datatables in my app following the instructions here: http://railscasts.com/episodes/340-datatables?view=asciicast. Everything was working fine.
Since my goal was to allow the user of my app to collapse and show columns, I read this page: http://www.datatables.net/release-datatables/examples/api/show_hide.html.
I translated the javascript initialization code from that page to coffee here: http://js2coffee.org/
Then I pasted this code into my app/assets/javascripts/drivers.js.coffee file:
[code]
fnShowHide = (iCol) ->
oTable = $("#drivers").dataTable()
bVis = oTable.fnSettings().aoColumns[iCol].bVisible
oTable.fnSetColumnVis iCol, (if bVis then false else true)
$(document).ready ->
$("drivers").dataTable
sScrollY: "200px"
bPaginate: false
[/code]
I then inspected the source code of the "Toggle column 1" link on http://www.datatables.net/release-datatables/examples/api/show_hide.html, and pasted the following into my app/views/drivers.html.erb file:
[code]Toggle column 1
[/code]
The link shows, but does not collapse the column. What am I missing?
I set up Datatables in my app following the instructions here: http://railscasts.com/episodes/340-datatables?view=asciicast. Everything was working fine.
Since my goal was to allow the user of my app to collapse and show columns, I read this page: http://www.datatables.net/release-datatables/examples/api/show_hide.html.
I translated the javascript initialization code from that page to coffee here: http://js2coffee.org/
Then I pasted this code into my app/assets/javascripts/drivers.js.coffee file:
[code]
fnShowHide = (iCol) ->
oTable = $("#drivers").dataTable()
bVis = oTable.fnSettings().aoColumns[iCol].bVisible
oTable.fnSetColumnVis iCol, (if bVis then false else true)
$(document).ready ->
$("drivers").dataTable
sScrollY: "200px"
bPaginate: false
[/code]
I then inspected the source code of the "Toggle column 1" link on http://www.datatables.net/release-datatables/examples/api/show_hide.html, and pasted the following into my app/views/drivers.html.erb file:
[code]Toggle column 1
[/code]
The link shows, but does not collapse the column. What am I missing?
This discussion has been closed.