Wijmo 5 - ListBox selection

HTML

<link rel="stylesheet" href="https://cdn.grapecity.com/wijmo/5.20183.568/styles/wijmo.min.css">
<script src="https://cdn.grapecity.com/wijmo/5.20183.568/controls/wijmo.min.js"></script>
<script src="https://cdn.grapecity.com/wijmo/5.20183.568/controls/wijmo.input.min.js"></script>
<script src="https://cdn.grapecity.com/wijmo/5.20183.568/controls/wijmo.grid.min.js"></script>
<h3>Row/RowRange</h3>
<p>The grid selection stays on the newly created row when you edit the NewRowTemplate:</p>
<div id="RowGrid" style="width:100%;height:150px"></div>

<h3>ListBox</h3>
<p>The grid selection moves down to the NewRowTemplate row when you create a new row:</p>
<div id="ListBoxGrid" style="width:100%;height:150px"></div>

JavaScript

var countries = 'Germany,Iceland'.split(',');
var data = [];
for (var i = 0; i < countries.length; i++) {
  data.push({
    country: countries[i],
    downloads: Math.round(Math.random() * 20000),
    sales: Math.random() * 10000,
    expenses: Math.random() * 5000
  });
}
  
function createGrid(selector, selectionMode) {

  var cv = new wijmo.collections.CollectionView(data);
  cv.canAddNew = true;

  var flex = new wijmo.grid.FlexGrid(selector, {
    autoGenerateColumns: false,
    selectionMode: selectionMode,
    isReadOnly: false,
    allowAddNew: true,
    itemsSource: cv,
    columns: [
      { header: "Downloads", binding: "downloads", dataType: wijmo.DataType.Number },
      { header: "Country", binding: "country", dataType: wijmo.DataType.String, width: 80, wordWrap: true },
      { header: "Sales", binding: "sales", dataType: wijmo.DataType.Number, format: "n2" },
    ],
  });
  if(selectionMode == wijmo.grid.SelectionMode.ListBox){
  	flex.rowAdded.addHandler(function(sender, args){
    	let item = sender.rows[args.row].dataItem;
      sender.selectedItems = [item];
    });
  }
  
  flex.beginningEdit.addHandler(function (sender, args) {
  	console.log("SELECTION ROW:", args.row, sender.selection.row);
  	console.log("SELECTION COL:", args.col, sender.selection.col);
  });
  
  return flex;
}

onload = function() {
  var g1 = createGrid("#RowGrid", wijmo.grid.SelectionMode.Row);
  var g2 = createGrid("#ListBoxGrid", wijmo.grid.SelectionMode.ListBox);
  window['g1'] = g1;window['g2'] = g2;
}