0

I'm trying to remove a select element after it gets used and put it into an ag-grid. The object appears to be selected correctly because I can see a row added to the grid, but the name/id properties aren't showing correctly in the grid and the select element is not removed. Here's the screen:

enter image description here

The freeze button runs this code:

freeze(firmCatId) {
const rowObj = this.firmCategories.filter(x => x.id === firmCatId);
this.rowData.push(rowObj);
this.firmCategories.filter(x => {
  x.id !== firmCatId
});
this.gridApi.setRowData(this.rowData);

}

I can see from debugging that the rowObj is selected successfully and added the ag-grid, but again, the column names aren't showing in the grid row. And firmCategories is that array of objects that powers the select, but it is having no effect. The data looks like this: `0: Object {id: "Bicycle", name: "Bicycle Facilities and Enhancement Design"} id:"Bicycle" name:"Bicycle Facilities and Enhancement Design" ....}

enter image description here

333Matt
  • 1,124
  • 2
  • 19
  • 29
  • 1
    You may need to tell Angular to detectChanges() – JWP Mar 25 '20 at 14:03
  • 1
    Try `this.gridApi.setRowData([...this.rowData])` – GreyBeardedGeek Mar 25 '20 at 14:18
  • Thanks for the suggestions, but the spread operator had no effect. In addition, I don't think the detectChanges in the problem here... after this line `this.firmCategories.filter(x => { x.id !== firmCatId });` the number of elements inside the array is still the same. Which seems very strange because I can hit a breakpoint inside there and x.id == "Bicycle" and firmCatId = "Bicycle" – 333Matt Mar 25 '20 at 16:38
  • I'm also wondering if there is something about how the object is constructed of why ag-grid doesn't see those fields the right way. Does it look OK? (adding screenshot to my post) – 333Matt Mar 25 '20 at 16:42
  • I did try the detetChanges() method but it did not seem to work. Leaving aside the grid problems for a moment, There must be something wrong with my .filter methods; even thought it detects an element with the same id, it is not removing that element. – 333Matt Mar 25 '20 at 17:37
  • OK, so as for the filter problem.... it doesn't mutate the array itself, you have to set it to a new array... so it needed `this.firmCategories = this.firmCategories.filter(x => { x.id !== firmCatId });`. Except now, it is removing everything from the array for some reason. What's going wrong here? – 333Matt Mar 25 '20 at 18:51

1 Answers1

0

Got this answer to the array.filter problem, still not sure why my ag-grid won't show it's cell data.

What's wrong with my array.filter syntax?

333Matt
  • 1,124
  • 2
  • 19
  • 29