Search results

Scrolling

The scrollbar will be displayed in the grid when content exceeds the element Width or Height. The vertical and horizontal scrollbars will be displayed based on the following criteria:

  • The vertical scrollbar appears when the total height of rows present in the grid exceeds its element height.
  • The horizontal scrollbar appears when the sum of columns width exceeds the grid element width.
  • The Height and Width are used to set the grid height and width, respectively.

The default value for Height and Width is auto.

Set width and height

To specify the Width and Height of the scroller in the pixel, set the pixel value to a number.

tagHelper
width-height.cs
<ejs-grid id="Grid" dataSource="ViewBag.datasource"  height="315" width="400" > 
    <e-grid-columns>
        <e-grid-column field="OrderID" headerText="Order ID" textAlign="Right" width="120"></e-grid-column>
        <e-grid-column field="CustomerID" headerText="Customer ID" width="150"></e-grid-column>
        <e-grid-column field="EmployeeID" headerText="Employee ID" textAlign="Right" width="120"></e-grid-column>
        <e-grid-column field="ShipCity" headerText="Ship City" width="150"></e-grid-column>
        <e-grid-column field="ShipCountry" headerText="Ship Country" width="150"></e-grid-column>
        <e-grid-column field="ShipName" headerText="Ship Name" width="150"></e-grid-column>
    </e-grid-columns>
</ejs-grid>
public IActionResult Index()
        {
            var orders= OrderDetails.GetAllRecords();
            ViewBag.datasource = orders;            
            return View();
        }

Responsive with parent container

Specify the Width and Height as 100% to make the grid element fill its parent container. Setting the Height to 100% requires the grid parent element to have explicit height.

tagHelper
responsive-parent.cs
<ejs-grid id="Grid" dataSource="ViewBag.datasource"  height="100%"  > 
    <e-grid-columns>
        <e-grid-column field="OrderID" headerText="Order ID" textAlign="Right" width="120"></e-grid-column>
        <e-grid-column field="CustomerID" headerText="Customer ID" width="150"></e-grid-column>
        <e-grid-column field="EmployeeID" headerText="Employee ID" textAlign="Right" width="120"></e-grid-column>
        <e-grid-column field="ShipCity" headerText="Ship City" width="150"></e-grid-column>
        <e-grid-column field="ShipCountry" headerText="Ship Country" width="150"></e-grid-column>
        <e-grid-column field="ShipName" headerText="Ship Name" width="150"></e-grid-column>
    </e-grid-columns>
</ejs-grid>
public IActionResult Index()
        {
            var orders=OrderDetails.GetAllRecords();
            ViewBag.datasource = orders;            
            return View();
        }

Scroll to selected row

You can scroll the grid content to the selected row position by using the RowSelected event.

tagHelper
scroll-selected-row.cs
<ej-numerictextbox id="numeric" width="200" min="0" showSpinButton="false" placeholder="Enter index to select a row" change="onChange" ></ej-numerictextbox>
<ejs-grid id="Grid" dataSource="ViewBag.datasource" rowSelected="rowSelected" height="270" width="100%" > 
    <e-grid-columns>
        <e-grid-column field="OrderID" headerText="Order ID" textAlign="Right" width="120"></e-grid-column>
        <e-grid-column field="CustomerID" headerText="Customer ID" width="140"></e-grid-column>
        <e-grid-column field="Freight" headerText="Freight" textAlign="Right" format="C2" width="120"></e-grid-column>
        <e-grid-column field="OrderDate" headerText="Order Date" textAlign="Right" format="yMd" width="140"></e-grid-column>
    </e-grid-columns>
</ejs-grid>

<script>


function onChange(args) { 
            var gridObj = document.getElementById("Grid").ej2_instances[0];
            gridObj.selectRow(parseInt(this.getText(), 10));
        }

function rowSelected(args) {
            var rowHeight = this.getRows()[this.getSelectedRowIndexes()[0]].scrollHeight;
            this.getContent().children[0].scrollTop = rowHeight * this.getSelectedRowIndexes()[0];
        }

</script>
public IActionResult Index()
        {
            var orders=OrderDetails.GetAllRecords();
            ViewBag.datasource = orders;            
            return View();
        }

Frozen rows and columns

Frozen rows and columns provides an option to make rows and columns always visible in the top and left side of the grid while scrolling.

In this demo, the FrozenColumns is set as ‘2’ and the FrozenRows is set as ‘3’. Hence, the left two columns and top three rows are frozen.

