如何在 laravel ajax 中使 yajra 数据表的整行可点击?即每个整行都可点击。以下是我的示例代码

问题描述 投票:0回答:2
$(函数() { $('#tableDT').DataTable({ 处理:真实, 服务器端:正确, ajax: '{{ 路线('客户') }}', 列: [ { 数据:'名字',名称:'名字' }, { 数据:'姓氏',名称:'姓氏' } ] }); });
ajax laravel
2个回答
0
投票

我为您编写了一个示例,希望这就是您的意思并且可以帮助您。

var dataSet = [
    [ "Tiger", "Nixon" ],
    [ "Garrett", " Winters" ],
    [ "Ashton", " Cox" ],
    [ "Cedric", " Kelly" ],
    [ "Airi", " Satou" ],
    [ "Thane", " Horton" ],
    [ "Burton", " Jackson" ],
    [ "Macaulay", " Cohen" ],
    [ "Steel", " Whitfield" ],
    [ "Travis", " Ochoa" ],
];
 
$(document).ready(function() {
    var selected = [];                       

    $('#tableDT').DataTable( {
        data: dataSet,
        columns: [
            { title: "First Name" },
            { title: "Last Name" },
        ],
        select: { style: 'multi' },          
        rowCallback: function( row, data ) { 
            if ( $.inArray(data.DT_RowId, selected) !== -1 ) {
                $(row).addClass('selected');
            }
        }
    } );
    
        $('#tableDT tbody').on('click', 'tr', function () {
        var id = this.id;
        var index = $.inArray(id, selected);
 
        if ( index === -1 ) {
            selected.push( id );
        } else {
            selected.splice( index, 1 );
        }
 
        $(this).toggleClass('selected');
    } );
} );
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.21/css/jquery.dataTables.min.css">

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.datatables.net/1.10.21/js/jquery.dataTables.min.js"></script>
<table id="tableDT">
<thead>

</thead>
<tbody>

</tbody>

</table>


0
投票

我使用了 yajra 数据表的行编辑选项

->setRowAttr([
     'onclick' => function(User $user) {
        return 'alert('.$user->name.')';
      },
 ])

我希望这对某人有帮助。

© www.soinside.com 2019 - 2024. All rights reserved.