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

Change Template Values based on selected value in dropdown column

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

1 Reply

MS Mani Sankar Durai Syncfusion Team September 28, 2017 12:31 PM UTC

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. 



Loader.
Live Chat Icon For mobile
Up arrow icon