Posted 14 September 2017, 2:46 am EST
We are testing some grids for our new angular app.
FlexGrid is one of our favorites but we have a little problem.
We are using the grid to edit articles. Each article has two units: ‘piece’ and ‘carton’
These units are stored in the article-object.
At the begining we’re creating a new object and push all the units into it.
angular.forEach(pos.article.units, function(unit) { var temp = { id: unit.id, name: unit.name }; myUnits.push(temp); });
Afterwards we’re filtering out duplicates cause each article can be added more than once.
var temp = {}; for (var i = 0; i < myUnits.length; i++) { temp[myUnits[i]['id']] = myUnits[i]; } myUnits= new Array(); for (var key in temp) { myUnits.push(temp[key]); }
To edit the units within the grid we’re using a datamap like this.
this.dmUnits = new wijmo.grid.DataMap(myUnits, 'id', 'name');
As far as everything works but if we change the unit within the grid the wrong id will be stored. (It seems to be the id of the first articel with the unit ‘piece’ or ‘carton’.)
this.beginningEdit = function(s, e) { var col = s.columns[e.col]; if (col.binding == 'unitId') { var view = col.dataMap.collectionView; var ids = _.map(s.rows[e.row].dataItem.article.units, function(unit) { return unit.id; }); view.filter = function(item) { var bool = ids.indexOf(item.id) > -1 return bool; } } } this.cellEditEnded = function(s, e) { var item = s.rows[e.row].dataItem; //this item has the wrong id - not the selected if (e.col === 6) { ... } ... };
The markup:
<wj-flex-grid items-source="ctrl.cvPositions" initialized="ctrl.init(s,e)" beginning-edit="ctrl.beginningEdit(s,e)" cell-edit-ended="ctrl.cellEditEnded(s, e)" cell-edit-ending="ctrl.cellEditEnding(s, e)"> ... <wj-flex-grid-column header="Unit" binding="unitId" data-map="ctrl.dmUnits"></wj-flex-grid-column> ... </wj-flex-grid>
NOTE: If the units have different names, there is no problem but this is not possible for us.