Frozen in Vue Grid component
16 Mar 202312 minutes to read
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.
To use frozen rows and columns support, inject the Freeze
module in the provide
section.
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.
<template>
<div id="app">
<ejs-grid :dataSource='data' height=315 :frozenColumns='2' :frozenRows='3' :allowSelection='false' :enableHover='false' width='600'>
<e-columns>
<e-column field='OrderID' headerText='Order ID' textAlign='Right' width=120></e-column>
<e-column field='CustomerID' headerText='Customer ID' width=150></e-column>
<e-column field='OrderDate' headerText='Order Date' width=130 format='yMd' textAlign='Right' type='date'></e-column>
<e-column field='ShipName' headerText='Ship Name' width=150></e-column>
<e-column field='ShipAddress' headerText='Ship Address' width=170></e-column>
<e-column field='ShipCity' headerText='Ship City' width=150></e-column>
<e-column field='ShipCountry' headerText='Ship Country' width=150></e-column>
<e-column field='ShipRegion' headerText='Ship Region' width=150></e-column>
<e-column field='ShipPostalCode' headerText='Ship Postal Code' width=150></e-column>
<e-column field='Freight' headerText='Freight' width=120></e-column>
</e-columns>
</ejs-grid>
</div>
</template>
<script>
import Vue from "vue";
import { GridPlugin, Freeze } from "@syncfusion/ej2-vue-grids";
import { data } from "./datasource.js";
Vue.use(GridPlugin);
export default {
data() {
return {
data: data
};
},
provide: {
grid: [Freeze]
}
}
</script>
<style>
@import "https://ej2.syncfusion.com/vue/documentation/node_modules/@syncfusion/ej2-vue-grids/styles/material.css";
</style>
- The
height
andwidth
must be set while giving frozen rows and columns.- Frozen rows and columns should not be set outside the grid view port.
- Frozen Grid will support row and column virtualization feature, which helps to improve the Grid performance while loading a large dataset.
Frozen Grid Limitations
The following features are not supported in frozen rows and columns:
- Grouping
- Row Template
- Detail Template
- Hierarchy Grid
Freeze Direction
You can freeze the Grid columns on the left or right side by using the column.freeze
property and the remaining columns will be movable. The grid will automatically move the columns to the left or right position based on the column.freeze
value.
Types of the column.freeze
directions:
-
Left
: Allows you to freeze the columns at the left. -
Right
: Allows you to freeze the columns at the right.
In this demo, the ShipCountry column is frozen at the left and the CustomerID column is frozen at the right side of the content table.
<template>
<div id="app">
<ejs-grid :dataSource='data' height=315 :frozenRows='2' :enableHover='false'>
<e-columns>
<e-column field='OrderID' headerText='Order ID' textAlign='Right' width=120></e-column>
<e-column field='Freight' headerText='Freight' width=120></e-column>
<e-column field='CustomerID' headerText='Customer ID' width=150 freeze='Right'></e-column>
<e-column field='OrderDate' headerText='Order Date' width=130 format='yMd' textAlign='Right' type='date'></e-column>
<e-column field='ShipName' headerText='Ship Name' width=150></e-column>
<e-column field='ShipAddress' headerText='Ship Address' width=170></e-column>
<e-column field='ShipCity' headerText='Ship City' width=150></e-column>
<e-column field='ShipCountry' headerText='Ship Country' width=150 freeze='Left'></e-column>
</e-columns>
</ejs-grid>
</div>
</template>
<script>
import Vue from "vue";
import { GridPlugin, Freeze } from "@syncfusion/ej2-vue-grids";
import { data } from "./datasource.js";
Vue.use(GridPlugin);
export default {
data() {
return {
data: data
};
},
provide: {
grid: [Freeze]
}
}
</script>
<style>
@import "https://ej2.syncfusion.com/vue/documentation/node_modules/@syncfusion/ej2-vue-grids/styles/material.css";
</style>
- Freeze Direction is not compatible with the
isFrozen
andfrozenColumns
properties.
Limitations of Freeze Direction
This feature has the below limitations, along with the above mentioned Frozen Grid limitations.
- Column virtualization
- Infinite scroll cache mode
- Freeze direction in the stacked header is not compatible with column reordering.
Add validation rule for frozen Grid
In a frozen column enabled Grid, Grid content will be separated into frozen and movable parts. The following code can be used to dynamically add validation to input fields that are placed in the movable part. In the actionComplete event args, you can find the movableform instance as an argument. Here, you can add validation rules dynamically.
actionComplete: (args: DialogEditEventArgs) => {
if ((args.requestType === 'beginEdit' || args.requestType === 'add')) {
// Add Validation Rules
args.movableForm.ej2_instances[0].addRules('Freight', { max: 200 }); // Here, 'Freight' is the column name.
}
}
Validation rules for the ‘EmployeeID’ and ‘Freight’ columns can be added in the sample below.
<template>
<div id="app">
<ejs-grid :dataSource='data' height=315 :toolbar='toolbar' :editSettings='editSettings' :enableHover='false' :allowSelection='false' :actionComplete = 'actionComplete'>
<e-columns>
<e-column field='OrderID' headerText='Order ID' textAlign='Right' isPrimaryKey='true' width=120></e-column>
<e-column field='CustomerID' headerText='Customer ID' width=120 textAlign='Right' :validationRules='valRules'></e-column>
<e-column field='ShipName' headerText='Ship Name' width=150></e-column>
<e-column field='ShipAddress' headerText='Ship Address' width=170></e-column>
<e-column field='ShipCity' headerText='Ship City' width=150></e-column>
<e-column field='ShipCountry' headerText='Ship Country' width=150 isFrozen='true'></e-column>
<e-column field='Freight' headerText='Freight' width=120 :validationRules='valRules'></e-column>
</e-columns>
</ejs-grid>
</div>
</template>
<script>
import Vue from "vue";
import { GridPlugin, Freeze, Selection, Edit, Toolbar } from "@syncfusion/ej2-vue-grids";
import { data } from "./datasource.js";
Vue.use(GridPlugin);
export default {
data() {
return {
data: data,
toolbar: ['Add', 'Edit', 'Delete', 'Update', 'Cancel'],
editSettings: { allowEditing: true, allowAdding: true, allowDeleting: true, mode: 'Normal' },
valRules: { required: true }
};
},
methods: {
actionComplete(args) {
if (args.requestType === 'beginEdit' || args.requestType === 'add') {
// Add Validation Rules
args.movableForm.ej2_instances[0].addRules('Freight', { max: 200 });
args.movableForm.ej2_instances[0].addRules('EmployeeID', { max: 20 });
}
}
},
provide: {
grid: [Freeze, Selection, Edit, Toolbar]
}
}
</script>
<style>
@import "../node_modules/@syncfusion/ej2-vue-grids/styles/material.css";
</style>
This is applicable when a frozen column is enabled and the edit mode is set as “Normal” in the Grid.