javascript - jQuery datatables - select not working - Stack Overflow

When i apply dataTables functionality on a given table and want it to be selecteable, i perform the fol

When i apply dataTables functionality on a given table and want it to be selecteable, i perform the following:

 var table = $('#table').DataTable( {
        select: true
    });

Which is working fine on the first table on the same site. However, when i try to have a second selecteable table, it just won't select on click. It shows the info message "click to select", though.

I have loaded the dataTables.select.min.js file, after loading the dataTables.js itself. (It works on the first table on the site, even without loading the dataTables.select.min.js, but i wanted to be sure..)

I also tried to apply table.select() after initialization, it does not work either.

Any ideas on why this isn't working properly?

DataTabels version is 1.10.16, select version is 1.2.3

Edit: My second table is being build on a button click, asynchronuosly via ajax call to get the data, and then using js .innerHTML to actualy build the DOM for the second table. So maybe the problem is, that i do not apply the datatables functionality for the second table on $(document).ready, as i do not have the option to do so?

When i apply dataTables functionality on a given table and want it to be selecteable, i perform the following:

 var table = $('#table').DataTable( {
        select: true
    });

Which is working fine on the first table on the same site. However, when i try to have a second selecteable table, it just won't select on click. It shows the info message "click to select", though.

I have loaded the dataTables.select.min.js file, after loading the dataTables.js itself. (It works on the first table on the site, even without loading the dataTables.select.min.js, but i wanted to be sure..)

I also tried to apply table.select() after initialization, it does not work either.

Any ideas on why this isn't working properly?

DataTabels version is 1.10.16, select version is 1.2.3

Edit: My second table is being build on a button click, asynchronuosly via ajax call to get the data, and then using js .innerHTML to actualy build the DOM for the second table. So maybe the problem is, that i do not apply the datatables functionality for the second table on $(document).ready, as i do not have the option to do so?

Share Improve this question edited Nov 21, 2017 at 13:28 Gyrocode. 59k16 gold badges156 silver badges192 bronze badges asked Nov 21, 2017 at 11:47 Toni LatenzToni Latenz 2162 gold badges5 silver badges21 bronze badges 2
  • Do both tables have the #table id - if so that's the problem. Use a class to select multiple elements as ids must be unique – Rory McCrossan Commented Nov 21, 2017 at 11:49
  • They have different id's. As far as i know, the class tag is used to define dataTables options only. – Toni Latenz Commented Nov 21, 2017 at 11:51
Add a ment  | 

2 Answers 2

Reset to default 1

Either initialize your tables using class name once:

var table = $('.example').DataTable({
    select: true
});

or initialize your table separately by using ID:

var table1 = $('#example1').DataTable({
    select: true
});

var table2 = $('#example2').DataTable( {
    select: true
});

See this example for code and demonstration.

So yeah, the problem was, i did not initialize the second table within a $(document).ready function. Doing so, solved the issue.

Thank you for your contribution.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744389691a4571844.html

相关推荐

  • javascript - jQuery datatables - select not working - Stack Overflow

    When i apply dataTables functionality on a given table and want it to be selecteable, i perform the fol

    7天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信