Donate

Bootstrap Table Get Or Retrieve All Table Data On CheckAll Event

Good evening fellow developers!

Here's are solutions on how to obtain the Bootstrap-Table by Wenzhixin data if the check all event is fired. The first one loops through the table rows and then looks for the element in the row that holds the data either in the element attribute or innerText and retrieves it using jQuery methods.
$('#AttachmentsTable').on('check-all.bs.table', function (e, rows) {
    var allrows = $("#AttachmentsTable tr");
    downloadAttachmentsArray.length = 0;
    downloadAttachmentsArray = [];
 
    $.each(allrows, function (i, item) {
        if (i > 0) {
            var aElem = $(item).find('a').attr('file');
            downloadAttachmentsArray.push({ Filename: aElem });
        }
    });
});
The better solution uses the built-in getData method of the bootstrap table which returns an array. And then you may then loop through that array to get the data.
$('#AttachmentsTable').on('check-all.bs.table', function (e, rows) {
    var $table = $('#AttachmentsTable');
    var data = $table.bootstrapTable('getData');

    downloadAttachmentsArray.length = 0;
    downloadAttachmentsArray = [];

    for (var i = 0; i < data.length; i++) {
        downloadAttachmentsArray.push({ Filename: data[i].fn });
    }
});
Sample Fiddle: Bootstrap-Table Wenzhixin Get Data On Table CheckAll Event

Comments

Donate

Popular Posts From This Blog

WPF CRUD Application Using DataGrid, MVVM Pattern, Entity Framework, And C#.NET

TypeScript Error Or Bug: The term 'tsc' is not recognized as the name of a cmdlet, function, script file, or operable program.

Invalid nested tag div found, expected closing tag input