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

Conditional column with a button in a grid

Thread ID:





142939 Feb 26,2019 12:14 PM UTC Feb 27,2019 08:50 AM UTC ASP.NET Core 1
Tags: Grid
Asked On February 26, 2019 12:14 PM UTC

I'm trying to include a column with conditional in my Grid :

                dataSource: ej.DataManager({
    columns: [
 { headerText: 'Detail', template: '<a class="btn btn-info" rel='nofollow' rel='nofollow' href="/ServicesOrder/Detail/{{:ServicesOrderId}}">Detail</a>' },
{ headerText: 'Finish', template: '<a class="btn btn-sucess" >Finish</a>'
{ headerText: 'In progress', template: '<a class="btn btn-danger" >In progress</a>'

Indeed, I have a variable Rest (rest of payment) in my table ServicesOrder, my goal is to display one of the two columns :

if (rest==0) 
Only display --> 
{ headerText: 'Finish', template: '<a class="btn btn-sucess" >Finish</a>'
Only display --> 
{headerText: 'In progress', template: '<a class="btn btn-danger" >In progress</a>'

Vignesh Natarajan [Syncfusion]
Replied On February 27, 2019 08:50 AM UTC

Hi Marso, 
Thanks for contacting Syncfusion support.  
Query: “Indeed, I have a variable Rest (rest of payment) in my table ServicesOrder, my goal is to display one of the two butons (finish or In progress) :” 
From your query, we understand that you need to render the anyone of the two buttons based on the value from the dataSource. We have achieved your requirement using columnTemplate feature and JS render if else condition. Refer the below code example 
  <script type="text/x-jsrender" id="columnTemplate"> 
        {{if Verified}} 
  <a class="btn btn-sucess">Finish</a> 
 <a class="btn btn-danger">In progress</a> 
    <div id="Grid"></div> 
    <script type="text/javascript"> 
        $(function () { 
                // the datasource "window.employeeView" is referred from jsondata.min.js 
                dataSource: window.gridData, 
                allowPaging: true, 
                pageSettings: { pageSize: 4 }, 
                columns: [ 
                    { field: "OrderID", headerText: "Order ID", isPrimaryKey: true, textAlign: ej.TextAlign.Right, width: 90 }, 
                    { field: "CustomerID", headerText: "Customer ID", width: 150 }, 
                    { field: "EmployeeID", headerText: "Employee ID", textAlign: ej.TextAlign.Right, width: 100 }, 
                    { field: "OrderDate", headerText: "Order Date", textAlign: ej.TextAlign.Right, width: 100, format: "{0:MM/dd/yyyy}" }, 
                    { field: "Freight", headerText: "Freight", textAlign: ej.TextAlign.Right, format: "{0:C}" }, 
                    { field: "Verified", headerText: "Verified", width: 100 }, 
                    { headerText: "Employee Image", template: "#columnTemplate", textAlign: "center", width: 110 }, 
For your convenience we have prepared a JS playground sample which can be referred below  
Refer the help documentation for your reference 
Please get back to us if you have further queries. 
Vignesh Natarajan 


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