我为您编写了一个示例,希望这就是您的意思并且可以帮助您。
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>
我使用了 yajra 数据表的行编辑选项
->setRowAttr([
'onclick' => function(User $user) {
return 'alert('.$user->name.')';
},
])
我希望这对某人有帮助。