Enable multiple row selection in a DataTable

To enable multiple row selection in a DataTable, you can set the select option to 'multi' when initializing the DataTable, like this:

$(document).ready(function() {
    $('#myTable').DataTable({
        select: 'multi'
    });
});

This will enable multiple row selection using the standard click and shift-click behavior.

You can then get the selected rows using the rows({selected: true}) method. For example, to get the data for all selected rows, you could use:

var table = $('#myTable').DataTable();
var data = table.rows({selected: true}).data().toArray();

This would give you an array of objects, where each object represents a selected row and contains the row's data.

You can also listen for the select and deselect events to perform actions when rows are selected or deselected. For example, to log the selected rows to the console whenever a row is selected or deselected, you could use:

$('#myTable').on('select deselect', function(e, dt, type, indexes) {
    var table = $('#myTable').DataTable();
    var data = table.rows({selected: true}).data().toArray();
    console.log(data);
});

Komentar

Postingan populer dari blog ini

Node.js Telegram Bot API send an image with text

Node.js Telegram BOT retrieve data from API

WhatsApp Web login QR code in an HTML page using whatsapp-web.js