• About Morris Development
  • A Focus for Cloud Efficiency
    • Microsoft Azure
    • Amazon Web Services
  • What our Clients Say
  • Our Products
    • PreschoolDB
    • WebinarDB
  • Contact Us

Morris Development

Custom System Development and Integration

April 2, 2021

Modifying Dropdown options on AG-Grid after grid has rendered

AG-Grid is created, all the structure and settings are fixed. However, one particular issue presents itself when trying to insert dropdown options. The grid begins to render immediately as the page is constructed. There is no clear way to actually modify the options after the grid has been rendered.

So, here is how to do it.

I have a grid with a column for “General Foreman”. The user needs to be able to pick the foreman from a dropdown menu. However, the foreman names come from a json object array which is downloaded asynchronously. So, when the grid was rendered there were no values in my array of foremen. The way to fix it is to bind the options to a function which returns the list.

First, make a function which returns a list of values. I generally have mine in an object array, so I need to extract them and just make an array like this [“Joe”,”Bob”,”Mary”, “Frank”].

I have a service called “datastore.service.ts” that I inject into my component. Inside, I have a property called “generalForemanOptionsArray”. That array starts out as [].

  generalForemen() {
    
    let options = this.dataStore.generalForemanOptionsArray; 
    options.unshift("");  /* Just add a blank value in case there is no person selected */
    return { values: options }
  }
 // Then in the column, we use the bind function
    {
      headerName: "General Foreman", sortable: true, field: "generalForeman", hide: true, editable: true, enableValue: true, enableRowGroup: true, enablePivot: true,
      cellEditor: "agRichSelectCellEditor",
      cellEditorParams: this.generalForemen.bind(this),
   
    },

Ok, so now we have an empty array. The grid has rendered and the only option available is a blank record. Now, at any time, I can update the generalForemanOptionsArray to contain a list of values and the grid will display those options when the select box is activated. Every single time it is activated, it will seek out that function and use its results to generate the options.

Honestly, that took FOREVER to figure out!

ALTERNATIVELY

You can actually use route resolvers to do this. With that method, you’d be pulling in your data when the route is activated and the page wouldn’t begin to render until all the data was loaded. Then, you’d have the data before the grid was set up and you could use those select box options in the original column definitions. If you already use route resolvers, then that’s probably the best way to go. In my case, however the options are sometimes different depending upon the job. For example, if the job is taking place in Region A, it can only offer a selection of Foremen who are available to work in Region A. So, even if I used a route resolver to get the data initially, I would STILL have to modify them after the fact using a bind().

Article by MacGyver / Angular 2 / aggrid

About MacGyver

I've worked with database systems for over 20 years, and started my own company in 2000. Almost all my business consists of internal database systems, either ERP or CRM. My programming is primarily in Angular / Microsoft C# and MS SQL.

About This Site

Morris Development has been specializing in internal database system design and integration since 1999. We provide long-term management and support of secure data systems for many businesses as well as developing the more complex code structures for ERP systems like Intellievent, Apidas, and AVMS.

This site is primarily for our developers to keep track up various technologies and updates that are used by Morris Development.

Training

Integrating Angular Microsite with .Net

Private Data Caching with Google Storage

Continuous Deployment for Production Releases?

Azure Websites – the perfect Angular host

Angular 2

  • Angular 2 Authentication
  • Angular Command Line Interface
  • Material Design for Angular
  • Using Observables in Angular 2

Mentors

  • Ben Nadel
  • Dan Wahlin
  • Deborah Kurata
  • John Papa

Staff

  • Dan Morris

Training

  • Google Development Courses
  • Microsoft Virtual Academy
  • PluralSight
  • Test Deep Links

© 2025 · Morris Development