Search results

Cell

Displaying the HTML content

The HTML tags can be displayed in the Grid header and content by enabling the disableHtmlEncode property of e-grid-column tag helper.

tagHelper
html.cs
<ejs-grid id="Grid" dataSource="@ViewBag.DataSource" height="135" allowPaging="true">
    <e-grid-columns>
        <e-grid-column field="OrderID" headerText="<span> Order ID </span>"  disableHtmlEncode="true" textAlign="Right" width="140"></e-grid-column>
        <e-grid-column field="CustomerID" headerText="<span> Customer ID </span>" disableHtmlEncode="false" width="120"></e-grid-column>                
        <e-grid-column field="OrderDate" headerText="Order Date" format='yMd' textAlign="Right" width="100"></e-grid-column>
        <e-grid-column field="ShipCity" headerText="Ship City" width="100"></e-grid-column>
    </e-grid-columns>
</ejs-grid>
public IActionResult Index()
{
    var Order = OrderDetails.GetAllRecords();
    ViewBag.DataSource = Order;
    return View();
}

Customize cell styles

The appearance of cells can be customized by using the queryCellInfo event.

The queryCellInfo event triggers for every cell.

tagHelper
customize.cs
<ejs-grid id="Grid" dataSource="@ViewBag.DataSource" queryCellInfo="customiseCell">
    <e-grid-columns>
        <e-grid-column field="OrderID" headerText="Order ID"  textAlign="Right" width="100"></e-grid-column>
        <e-grid-column field="CustomerID" headerText="Customer ID"  width="120"></e-grid-column>                
        <e-grid-column field="OrderDate" headerText="Order Date" format='yMd'  width="100"></e-grid-column>
        <e-grid-column field="Freight" headerText="Freight" textAlign="Right" format="C2" width="100"></e-grid-column>
        <e-grid-column field="ShipCity" headerText="Ship City" width="100"></e-grid-column>
    </e-grid-columns>
</ejs-grid>

<script>
function customiseCell(args) {
    if(args.column.field === 'Freight') {
        if (args.data['Freight'] < 30){
            args.cell.classList.add('below-30');
        } else if(args.data['Freight'] < 80 ) {
            args.cell.classList.add('below-80');
        } else {
            args.cell.classList.add('above-80');
        }
    }
}
</script>
public IActionResult Index()
{
    var Order = OrderDetails.GetAllRecords();
    ViewBag.DataSource = Order;
    return View();
}

Auto wrap

The auto wrap allows the cell content of the grid to wrap to the next line when it exceeds the boundary of the cell width. The Cell Content wrapping works based on the position of white space between words. To enable auto wrap, set the allowTextWrap property to true. You can configure the auto wrap mode by setting the wrapMode property of e-grid-textwrapsettings tag helper.

There are three types of wrapMode. They are:

  • Both: Both value is set by default. Auto wrap will be enabled for both the content and the header.
  • Header: Auto wrap will be enabled only for the header.
  • Content: Auto wrap will be enabled only for the content.

Note: When a column width is not specified, then auto wrap of columns will be adjusted with respect to the grid’s width.

In the following example, the wrapMode is set to Content.

tagHelper
autowrap.cs
<ejs-grid id="Grid" dataSource="@ViewBag.DataSource" gridLines="Default" height="315" allowTextWrap="true">
    <e-grid-textwrapsettings wrapMode="Content"></e-grid-textwrapsettings>
    <e-grid-columns>
        <e-grid-column field="RoolNo" headerText="Rool No"  textAlign="Right" width="120"></e-grid-column>
        <e-grid-column field="Name" headerText="Name of the inventor"  width="100"></e-grid-column>                
        <e-grid-column field="patentfamilies" headerText="No of patentfamilies"  width="130"></e-grid-column>
        <e-grid-column field="Country" headerText="Country" width="130"></e-grid-column>
        <e-grid-column field="mainfields" headerText="Main fields of Invention" width="150"></e-grid-column>
    </e-grid-columns>
 </ejs-grid>
