Search results

Row

The row represents record details fetched from data source.

Customize rows

You can customize the appearance of a row by using the rowDataBound event. The rowDataBound event triggers for every row. In the event handler, you can get the args which contains details of the row.

tagHelper
CustomizeRows.cs
<ejs-treegrid id="TreeGrid" dataSource="@ViewBag.datasource" height="275" enableHover="false" rowDataBound="rowDataBound" childMapping="Children" treeColumnIndex="1">
    <e-treegrid-columns>
        <e-treegrid-column field="TaskId" headerText="Task ID" textAlign="Right" width="90"></e-treegrid-column>
        <e-treegrid-column field="TaskName" headerText="Task Name" width="180"></e-treegrid-column>
        <e-treegrid-column field="StartDate" headerText="Start Date" textAlign="Right"
            format="yMd" width="90"></e-treegrid-column>
        <e-treegrid-column field="Duration" headerText="Duration" textAlign="Right" width="80"></e-treegrid-column>
    </e-treegrid-columns>
</ejs-treegrid>



<script>
    function rowDataBound(args) {
        if (args.data['Duration'] > 5) {
            args.row.style.background = '#336c12';
        } else if (args.data['Duration'] < 5) {
            args.row.style.background = '#7b2b1d';
        }
    }
</script>
public IActionResult Index()
{
    var tree = TreeData.GetDefaultData();
    ViewBag.datasource = tree;
    return View();
}

Styling alternate rows

You can change the treegrid’s alternative rows’ background color by overriding the .e-altrow class.

.e-treegrid .e-altrow {
    background-color: #ffd800;
}

Please refer to the following example.

tagHelper
alternateRows.cs
<ejs-treegrid id="TreeGrid" dataSource="@ViewBag.datasource" height="275" enableHover="false" childMapping="Children" treeColumnIndex="1">
    <e-treegrid-columns>
        <e-treegrid-column field="TaskId" headerText="Task ID" textAlign="Right" width="90"></e-treegrid-column>
        <e-treegrid-column field="TaskName" headerText="Task Name" width="180"></e-treegrid-column>
        <e-treegrid-column field="StartDate" headerText=" Start Date" textAlign="Right"
            format="yMd" width="90"></e-treegrid-column>
        <e-treegrid-column field="Duration" headerText="Duration" textAlign="Right" width="80"></e-treegrid-column>
    </e-treegrid-columns>
</ejs-treegrid>

<style>
    .e-treegrid .e-altrow {
        background-color: #ffd800;
    }
</style>
public IActionResult Index()
{
    var tree = TreeData.GetDefaultData();
    ViewBag.datasource = tree;
    return View();
}

Row height

You can customize the row height of treegrid rows through the rowHeight property. The rowHeight property is used to change the row height of entire treegrid rows.

In the below example, the rowHeight is set as 60px.

tagHelper
rowHeight.cs
<ejs-treegrid id="TreeGrid" dataSource="@ViewBag.datasource" rowHeight="60" height="275" enableHover="false" childMapping="Children" treeColumnIndex="1">
    <e-treegrid-columns>
        <e-treegrid-column field="TaskId" headerText="Task ID" textAlign="Right" width="90"></e-treegrid-column>
        <e-treegrid-column field="TaskName" headerText="Task Name" width="180"></e-treegrid-column>
        <e-treegrid-column field="StartDate" headerText=" Start Date" textAlign="Right" format="yMd" width="90"></e-treegrid-column>
        <e-treegrid-column field="Duration" headerText="Duration" textAlign="Right" width="80"></e-treegrid-column>
    </e-treegrid-columns>
</ejs-treegrid>
public IActionResult Index()
{
    var tree = TreeData.GetDefaultData();
    ViewBag.datasource = tree;
    return View();
}

Customize row height for particular row

Grid row height for particular row can be customized using the rowDataBound event by setting the rowHeight in arguments for each row based on the requirement.

In the below example, the row height for the row with Task ID as ‘3’ is set as ‘90px’ using the rowDataBound event.

tagHelper
customizeRowHeight.cs
<ejs-treegrid id="TreeGrid" dataSource="@ViewBag.datasource" rowDataBound="rowDataBound" height="275" enableHover="false" childMapping="Children" treeColumnIndex="1">
    <e-treegrid-columns>
        <e-treegrid-column field="TaskId" headerText="Task ID" textAlign="Right" width="90"></e-treegrid-column>
        <e-treegrid-column field="TaskName" headerText="Task Name" width="180"></e-treegrid-column>
        <e-treegrid-column field="StartDate" headerText=" Start Date" textAlign="Right" 
                format="yMd" width="90"></e-treegrid-column>
        <e-treegrid-column field="Duration" headerText="Duration" textAlign="Right" width="80"></e-treegrid-column>
    </e-treegrid-columns>
