Grid - How to set/show selected value in dropdown

Grid - How to set/show selected value in dropdown 

I am not seeing the dropdown values and also the selected value

<ejs-grid [editSettings]='editSettings' [toolbar]='toolbar'      (toolbarClick)='clickHandler($event)' [dataSource]='aProducts' [allowPaging]='true' [allowSorting]='true'
                [pageSettings]='pageOptions' (commandClick)='commandClick($event)'
                (actionBegin)='actionBegin($event)'  (actionComplete)="actionComplete($event)"  
             (cellEdit)="cellEdit($event)"   (rowSelected)='rowSelected($event)'  
            [allowFiltering]='true' [filterSettings]='filterOptions'            >
                <e-columns>
                    <e-column field='name' headerText='Product Name' textAlign='Left' width=90></e-column>
                    <e-column field='personageDetailId' editType='dropdownedit' [edit]='ddParamsP'  headerText='Product Owner' textAlign='Left' width=90>
                    </e-column>
                    <e-column headerText='' width=140 [commands]='commands'></e-column>
                </e-columns>
            </ejs-grid>


 this.ddParamsP = {
      params: {
        allowFiltering: true,
        dataSource: this.usersData,
        fields: { text: 'name'value: 'personageDetailId' },
        // query: new Query(),
        actionComplete: () => false

      }
    }


 

7 Replies 1 reply marked as answer

BS Balaji Sekar Syncfusion Team July 28, 2020 10:30 AM UTC

Hi Vin, 
 
Greetings from the Syncfusion support. 
 
We have validated the dropdownedit type value property does not work while it was being used in edit params option. In edit params we cannot set dropdownedit value, so we suggest to use the cellEditTemplate feature to externally render dropdownlist, then we can use the required dropdownlist properties. For more information please refer to the example code, sample and Documentation below. 
 
[app.component.ts] 
... 
export class NormalEditComponent implements OnInit { 
... 
   public ngOnInit(): void { 
        this.data = orderDatas; 
... 
        this.ddParamsP= { 
                        create: () => { 
                            this.elem = document.createElement('input'); 
                            return this.elem; 
                        }, 
                        read: () => { 
                            return this.dropdownObj.text; //return text property value while selected dropdown item 
                        }, 
                        destroy: () => { 
                            this.dropdownObj .destroy(); 
                        }, 
                       write: (args: { rowData: any, column: any }) => { 
                                                    
                            this.dropdownObj  = new DropDownList({ 
                              dataSource: <any>orderDatas,     
                            value: (args.rowData as any).OrderID,      // set the value property field while editing CustomerID column 
                             fields: { text: 'CustomerID', value: 'OrderID' } 
                            }); 
                            this.dropdownObj .appendTo(this.elem); 
                        } 
                    } 

        this.pageSettings = {pageCount: 5}; 
    } 
 
 
                                https://ej2.syncfusion.com/angular/documentation/grid/edit/#cell-edit-template 

please get back to us, if you need further assistance. 

Regards, 
Balaji Sekar 


Marked as answer

VI vin August 3, 2020 12:47 AM UTC

Thanks
In the grid display mode, i am seeing Product owner ID, instead i need to see the name in the display mode
In edit mode, i am able to see the name of the product owner

How to make it see owner name id display mode?
      <e-column field='personageDetailId'  [edit]='ddParamsP'  headerText='Product Owner' textAlign='Left' width=90>
                       
                    </e-column>




AG Ajith Govarthan Syncfusion Team August 3, 2020 02:40 PM UTC

Hi Vin, 

Thanks for the update. 

Based on your requirement we suspect that you want to use the foreign key column feature of our EJ2 grid. When you use foreign key column feature the dropdown will be rendered for the corresponding column. 

In EJ2 Grid the foreignKey field value will be shown and when you edit the row and select the data from the dropdown will store the appropriate foreignkey value in the datasource. So you can use the foreignkey column feature to show the text values in the grid and can store the id values using the foreign key feature. 


Please get back to us if you need further assistance. 

Regards, 
Ajith G. 



VI vin August 4, 2020 03:23 AM UTC

Its not working, not seeing any error. Looks like its not able to map foreign key
<e-column field='personageDetailId'  [edit]='ddParamsP'  headerText='Product Owner' 
                    textAlign='Left' width=90 foreignKeyValue='name'  [dataSource]='usersData'>                       
                    e-column>

Spinner keeps loading !!



