Thank you for your reply.
I had another query.
$(document).on(‘changeDate’, ‘[id^=“ToDate”]’, function (event) {
var id = $(this).attr(‘id’).replace(‘ToDate’, ‘’); // Extract the numeric part of the ID
var shiftValue = $(’[id^=“Shiftnew’ + id + '”]’).val();
var fromDateValue = $(’[id^=“FromDate’ + id + '”]’).val();
updateSelectedRange1(shiftValue, fromDateValue, event.target.value);
});
function updateSelectedRange(value, startDate, endDate) {
var start = new Date(startDate);
var end = new Date(endDate);
// Prepare data object for bulk update
var dataChanges = [];
var currentStart = new Date(start);
while (currentStart <= end) {
var dateKey = (currentStart.getDate()) + currentStart.toLocaleDateString('en-US', { weekday: 'short' }).charAt(0);
var columnIndex = headers.indexOf(dateKey) + 1;
if (columnIndex !== -1 && headers[columnIndex] !== 'Employee') {
for (var rowIndex = 0; rowIndex < hot.countRows(); rowIndex++) {
if (!dataChanges[rowIndex]) {
dataChanges[rowIndex] = {};
}
// Preserve the "Employee" column value
dataChanges[rowIndex]['Employee'] = hot.getDataAtCell(rowIndex, 0);
// Update the other columns
dataChanges[rowIndex][dateKey] = value;
}
}
currentStart.setDate(currentStart.getDate() + 1); // Move to the next day
}
// Use loadData to update the data in bulk
hot.loadData(dataChanges);
}
On change of date I am adding values in the grid. I have multiple dynamic date fields. I am using loadData to add values in the grid. Is there any way i can retain values in the grid. Because on change of date, it removes the old data completely. I only need to update some data on change
I tried using setdataatcell as well but it takes a lot of time to write data in cells. here is the code:
function updateSelectedRange(value, startDate, endDate) {
var start = new Date(startDate);
var end = new Date(endDate);
// Get the index of the first column to skip
var firstColumnIndex = 1;
// Iterate through the date range and update corresponding cells, starting from the second column
for (var rowIndex = 0; rowIndex < hot.countRows(); rowIndex++) {
// Iterate through the date range and update corresponding cells, starting from the second column
var currentStart = new Date(start); // Reset currentStart for each row
while (currentStart <= end) {
var dateKey = (currentStart.getDate()) + currentStart.toLocaleDateString('en-US', { weekday: 'short' }).charAt(0);
var columnIndex = headers.indexOf(dateKey) + 1;
if (columnIndex !== -1 && columnIndex >= firstColumnIndex) {
hot.setDataAtCell(rowIndex, columnIndex, value, 'loadData');
}
currentStart.setDate(currentStart.getDate() + 1); // Move to the next day
}
}
}