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. Image for the cookie policy date
close icon

Can not set selected value in dropdownlist in Grid

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>

3 Replies

PS Pavithra Subramaniyam Syncfusion Team 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. 



RY Ryosei Yawata September 18, 2019 07:27 AM UTC

Hi Pavithra,

Thanks, a lot.It works now.

Ryosei


PS Pavithra Subramaniyam Syncfusion Team 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. 


Loader.
Live Chat Icon For mobile
Up arrow icon