</ejs-treegrid>

<script>
    function rowDataBound(args) {
        if(args.data.TaskId === 3){
            args.rowHeight = 90;
        }
    }
</script>
public IActionResult Index()
{
    var tree = TreeData.GetDefaultData();
    ViewBag.datasource = tree;
    return View();
}

Row template

The rowTemplate has an option to customise the look and behavior of the treegrid rows. The rowTemplate property accepts either the template string or HTML element ID.

tagHelper
row-template.cs
<ejs-treegrid id="TreeGrid" rowHeight="83" dataSource="ViewBag.datasource" height="250" childMapping="Children" treeColumnIndex="0" rowTemplate="#rowtemplate">
    <e-treegrid-columns>
        <e-treegrid-column field="EmpID" headerText="Employee ID" width="150"></e-treegrid-column>
        <e-treegrid-column field="Name" headerText="Employee Name" width="150"></e-treegrid-column>
        <e-treegrid-column field="Address" headerText="Employee Details" width="300"></e-treegrid-column>
    </e-treegrid-columns>
</ejs-treegrid>

    <script id="rowtemplate" type="text/x-template">
        <tr>
            <td class="border" style='padding-left:18px;'>
                <div>${EmpID}</div>
            </td>
            <td class="border" style='padding: 10px 0px 0px 20px;'>
                <div style="font-size:14px;">
                    ${Name}
                    <p style="font-size:9px;">${Designation}</p>
                </div>
            </td>
            <td class="border">
                <div>
                    <div style="position:relative;display:inline-block;">
                        <img src="/images/TreeGrid/${FullName}.png" alt="${FullName}" />
                    </div>
                    <div style="display:inline-block;">
                        <div style="padding:5px;">${Address}</div>
                        <div style="padding:5px;">${Country}</div>
                        <div style="padding:5px;font-size:12px;">${Contact}</div>
                    </div>
                </div>
            </td>
        </tr>
    </script>
    <style type="text/css">
        .border {
            border-color: #e0e0e0;
            border: 1px solid #e0e0e0;
            border-width: 1px 0 0 0;
        }

        img {
            width: 60px;
            height: 60px;
            vertical-align: baseline;
            border-radius: 50px;
            margin-left: 20px;
            background-repeat: no-repeat;
        }
    </style>
public IActionResult RowTemplate()
        {
            ViewBag.datasource = TreeData.GetTemplateData();
            return View();
        }

The rowTemplate property accepts only the TR element.

Row template with formatting

If the rowTemplate is used, the value cannot be formatted inside the template using the columns.format property. In that case, a function should be defined globally to format the value and invoke it inside the template.

tagHelper
rowtemplate-formatting.cs
<ejs-treegrid id="TreeGrid" rowHeight="83" dataSource="ViewBag.datasource" height="250" childMapping="Children" treeColumnIndex="0" rowTemplate="#rowtemplate">
            <e-treegrid-columns>
                <e-treegrid-column field="EmpID" headerText="Employee ID" width="150"></e-treegrid-column>
                <e-treegrid-column field="Address" headerText="Employee Details" width="350"></e-treegrid-column>
                <e-treegrid-column field="DOB" headerText="DOB" width="150"></e-treegrid-column>
            </e-treegrid-columns>
        </ejs-treegrid>

    <script id="rowtemplate" type="text/x-template">
        <tr>
            <td class="border" style='padding-left:18px;'>
                <div>${EmpID}</div>
            </td>
            <td class="border">
                <div>
                    <div style="position:relative;display:inline-block;">
                        <img src="/images/TreeGrid/${FullName}.png" alt="${FullName}" />
                    </div>
                    <div style="display:inline-block;">
                        <div style="padding:5px;">${Address}</div>
                        <div style="padding:5px;">${Country}</div>
                        <div style="padding:5px;font-size:12px;">${Contact}</div>
                    </div>
                </div>
            </td>
            <td class="border" style='padding-left: 20px;'>
                <div>${DOB.toLocaleDateString()}</div>
            </td>
        </tr>
    </script>
    <style type="text/css">
        .border {
            border-color: #e0e0e0;
            border: 1px solid #e0e0e0;
            border-width: 1px 0 0 0;
        }

        img {
            width: 60px;
            height: 60px;
            vertical-align: baseline;
            border-radius: 50px;
            margin-left: 20px;
            background-repeat: no-repeat;
        }
    </style>
public IActionResult RowTemplate()
        {
            ViewBag.datasource = TreeData.GetTemplateData();
            return View();
        }

Limitations

Row template feature is not compatible with all the features which are available in treegrid and it has limited features support. Here we have listed out the features which are compatible with row template feature.

  • Filtering
  • Paging
  • Sorting
  • Scrolling
  • Searching
  • Rtl
  • Context Menu
  • State Persistence