Rails dataTables add row not working
-
21-12-2019 - |
Question
I'm using gem 'jquery-datatables-rails', '~> 2.1.10.0.3'
in a Rails project.
I'm just starting an attempt to use the dataTable add row feature.
This is my JavaScript (Coffeescript):
t = $("#dataTableAdd").dataTable
bfilter: true
iDisplayLength: 25
bLengthChange: true
"sPaginationType": "bootstrap"
oColVis:
buttonText: "Hide/Show"
bRestore: true
sDom: "C<\"clear\">lrTtiXp"
oTableTools:
aButtons: [
sExtends: "xls"
sButtonText: "Save Excel"
,
sExtends: "pdf"
sPdfOrientation: "landscape"
sPdfMessage: "pdf"
mColumns: "visible"
sButtonText: "Save PDF"
]
$("#addRow").on "click", ->
t.row.add([
"Name"
"Description"
"Type"
"Count"
"Manufacturer"
"Man Date"
"Purchase Date"
"Purchase Price"
"Actions"
"Actions2"
]).draw()
return
I'm getting this error when I click on the addrow button:
Uncaught TypeError: Cannot read property 'add' of undefined
It happens on the t.row.add
line.
Thanks for the help!
Solution
Instead of:
t = $("#dataTableAdd").dataTable
try:
t = $("#dataTableAdd").DataTable
It looks like the old datatables API 'dataTable()
' does not support the function you are calling. Use the new API with: 'DataTable()
'. Read here for more info: https://datatables.net/blog/2014-02-04#API
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow