【问题标题】:How to close all when I click someone open in Datatables?当我点击某人在数据表中打开时如何关闭所有?
【发布时间】:2020-01-23 04:06:36
【问题描述】:

为打开和关闭细节添加一个事件监听器。当我点击某人打开时如何关闭所有?

$('#laravel_datatable tbody').on('click', 'td.details-control', function () {

            var tr = $(this).closest('tr');
            var row = table.row( tr );

            if ( row.child.isShown() ) {
                // This row is already open - close it
                row.child.hide();
                tr.removeClass('shown');
            }

            else {
                // Open this row
                row.child( format(row.data()) ).show();
                tr.addClass('shown');
            }

});

【问题讨论】:

    标签: jquery ajax datatables


    【解决方案1】:
    Please Add below Code After Line var row = table.row( tr );
    It will find all class (.shown) from datatable and remove it and hide it
    
    $('.shown').each(function(i, obj) {
        newtr = $(this).closest('tr');
        newrow = table.api().row( newtr );
        newrow.child.hide();
        newtr.removeClass('shown');
    });
    

    【讨论】:

      猜你喜欢
      • 2022-08-10
      • 2020-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多