 <ejs-grid [editSettings]='editSettings' [toolbar]='toolbar'      (toolbarClick)='clickHandler($event)' [dataSource]='aProducts' [allowPaging]='true' [allowSorting]='true'
                [pageSettings]='pageOptions' (commandClick)='commandClick($event)'
                (actionBegin)='actionBegin($event)'  (actionComplete)="actionComplete($event)"  
             (cellEdit)="cellEdit($event)"   (rowSelected)='rowSelected($event)'  
            [allowFiltering]='true' [filterSettings]='filterOptions'            >

Products array - aProducts
  1. name"Imperva"
  2. ownerPersonageDetailId5
  3. personageDetailId5
  4. syndicateDetailId7
  5. syndicateProductId1

  1. Users Array - usersData
  2. name"Test Test"
  3. personageDetailId5

Any other solution ?




BS Balaji Sekar Syncfusion Team August 5, 2020 03:32 PM UTC

Hi Vin, 
 
We have validated your query with provided the information and we suspect that you have used edit params in foreignKey column. We suggest you to avoid the editparams in foreignkey column. By default, foreignKey column bind the dropdown editing with foreignKey column dataSource.  
 
If you face sample problem, please share the below details to us that will help to validate further. 
 
  1. Share the video demonstration of the problem.
  2. Share a sample with replicated problem, if possible
  3. Ensure the Syncfusion package version.
 
Regards, 
Balaji Sekar 



VI vin August 6, 2020 03:08 AM UTC

tried removing editparams in foreignkey column, no luck
can you please create a sample with the data samples i gave

Products array - aProducts
  1. name"Imperva"
  2. ownerPersonageDetailId5
  3. personageDetailId5
  4. syndicateDetailId7
  5. syndicateProductId1

  1. Users Array - usersData
  2. name"Test Test"
  3. personageDetailId5


BS Balaji Sekar Syncfusion Team August 7, 2020 07:38 AM UTC

Hi Vin, 
 
Thanks for your patience, 
 
We have created a sample with information provided, and it works properly when using the ForeignKey Column option with your requirement. We suspect that by editparams you have bound the ForeigbKey Column dataSource that is causing the problem. We do have dataSource property in Grid column while using ForeignKey feature. Please refer to the code example and sample for more information. 
[app.component.html] 
  <ejs-grid [dataSource]='aProducts' allowPaging='true' height='400' [pageSettings]='pageSettings' [editSettings]='editSettings'> 
        <e-columns> 
            <e-column field='name' headerText='Product Name' width='120' textAlign='Right' isPrimaryKey='true' ></e-column>            
       <e-column field='personageDetailId'  foreignKeyValue='name'  foreignKeyField ='personageDetailId' [dataSource]='userData' headerText='Product Owner' textAlign='Left' width=90></e-column> 
            <e-column headerText='Manage Records' width='160' [commands]='commands'></e-column> 
        </e-columns> 
    </ejs-grid> 
[app.component.ts] 
 this.aProducts = [ 
        { 
          name: "Imperva", 
          ownerPersonageDetailId: 5, 
          personageDetailId: 5, 
          syndicateDetailId: 7, 
          syndicateProductId: 1 
        } 
      ]; 
      this.userData = [ 
        { 
          name: "Test Test", 
          personageDetailId: 5 
        } 
      ] 
 
 
 
For your reference, we shared Help Documentation to know details about the ForeignKey Column feature as seen below 
 
 
Please get back to us, if you need further assistance. 
 
Regards, 
Balaji Sekar 


Loader.
Up arrow icon