Find all checked ckeckboxes in a datatable


Topic: Find all checked ckeckboxes in a datatable

dmermigas pro asked 6 years ago

Hi,

I have the same datatable as your example with a checkbox in every row. How can i get all checked checkboxes on all rows of the datatable regardless of the datapage they are located?


Piotr Glejzer staff commented 6 years ago

Hi,

is that what you want?

$('#id-for-your-table').find('input[type=checkbox]:checked');
 
You have to use after/before (it dosen't matter) $('document).ready(function() {}).
 
Best,
Piotr
 

dmermigas pro commented 6 years ago

Partially correct. This shows the checked items on the currenct page only! I want to find the checked items in the whole datatable regardless the page they are. The result i am aiming at is checked_items = "ID1, ID2, ID15,..."


dmermigas pro commented 6 years ago

Hi,

I found how to return all checked checkboxes ids in a comma separated field in a datatable regardless the page they are.

 

 var table = $('#MyTable').DataTable();

  var checkedvalues = table.$('input:checked').map(function () {
return this.id;
}).get().join(',');


Piotr Glejzer staff commented 6 years ago

Cool. I'm happy that you find a solution. I have an another for that but I think your is better.

let table=$('#MyTable').DataTable();
let arr= [];
let checkedvalues = table.$('input:checked').each(function () {
arr.push($(this).attr('id'))
});
arr=arr.toString();
 
Have a nice day.

Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Resolved

Specification of the issue
  • User: Pro
  • Premium support: No
  • Technology: MDB jQuery
  • MDB Version: 4.5.10
  • Device: Pc
  • Browser: Ie and Firefox
  • OS: Win 10
  • Provided sample code: No
  • Provided link: No