We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Can not set selected value in dropdownlist in Grid

Thread ID:

Created:

Updated:

Platform:

Replies:

147583 Sep 17,2019 09:15 AM UTC Sep 19,2019 06:04 AM UTC React - EJ 2 3
loading
Tags: Grid
Ryosei Yawata
Asked On September 17, 2019 09:15 AM UTC

Hi,

based on the article, I can add dropdownlist to grid.
However, nothing in the dropwdownlist in a dialog  is selected(just show placeholder), when opening dialog to edit.
Could you tell me how to select value based on selected row data value?




    const typeColl = [
      { select_name: 'text', input_type: 'text' },
      { select_name: 'select', input_type: 'select' },
      { select_name: 'date', input_type: 'date' },
    ];

    const typeParams = {
      create: () => {
        this.stateElem = document.createElement('input');
        return this.stateElem;
      },
      destroy: () => {
        this.stateObj.destroy();
      },
      read: () => {
        return this.stateObj.value;
      },
      write: (args) => {
        let dataIndex = typeColl.findIndex(e => e.input_type === args.rowData[args.column.filed]);

        this.stateObj = new DropDownList({
          dataSource: new DataManager(typeColl),
          enabled: true,
          fields: { value: 'input_type', text: 'select_name' },
          floatLabelType: 'Never',
          placeholder: 'Select a type',
          index: dataIndex
        });
        this.stateObj.appendTo(this.stateElem);
      }
    };


        <GridComponent id="personConfig" rowDropSettings={{ targetID: 'personConfig' }} rowDrop={this.arrangeConfig} dataSource={this.state.personExtra}  allowRowDragAndDrop={true}  editSettings={{ allowEditing: true, allowAdding: true, allowDeleting: true, mode: "Dialog", showDeleteConfirmDialog: true, newRowPosition: 'Bottom' }}
          toolbar={toolbarOptions} toolbarClick={this.toolbarClickHandler}
          height="500" width="900" selectionSettings={{ type: 'Single' }}
          beforeDataBound={this.createEditData}
          rowDeselected={this.rowDeselected}
          rowSelected={this.rowSelected}
        >
          <Inject services={[RowDD, Selection, Edit, Toolbar]} />
          <ColumnsDirective>
            <ColumnDirective field='order' isPrimaryKey={true} headerText='No' defaultValue={extraDefaultValue} allowEditing={false} width="50"></ColumnDirective>
            <ColumnDirective field='extra_name'  width="100"></ColumnDirective>
            <ColumnDirective field='input_type'  width="50" editType="dropdownedit" edit={typeParams} validationRules={{ required: true }}></ColumnDirective>
          </ColumnsDirective>
        </GridComponent>

Pavithra Subramaniyam [Syncfusion]
Replied On September 18, 2019 05:53 AM UTC

Hi Ryosei, 
 
Thanks for contacting Syncfusion support. 
 
Query: Could you tell me how to select value based on selected row data value?. 
 
You can set the row data value for the edit dropdown by using the “value” property of dropdownlist. Please refer to the below code example, documentation link and sample link for more information. 
 
[index.js] 
this.typeParams = { 
      create: () => { 
        this.stateElem = document.createElement('input'); 
        return this.stateElem; 
      }, 
      destroy: () => { 
        this.stateObj.destroy(); 
      }, 
      read: () => { 
        return this.stateObj.value; 
      }, 
      write: (args) => { 
        let dataIndex = this.typeColl.findIndex(e => e.input_type === args.rowData[args.column.filed]); 
 
        this.stateObj = new DropDownList({ 
          dataSource: new DataManager(this.typeColl), 
          enabled: true, 
          value: args.rowData[args.column.field], 
          fields: { value: 'input_type', text: 'select_name' }, 
          floatLabelType: 'Never', 
          placeholder: 'Select a type', 
          index: dataIndex 
        }); 
        this.stateObj.appendTo(this.stateElem); 
      } 
    }; 
 
 
 
 
Please g et back to us if you need any further assistance on this. 
 
Regards, 
Pavithra S. 


Ryosei Yawata
Replied On September 18, 2019 07:27 AM UTC

Hi Pavithra,

Thanks, a lot.It works now.

Ryosei

Pavithra Subramaniyam [Syncfusion]
Replied On September 19, 2019 06:04 AM UTC

Hi Ryosei, 
 
Thanks for your update. 

We are happy to hear that the provided solution is working. 

Please contact us if you need any further assistance. As always, we will be happy to assist you.  
  
Regards, 
Pavithra S. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon