Posted 29 June 2018, 2:20 am EST
Hi,
We are indeed sorry for the issue in the last sample. We can fix that by assigning new array for each individual data cell.
In _closeEditor method replace this code
this._grid.setCellData(this._rng.row, this._rng.col, ctl.checkedItems);
//with following
this._grid.setCellData(this._rng.row, this._rng.col, ctl.checkedItems.map(item=>item));
For adding support for an array of object we need few more minor adjustments.
First, define a function which will determine if the given objects are equal based on some condition
function areObjectEqual(obj1,obj2){
/* if ref are equal objects are definitely equal
can also compare value types */
if(obj1===obj2){
return true;
}
for(let key in obj1){
if(obj1[key]!=obj2[key]){
return false;
}
}
return true;
}
//then in _beginningEdit method instead of assigning the data from grid directly to multiselect first create a new array of objects that contains the values from grid then assign it to multiselect.checkedItems
//if multiselect
var data=grid.getCellData(this._rng.row, this._rng.col, false);
if((data instanceof Array)&&(this._ctl instanceof wijmo.input.MultiSelect)){
var checked=[];
data.forEach(dataItem=>{
for(let item of this._ctl.itemsSource){
if(areObjectEqual(dataItem,item)){
checked.push(item);
break;
}
}
});
this._ctl.checkedItems=checked;
}
Finally to display the array of objects into grid’s cell you need to handle the formatItem event and convert the array to the required display string value:-
grid.formatItem.addHandler((s,e)=>{
if(e.panel!=s.cells||e.editRange){
return;
}
if(s.columns[e.col].binding!="products"){
return;
}
var dataItem=s.rows[e.row].dataItem.products;
var displayString=dataItem.reduce((acc,curr)=>{
if(acc){
return acc+","+curr.value;
}else{
return curr.value;
}
},"");
e.cell.innerHTML=displayString;
});
Please refer to the following updated sample and let us know if you still face any issues:-
https://stackblitz.com/edit/js-3iesr9-kfqjmy?file=index.js
~Manish