Hello Handsontable Forum,
Iam loading data from a Database and hand it over to JS in Drupal with:
$build['#attached']['drupalSettings']['row'] = $row;
Everything is working fine (only the last row) but I cant change the Cells with the loaded data when the table is initialized.
The whole table freezes when I change something above the last empty row(see Screenshots).
With var $row = drupalSettings.row;
I get an array as strings and hand them over to load the saved data and generate some predefined cells with
function getData() {
var $result=[];
var $count =1;
$.each($row, function (index,value) {
$count++;
$result.push([
[$row[index]['nr']],[$row[index]['fah']],[$row[index]['time']],[$row[index]['auto']],[$row[index]['fromo']],[$row[index]['from']],[$row[index]['targeto']],[$row[index]['target']]]]
]);
});
$result.push([
[$count],getDate(),getTime()
]);
return $result;
}
Iam changing the source of an cell when another cell has a specific value:
var example1 = document.getElementById('example');
var config;
config = {
data: getData(),
colHeaders: ['Nr', 'datum', 'Uhrzeit', 'Car', 'FromPlace', 'FromStr', 'Targetplace', 'Targetstr'],
columns: [
{type: 'numeric',editor: false},
{type: 'date', dateFormat: 'D.M.YYYY'},
{type: 'time', timeFormat: 'HH:MM'},
{
type: 'autocomplete',
source: ['T1','T2', 'T3', 'T4', 'T5', 'T6', 'T7', 'T8','M1', 'M2', 'M3', 'M4', 'M5', 'M6', 'M7', 'M8', 'N1', 'N2', 'N3', 'N4', 'N5', 'N6', 'N7', 'N8'],
strict: true
},
{
type: 'autocomplete',
source: ['Dietzenbach','Darmstadt','Frankfurt am Main','Offenbach am Main'],
strict: true
},
{
type: 'autocomplete',
strict: true
},
{
type: 'autocomplete',
source: ['Dietzenbach','Darmstadt','Frankfurt am Main','Offenbach am Main'],
strict: true
},
{
type: 'autocomplete',
strict: true
}
],
afterChange: function cellChange(changes, source) {
if (!changes) {
return;
}
var $countRow=hot1.countRows();
var $lastRow=hot1.getDataAtRow($countRow-1);
if(changes[0][1] === 4)
{
hot1.getCellMeta(changes[0][0],5).source=getStreets(changes[0][3]);
}
if(changes[0][1] === 6)
{
hot1.getCellMeta(changes[0][0],7).source=getStreets(changes[0][3]);
}
if($lastRow[4]!= null && $lastRow[5]!= null && $lastRow[6]!= null && $lastRow[7]!= null)
{
hot1.alter('insert_row');
hot1.setDataAtCell([[$countRow,0,$countRow+1],[$countRow,1,getDate()],[$countRow,2,getTime()]]);
}
var hot1 = new Handsontable(example1, config);
});
}
}
Iam sure its some small problem I dont see but Iam struggling since hours