2

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!

1 Answer 1

6

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.