【问题标题】:Not able to use Responsive event无法使用响应事件
【发布时间】:2019-12-03 09:41:45
【问题描述】:

我使用带有原始 HTML 的 DataTable。

目前,我正在尝试捕捉.on('responsive-display') 事件。

这是我的方法:

我在一个文件中实例化 DataTable:

$('#DataTables_Table_0').DataTable({
    responsive: {
        details: {
            type: 'column',
            target: 'tr'
        }
    }
});

在另一个文件中,我尝试在一行打开时记录日志以显示更多内容:

$('#DataTables_Table_0').dataTable().api().on('responsive-display', function (e, datatable, row, showHide, update) {
    console.log('Details for row ' + row.index() + ' ' + (showHide ? 'shown' : 'hidden'));
});

在也试过了:

$('#DataTables_Table_0').DataTable().on('responsive-display', function (e, datatable, row, showHide, update) {
    console.log('Details for row ' + row.index() + ' ' + (showHide ? 'shown' : 'hidden'));
});

$('#DataTables_Table_0').dataTable().on('responsive-display', function (e, datatable, row, showHide, update) {
    console.log('Details for row ' + row.index() + ' ' + (showHide ? 'shown' : 'hidden'));
});

当我单击一行打开它时,它不会记录任何内容。我想我错误地使用了这个插件。

如果你有任何线索,请分享!

【问题讨论】:

  • 检查documentationon() 在 DataTable 引用上调用,而不是在 api() 引用上。
  • 嗨,我试过没有,并相应地编辑了我的帖子。
  • DataTable(),而不是dataTable()。两者不一样。
  • 抱歉,我修正了我的错字

标签: javascript jquery html datatables


【解决方案1】:

问题在于我没有在我的表上设置和使用 id 属性,而是使用了 DataTable 生成的属性。

【讨论】:

    猜你喜欢
    • 2016-04-25
    • 2012-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多