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.
Unfortunately, activation email could not send to your email. Please try again.

Change Template Values based on selected value in dropdown column

Thread ID:

Created:

Updated:

Platform:

Replies:

132903 Sep 27,2017 05:53 PM Sep 28,2017 08:31 AM ASP.NET Web Forms 1
loading
Tags: Grid
Ahmed Sherien
Asked On September 27, 2017 05:53 PM

I've got a dropdown column with a display template:

<ej:Column Field="FactoryID" HeaderText="Factory" TextAlign="Center" Visible="true" AllowEditing="true"
           Template="<span class='label' style='min-width:70px;font-size:12px;cursor:pointer;color:white;background-color:{{:FactoryColor}} !important'>{{:FactoryName}}</span>"
           EditType="Dropdown" ForeignKeyField="FactoryID" ForeignKeyValue="FactoryName" />
I want the {{:FactoryName}} and {{:FactoryColor}} to be changed based on selected value not row value

Mani Sankar Durai [Syncfusion]
Replied On September 28, 2017 08:31 AM

Hi Ahmed, 

Thanks for contacting Syncfusion support.  

We have analyzed your query and we found that you want to change the background color for the dropdown value based on selected data from dropdown and bind data for the foreign key column. Since {{:FactoryName}} and {{:FactoryColor}} is a field from the foreign key column so the data will not bound on template. But based on your requirement we can achieve it using templateRefresh property instead of binding it in direct template property. 

Refer the code example 
   <ej:Grid ID="FlatGrid" runat='server' AllowPaging="true"> 
                 ... 
        <Columns> 
... 
            <ej:Column Field="EmployeeID" HeaderText="Employee ID" TextAlign="Center" Visible="true" AllowEditing="true" 
           Template="<span class='label' style='min-width:70px;font-size:12px;cursor:pointer;color:white;'></span>" 
           EditType="Dropdown" ForeignKeyField="EmployeeID" ForeignKeyValue="FirstName" /> 
... 
        </Columns> 
        <ClientSideEvents TemplateRefresh="refresh"/> 
       </ej:Grid> 
    <script> 
        function refresh(args) { 
            var data = ej.DataManager(this.model.columns[2].dataSource).executeLocal(ej.Query().where("EmployeeID", "equal", parseInt(args.rowData.EmployeeID), true));   //data for the corresponding column will be filtered using where query from DataManager 
 
                 $(args.cell).find("span").css("background-color", data[0].Color);  
//set the background color for the template column 
 
                 $(args.cell).find("span").text(data[0].FirstName);  //set the value for the template 
        } 
    </script> 

We have also prepared a sample that can be available from the below link. 

Refer the documentation link. 

Please let us know if you need further assistance. 

Regards, 
Manisankar Durai. 



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.

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.

;