public IActionResult Index()
{
    var Records = InventorDetails.GetAllRecords();
    ViewBag.DataSource = Records;
    return View();
}

Custom Attributes

You can customize the grid cells by adding a CSS class to the customAttribute property of e-grid-column tag helper.

.e-attr {
    background: #d7f0f4;
}

In the below example, we have customized the cells of OrderID and ShipCity columns.

tagHelper
customStyle.cs
<ejs-grid id="Grid" dataSource="@ViewBag.DataSource">
    <e-grid-columns>
        <e-grid-column field="OrderID" headerText="Order ID" customAttributes=@(new { @class="e-attr" } ) textAlign="Right" width="100"></e-grid-column>
        <e-grid-column field="CustomerID" headerText="Customer ID"  width="120"></e-grid-column>                
        <e-grid-column field="ShipCity" headerText="Ship City" customAttributes=@(new { @class="e-attr" } ) width="100"></e-grid-column>
        <e-grid-column field="OrderDate" headerText="Order Date" format='yMd'  width="100"></e-grid-column>
    </e-grid-columns>
</ejs-grid>

<style>
    .e-attr {
        background: #d7f0f4;
    }
</style>
public IActionResult Index()
{
    var Order = OrderDetails.GetAllRecords();
    ViewBag.DataSource = Order;
    return View();
}

Grid Lines

The GridLines have option to display cell border and it can be defined by the gridLines property.

The available modes of grid lines are:

Modes Actions
Both Displays both the horizontal and vertical grid lines.
None No grid lines are displayed.
Horizontal Displays the horizontal grid lines only.
Vertical Displays the vertical grid lines only.
Default Displays grid lines based on the theme.
tagHelper
gridlines.cs
<ejs-grid id="Grid" dataSource="@ViewBag.DataSource" height="315" gridLines="Both" >            
    <e-grid-columns>
        <e-grid-column field="OrderID" headerText="Order ID" textAlign="Right" width="100"></e-grid-column>
        <e-grid-column field="CustomerID" headerText="Customer ID" width="120"></e-grid-column>               
        <e-grid-column field="ShipCity" headerText="Ship City" width="100"></e-grid-column>
        <e-grid-column field="ShipName" headerText="Ship Name" width="100"></e-grid-column>
    </e-grid-columns>
 </ejs-grid>
public IActionResult Index()
{
    var Order = OrderDetails.GetAllRecords();
    ViewBag.DataSource = Order;
    return View();
}

By default, the grid renders with Default mode.

Clip Mode

The clip mode provides options to display its overflow cell content and it can be defined by the clipMode property of e-grid-column tag helper.

There are three types of ClipMode. They are:

  • Clip: Truncates the cell content when it overflows its area.
  • Ellipsis: Displays ellipsis when the cell content overflows its area.
  • EllipsisWithTooltip: Displays ellipsis when the cell content overflows its area, also it will display the tooltip while hover on ellipsis is applied.
tagHelper
clipmode.cs
<ejs-grid id="Grid" dataSource="@ViewBag.DataSource" height="315" allowPaging="true">
	<e-grid-columns>
		<e-grid-column field="RoolNo" headerText="Rool No" textAlign="Right" width="100"></e-grid-column>
		<e-grid-column field="Name" headerText="Name of the inventor" clipMode="Clip" width="80"></e-grid-column>
		<e-grid-column field="patentfamilies" headerText="No of patentfamilies" clipMode="Ellipsis" width="100"></e-grid-column>
		<e-grid-column field="Country" headerText="Country" width="100"></e-grid-column>
		<e-grid-column field="mainfields" headerText="Main fields of Invention" clipMode="EllipsisWithTooltip" width="100"></e-grid-column>
	</e-grid-columns>
 </ejs-grid>
public IActionResult Index()
{
    var Order = OrderDetails.GetAllRecords();
    ViewBag.DataSource = Order;
    return View();
}

By default, clipMode value is Ellipsis.