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

TypeScript example - custom cell dropdown

Thread ID:

Created:

Updated:

Platform:

Replies:

148238 Oct 10,2019 09:08 PM UTC Oct 15,2019 02:21 PM UTC JavaScript - EJ 2 5
loading
Tags: Grid
Jack
Asked On October 10, 2019 09:08 PM UTC

Hi, 

I read the thread https://www.syncfusion.com/forums/136659/custom-cell-edittemplate. It helps when we create a datagrid that has different edit types in the same column. It also shows how to change the datasource of the dropdown cell edit from a local item list using JavaScript:
var items = [{ text: "ListItem 1", value: "item1" },  
                    { text: "ListItem 2", value: "item2" }, 
                    { text: "ListItem 3", value: "item3" }, 
                    { text: "ListItem 4", value: "item4" }, 
                    { text: "ListItem 5", value: "item5" }];  

Do you have a TypeScript example? I am struggling on a TS implementation.

Thank you

Seeni Sakthi Kumar Seeni Raj [Syncfusion]
Replied On October 11, 2019 10:29 AM UTC

Hi Jack , 
 
As requested , a sample for cell editing dropdown is attached below. Please follow the below steps for more clarifications. In the below sample the dropdown is rendered in the shipcountry column. 
 
 
let itemElem: HTMLElement; 
let itemObj: DropDownList; 
 
let items: { [key: string]: Object }[] = [ 
  { text: "France", value: "item1" },   
  { text: "Germany", value: "item2" },  
  { text: "Brazil", value: "item3" },  
  { text: "Belgium", value: "item4" },  
  { text: "Switzerland", value: "item5" }];   
 
    let grid: Grid = new Grid( 
        { 
         
            dataSource: orderDataSource, 
            editSettings: { allowEditing: true, allowAdding: true, allowDeleting: true, mode: 'Normal' }, 
            allowPaging: true, 
            pageSettings: { pageSize: 6, pageCount: 5 }, 
            toolbar: ['Add', 'Edit', 'Delete', 'Update', 'Cancel'], 
            columns: [ 
                 . . . 
                        . . . 
                { 
                    field: 'ShipCountry', headerText: 'Ship Country',width: 160, edit:{ 
                
                    create: () => { 
                    itemElem = document.createElement('input'); 
                    return itemElem; 
                    }, 
                     
                    read: () => { 
                      return itemObj.text; 
                    }, 
 
                    destroy:() =>{ 
                      itemObj.text; 
                    }, 
 
                    write: (e) => { 
                    var Data = e.rowData.ShipCountry; 
                    itemObj = new DropDownList({ 
                    dataSource: items, 
                    fields : { value:'value' , text :'text'},        
                    text: Data , 
                    floatLabelType: 'Never' 
                    }); 
                     
                  itemObj.appendTo(itemElem); 
                    } 
                 
                }   
              ], 
        }); 
    grid.appendTo('#Grid'); 
 
 
 
Regards, 
Seeni Sakthi Kumar S 


Jack
Replied On October 11, 2019 04:47 PM UTC

Hi Seeni,

Thank you so much for the example. It works.

In my case, I want to use this local dropdown for the ShipCountry column depending on the value from the other column. For example when CustomerID = VINET, we use this local dropdown, otherwise we use the defaultedit as the editType for the ShipCountry column. How to do that?

Thanks
Jack



Seeni Sakthi Kumar Seeni Raj [Syncfusion]
Replied On October 14, 2019 01:05 PM UTC

 
Hi Jack , 
 
We could see you would like to render the dropdown and textbox and make a toggle between them based  on the value of the other columns. We can achieve your requirement using the edit template feature of the Grid. Refer to the following code example. 
 
index.ts 

{
 field: 'ShipCountry', headerText: 'Ship Country',width: 160, edit:{
 
                
                    create: () => { 
                    itemElem = document.createElement('input'); 
                    return itemElem; 
                    },

                    write: (e) => { 
                    if(e.rowData.CustomerID == "VINET"){ 
                    var Data = e.rowData.ShipCountry; 
                    itemObj = new DropDownList({ 
                    dataSource: items, 
                    fields : { value:'value' , text :'text'},        
                    text: Data , 
                    floatLabelType: 'Never' 
                    }); 
                  itemObj.appendTo(itemElem); 
                    } 
                    else{ 
                      var Pole = e.rowData.ShipCountry; 
                      itemElem.value = Pole; 
                    } 
                    } 
                  } 
                }   
              ], 
        }); 
    grid.appendTo('#Grid'); 
  
 
Regards, 
Seeni Sakthi Kumar S 


Jack
Replied On October 14, 2019 11:49 PM UTC

Thank you. That is what I need.

Seeni Sakthi Kumar Seeni Raj [Syncfusion]
Replied On October 15, 2019 02:21 PM UTC

Hi Jack,  
  
Thanks for the update.  
  
We are happy to hear your requirement has been achived and you are good to go. 
  
Regards,  
Seeni Sakthi Kumar 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