ok, I do have the data on the backend on the rails server.
But, it’s sending the entire table array, instead of just the value of the checkbox that has been checked.
function checkboxRenderer(instance, td, row, col, prop, value, cellProperties) {
// Create a checkbox input element
const checkbox = document.createElement(‘input’);
checkbox.type = ‘checkbox’;
checkbox.checked = value;
// Handle the checkbox click event
checkbox.addEventListener(‘click’, (event) => {
data[row][prop] = event.target.checked; // Update the data source
// sendUpdateToBackend(data); // Send the updated data to the backend
});
// Append the checkbox to the table cell
td.appendChild(checkbox);
td.style.textAlign = ‘center’; // Center-align the checkbox
sendUpdateToBackend(data); // Send the updated data to the backend
Handsontable.renderers.CheckboxRenderer.apply(this, arguments); // Call the built-in checkbox renderer
}
function sendUpdateToBackend(updatedData) {
// in this part you should put the function inside the controler
fetch('/projects/assign_roles2_update', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ data: updatedData }),
})
.then(response => {
if (response.ok) {
// Handle success
} else {
// Handle errors
}
})
.catch(error => {
// Handle network errors
});
}