Search results

Freeze Panes in ASP.NET MVC Spreadsheet control

28 Oct 2021 / 3 minutes to read

Freeze Panes helps you to keep particular rows or columns visible when scrolling the sheet content in the spreadsheet. You can specify the number of frozen rows and columns using the frozenRows and frozenColumns properties inside the Sheet property.

Apply freezepanes on UI

User Interface:

In the active spreadsheet, click the cell where you want to create freeze panes. Freeze panes can be done in any of the following ways:

  • Select the View tab in the Ribbon toolbar and choose the Freeze Panes item.
  • Use the freezePanes method programmatically.

FrozenRows

It allows you to keep a certain number of rows visible while scrolling vertically through the rest of the worksheet.

User Interface:

In the active spreadsheet, select the cell where you want to create frozen rows. Frozen rows can be done in any one of the following ways:

  • Select the View tab in the Ribbon toolbar and choose the Freeze Rows item.
  • You can specify the number of frozen rows using the frozenRows property inside the Sheet property.

FrozenColumns

It allows you to keep a certain number of columns visible while scrolling horizontally through the rest of the worksheet.

User Interface:

In the active spreadsheet, select the cell where you want to create frozen columns. Frozen columns can be done in any one of the following ways:

  • Select the View tab in the Ribbon toolbar and choose the Freeze Columns item.
  • You can specify the number of frozen columns using the frozenColumns property inside the Sheet property.

In this demo, the frozenColumns is set as ‘2’, and the frozenRows is set as ‘2’. Hence, the two columns on the left and the top two rows are frozen.

razor
Copied to clipboard
@Html.EJS().Spreadsheet("spreadsheet").Created("createdHandler").Sheets(sheet =>
   {
       sheet.Name("Gross Salary").FrozenRows(2).FrozenColumns(2).SelectedRange("C1").Ranges(ranges =>
       {
           ranges.DataSource((IEnumerable<object>)ViewBag.DefaultData).StartCell("A2").Add();
       }).Rows(row =>{
           row.Cells(cell => {
               cell.Index(1).Value("Period").Style(new SpreadsheetCellStyle { FontSize = "12pt", FontWeight = FontWeight.Bold, TextAlign = TextAlign.Center, VerticalAlign = VerticalAlign.Middle }).Add();
               cell.Index(3).Value("Total Gross Salary").Style(new SpreadsheetCellStyle { FontSize = "12pt", FontWeight = FontWeight.Bold, TextAlign = TextAlign.Center, VerticalAlign = VerticalAlign.Middle }).Add();
           }).Add();
           row.Cells(cell =>
           {
               cell.Index(2).Value("Basic Salary").Add();
               cell.Value("Revised Basic Salary").Add();
               cell.Value("DA").Add();
               cell.Value("Revised DA").Add();
               cell.Value("HRA").Add();
               cell.Value("Revised HRA").Add();
               cell.Value("Conveyance Allowance").Add();
               cell.Value("Revised Conveyance Allowance").Add();
               cell.Value("Medical Expenses").Add();
               cell.Value("Revised Medical Expenses").Add();
               cell.Value("Special Allowance").Add();
               cell.Value("Revised Spcial Allowance").Add();
               cell.Value("Total Gross Salary").Add();
               cell.Value("Revised Total Gross Salary").Add();
           }).Add();
           row.Index(26).Cells(cell => {
               cell.Index(13).Value("Total Amount").Style(new SpreadsheetCellStyle { FontSize = "12pt", FontWeight = FontWeight.Bold, TextAlign = TextAlign.Center, VerticalAlign = VerticalAlign.Middle }).Add();
               cell.Formula("=SUM(O4:O26)").Style(new SpreadsheetCellStyle { FontSize = "12pt", FontWeight = FontWeight.Bold, TextAlign = TextAlign.Center, VerticalAlign = VerticalAlign.Middle }).Add();
               cell.Formula("=SUM(P4:P26)").Style(new SpreadsheetCellStyle { FontSize = "12pt", FontWeight = FontWeight.Bold, TextAlign = TextAlign.Center, VerticalAlign = VerticalAlign.Middle }).Add();
           }).Add();
       }).Columns(column => {
           column.Width(80).Add();
           column.Width(80).Add();
           column.Width(100).Add();
           column.Width(100).Add();
           column.Width(100).Add();
           column.Width(100).Add();
           column.Width(100).Add();
           column.Width(100).Add();
           column.Width(100).Add();
           column.Width(100).Add();
           column.Width(100).Add();
           column.Width(100).Add();
           column.Width(80).Add();
           column.Width(100).Add();
           column.Width(100).Add();
           column.Width(100).Add();
       }).Add();
   }).Render()

<script>
    function createdHandler() {
        this.wrap("C2:P2");
        this.merge('A1:B1');
        this.merge('C1:P1');
        this.cellFormat({ backgroundColor: '#4e4ee6', color: '#FFFFF4', fontSize: '12pt', fontWeight: 'bold', textAlign: 'center', verticalAlign: 'middle' }, 'A1:P2');
        this.cellFormat({ backgroundColor: '#4e4ee6', color: '#FFFFF4' }, 'A3:B26');
        this.numberFormat('$#,##0.00', 'C2:P26');
        this.numberFormat('$#,##0.00', 'O27:P27');
    }
</script>

Limitations

Freeze Panes feature is not compatible with all the features which are available in the spreadsheet and it has limited features support. Here, we have listed out the features which are not compatible with Freeze Panes feature.

  • Show/hide rows and columns with freeze panes.
  • Filtering support with freeze panes.
  • Merging the cells between freeze and unfreeze area.

Note

You can refer to our ASP.NET MVC Spreadsheet feature tour page for its groundbreaking feature representations. You can also explore our ASP.NET MVC Spreadsheet example to knows how to present and manipulate data.

See Also