tagHelper
freeze-row-column.cs
<ejs-grid id="Grid" dataSource="ViewBag.datasource" height="315" allowSelection="false" enableHover="false" frozenColumns="2" frozenRows="3" width="100%" > 
    <e-grid-columns>
        <e-grid-column field="OrderID" headerText="Order ID" textAlign="Right" width="120" ></e-grid-column>
        <e-grid-column field="CustomerID" headerText="Customer Name" width="150"></e-grid-column>
        <e-grid-column field="EmployeeID" headerText=" Employee ID" textAlign="Right"  width="120"></e-grid-column>
        <e-grid-column field="ShipName" headerText="Ship Name" width="150"></e-grid-column>        
        <e-grid-column field="ShipName" headerText="Ship Name" width="150"></e-grid-column>
        <e-grid-column field="ShipAddress" headerText="Ship Name" width="150"></e-grid-column>
        <e-grid-column field="ShipCity" headerText="Ship City" width="150"></e-grid-column>
        <e-grid-column field="ShipCountry" headerText="Ship Country" width="150"></e-grid-column>
        <e-grid-column field="ShipRegion" headerText="Ship Region" width="150"></e-grid-column>
        <e-grid-column field="ShipPostalCode" headerText="Ship Postal Code" width="150"></e-grid-column>
        <e-grid-column field="Freight" headerText="Freight" textAlign="Right" format="C2" width="120"></e-grid-column>
    </e-grid-columns>
</ejs-grid>
public IActionResult Index()
        {
            if (orders.Count() == 0)
                DataSource();
            ViewBag.datasource = orders;            
            return View();
        }

        public void DataSource()
        {
            int code = 10000;
            for (int i = 1; i < 10; i++)
            {
                orders.Add(new OrderDetails(code + 1, "ALFKI", i + 0, 2.3 * i, false, new DateTime(1991, 05, 15), "Berlin", "Simons bistro", "Denmark", new DateTime(1996, 7, 16), "Kirchgasse 6"));
                orders.Add(new OrderDetails(code + 2, "ANATR", i + 2, 3.3 * i, true, new DateTime(1990, 04, 04), "Madrid", "Queen Cozinha", "Brazil", new DateTime(1996, 9, 11), "Avda. Azteca 123"));
                orders.Add(new OrderDetails(code + 3, "ANTON", i + 1, 4.3 * i, true, new DateTime(1957, 11, 30), "Cholchester", "Frankenversand", "Germany", new DateTime(1996, 10, 7), "Carrera 52 con Ave. Bolívar #65-98 Llano Largo"));
                orders.Add(new OrderDetails(code + 4, "BLONP", i + 3, 5.3 * i, false, new DateTime(1930, 10, 22), "Marseille", "Ernst Handel", "Austria", new DateTime(1996, 12, 30), "Magazinweg 7"));
                orders.Add(new OrderDetails(code + 5, "BOLID", i + 4, 6.3 * i, true, new DateTime(1953, 02, 18), "Tsawassen", "Hanari Carnes", "Switzerland", new DateTime(1997, 12, 3), "1029 - 12th Ave. S."));
                code += 5;
            }
        }

Freeze particular columns

To freeze particular column in the grid, the IsFrozen property can be used.

In this demo, the columns with field name OrderID and EmployeeID is frozen using the IsFrozen property.

tagHelper
freeze-column.cs
<ejs-grid id="Grid" dataSource="ViewBag.datasource" height="315" allowSelection="false" enableHover="false" frozenColumns="2" frozenRows="3" width="100%" > 
    <e-grid-columns>
        <e-grid-column field="OrderID" headerText="Order ID" textAlign="Right" width="120" isFrozen="true"></e-grid-column>
        <e-grid-column field="CustomerID" headerText="Customer Name" width="150"></e-grid-column>
        <e-grid-column field="EmployeeID" headerText=" Employee ID" textAlign="Right" isFrozen="true" width="120"></e-grid-column>
        <e-grid-column field="ShipName" headerText="Ship Name" width="150"></e-grid-column>        
        <e-grid-column field="ShipName" headerText="Ship Name" width="150"></e-grid-column>
        <e-grid-column field="ShipAddress" headerText="Ship Name" width="150"></e-grid-column>
        <e-grid-column field="ShipCity" headerText="Ship City" width="150"></e-grid-column>
        <e-grid-column field="ShipCountry" headerText="Ship Country" width="150"></e-grid-column>
        <e-grid-column field="ShipRegion" headerText="Ship Region" width="150"></e-grid-column>
        <e-grid-column field="ShipPostalCode" headerText="Ship Postal Code" width="150"></e-grid-column>
        <e-grid-column field="Freight" headerText="Freight" textAlign="Right" format="C2" width="120"></e-grid-column>
    </e-grid-columns>
</ejs-grid>
public IActionResult Index()
        {
            var orders =OrderDetails.GetAllRecords();
            ViewBag.datasource = orders;            
            return View();
        }
  • The AllowScrolling must be true while giving frozen rows and columns.
  • Frozen rows and columns should not be set outside the grid view port.

Limitations

The following features are not supported in frozen rows and columns:

  • Grouping
  • Row Template
  • Detail Template
  • Hierarchy Grid