typescript - ag-grid cellEditor select with object values -


i want select list of users:

user.ts

export class user {     constructor (public id: number, public username : string){} } 

the column definition this:

this.columns = [                 {headername: "assigned", field:"user.username",                   editable: true ,celleditor: "select",                   celleditorparams: {values : this.users.map(u=> u.username)}, ]  

i want able select user list , in cellvaluechanged object.

is there option user field , not string value , still user.username shown in cell?

finally found workaround 'select' working key , value.

var colorsnames = []; colors.foreach(color=> {   colorsnames.push(color.name); }) ...  {   headername: "color",   field: "colorid",   width: 150,   editable: true,   celleditor: 'select',   cellrenderer: function (data: any) {     var color = colors.find(color => color.id == data.value || color.name == data.value);     // here i've added check 'color.id' , 'color.name' because initailly db com id , afterwards form selectparams come name     return color.name;   },   oncellvaluechanged: function (data: any) {     /**      * because 'select' not offer possibility use 'key-value' traditional,      * use values in 'select' , changed 'id' when saved.      */     var servicetypename = data.data.servicetypeid;     data.data.servicetypeid = servicetypes.find(servicetype => servicetype.name == servicetypename).id;   },   celleditorparams: {     values: colorsnames   } }, 

the idea inside select params give strings , try find id of object based on name. important agreed name unique field.

after managing working, realized indeed select poor solution. not working , not advice use it.

@yonatan lilling question, please let me know.


Comments