最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - DataTables API methods not available - Stack Overflow

programmeradmin4浏览0评论

I'm trying to set up an extremely basic DataTables example. After initializing the table with DataTables, why are some of the API methods not available? Am I missing something as far as how it's supposed to be used?

Here's a simple jsfiddle where I initialize the table, and then try to retrieve the first row. However, it doesn't look the like row() method exists:

/

Here's the javascript in the fiddle:

$(document).ready(function(){
   var myDataTable = $('#myTable').dataTable();
   console.log(myDataTable.row(0));
});

Developer console shows the following error referring to the console.log line:

Uncaught TypeError: undefined is not a function

Any help here is much appreciated.

I'm trying to set up an extremely basic DataTables example. After initializing the table with DataTables, why are some of the API methods not available? Am I missing something as far as how it's supposed to be used?

Here's a simple jsfiddle where I initialize the table, and then try to retrieve the first row. However, it doesn't look the like row() method exists:

http://jsfiddle/LEWQU/

Here's the javascript in the fiddle:

$(document).ready(function(){
   var myDataTable = $('#myTable').dataTable();
   console.log(myDataTable.row(0));
});

Developer console shows the following error referring to the console.log line:

Uncaught TypeError: undefined is not a function

Any help here is much appreciated.

Share Improve this question edited Jun 17, 2014 at 23:57 flyingL123 asked Jun 17, 2014 at 22:34 flyingL123flyingL123 8,13613 gold badges74 silver badges138 bronze badges 3
  • Authorization required to load the jquery.dataTables.min.js and the jquery-2.0.3.min.js files. – bloodyKnuckles Commented Jun 17, 2014 at 22:44
  • Sorry about that @bloodyKnuckles, it's all fixed now. – flyingL123 Commented Jun 17, 2014 at 23:32
  • For this simple example, this is pulling up the rows: myDataTable[0].rows, and cells can be got: myDataTable[0].rows[0].cells. – bloodyKnuckles Commented Jun 18, 2014 at 0:28
Add a ment  | 

3 Answers 3

Reset to default 3

change

var myDataTable = $('#myTable').dataTable();

to

var myDataTable = $('#myTable').DataTable();

Couple of things:

  1. authorization is required to load jquery datatables (as bloodyknuckles pointed out too)

  2. the method is "dataTable()" and not "DataTable()"

Still not really sure what the issue was, but updating to the newest version of DataTables seems to have worked.

发布评论

评论列表(0)

  1. 暂无评论