Topic: Datatable Row Checkbox: disable or autocheck it
                  
                  futureweb
                  priority
                  asked 3 years ago
                
Is there any simpel way to interact with the checkbox that selects a row of a datatable?
(Check it per default or disable the checkbox if some conditions of the row are met?
                      
                      Dawid Wajszczuk
                      staff
                        answered 3 years ago
                    
Hi,
You can write your own functions to conditionally check checkbox. Here is a basic example
document.querySelectorAll('tr').forEach((row)=>{
  row.querySelectorAll('td').forEach((field)=>{
    if (field.innerHTML==='Tiger Nixon'){
      row.querySelector('input').checked = true
    }
  })
})
Here is the snippet https://mdbootstrap.com/snippets/standard/d-wajszczuk/3508587#js-tab-view.
Keep coding,
Dawid
futureweb priority commented 3 years ago
Thanks for the snippet, I used .click() instead of checked = true which will trigger it as clicked to know which ones are checked.
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Answered
- ForumUser: Priority
 - Premium support: Yes
 - Technology: MDB Standard
 - MDB Version: MDB5 3.10.1
 - Device: PC
 - Browser: Chrome
 - OS: Windows 11
 - Provided sample code: No
 - Provided link: No