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.
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.
Sample Fiddle: Bootstrap-Table Wenzhixin Get Data On Table CheckAll Event
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 }); } }); });
$('#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 }); } });
Comments
Post a Comment