Check box Selection in Vue Grid component
11 Jun 202424 minutes to read
Checkbox selection in the Grid component allows you to provide an option to select multiple records by using a checkbox in each row. This feature is particularly useful when you need to perform bulk actions or operations on selected records within the Grid.
To render checkbox in each grid row, you need to use checkbox column with type as checkbox using column type property.
Here’s an example of how to enable check box selection using type
property in the Grid component:
<template>
<div id="app">
<ejs-grid :dataSource='data' height='315px'>
<e-columns>
<e-column type='checkbox' width='50'></e-column>
<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='ShipCity' headerText='Ship City' width=150></e-column>
<e-column field='ShipName' headerText='Ship Name' width=150></e-column>
</e-columns>
</ejs-grid>
</div>
</template>
<script setup>
import { GridComponent as EjsGrid, ColumnDirective as EColumn, ColumnsDirective as EColumns } from "@syncfusion/ej2-vue-grids";
import { data } from './datasource.js';
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-buttons/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-calendars/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-dropdowns/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-inputs/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-vue-grids/styles/tailwind.css";
</style>
<template>
<div id="app">
<ejs-grid :dataSource='data' height='315px'>
<e-columns>
<e-column type='checkbox' width='50'></e-column>
<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='ShipCity' headerText='Ship City' width=150></e-column>
<e-column field='ShipName' headerText='Ship Name' width=150></e-column>
</e-columns>
</ejs-grid>
</div>
</template>
<script>
import { GridComponent, ColumnsDirective, ColumnDirective } from "@syncfusion/ej2-vue-grids";
import { data } from './datasource.js';
export default {
name: "App",
components: {
"ejs-grid":GridComponent,
"e-columns":ColumnsDirective,
"e-column":ColumnDirective
},
data() {
return {
data: data
};
}
}
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-buttons/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-calendars/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-dropdowns/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-inputs/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-vue-grids/styles/tailwind.css";
</style>
- By default selection is allowed by clicking a grid row or checkbox in that row. To allow selection only through checkbox, you can set selectionSettings.checkboxOnly property to true.
- Selection can be persisted on all the operations using selectionSettings.persistSelection property. For persisting selection on the Grid, any one of the column should be defined as a primary key using columns.isPrimaryKey property.
Checkbox selection mode
The checkbox selection mode in the Grid allows you to select rows either by clicking on checkboxes or by clicking on the rows themselves. This feature provides two types of checkbox selection modes that can be set using the selectionSettings.checkboxMode property. The available modes are:
-
Default: This is the default value of the
checkboxMode
. In this mode, you can select multiple rows by clicking rows one by one. When you click on a row, the checkbox associated with that row also switches to the checked state. -
ResetOnRowClick: In
ResetOnRowClick
mode, when clicking on row it will reset previously selected row. Also you can perform multiple-selection in this mode by press and hold CTRL key and click the desired rows. To select range of rows, press and hold the SHIFT key and click the rows.
In the following example, it demonstrates how to dynamically enable and change the checkboxMode
using the DropDownList
component:
<template>
<div id="app">
<div style="display: inline-block">
<label style="padding: 30px 17px 0 0 ;font-weight: bold">Choose checkbox selection mode:
</label>
<ejs-dropdownlist index="0" width="150" :dataSource="dropdownData" :change="valueChange">
</ejs-dropdownlist>
</div>
<div style="padding: 20px 0px 0px 0px">
<ejs-grid ref="grid" :dataSource='data' height='315px'>
<e-columns>
<e-column type='checkbox' width='50'></e-column>
<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='ShipCity' headerText='Ship City' width=150>
</e-column>
<e-column field='ShipName' headerText='Ship Name' width=150>
</e-column>
</e-columns>
</ejs-grid>
</div>
</div>
</template>
<script setup>
import { GridComponent as EjsGrid, ColumnDirective as EColumn, ColumnsDirective as EColumns } from "@syncfusion/ej2-vue-grids";
import { DropDownListComponent as EjsDropdownlist } from '@syncfusion/ej2-vue-dropdowns';
import { data } from "./datasource.js";
import { ref } from 'vue';
const grid = ref(null);
const dropdownData = [
{ text: 'Default', value: 'Default' },
{ text: 'ResetOnRowClick', value: 'ResetOnRowClick' }
];
const valueChange = function (args) {
grid.value.ej2Instances.selectionSettings.checkboxMode = args.value;
}
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-buttons/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-calendars/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-dropdowns/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-inputs/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-vue-grids/styles/tailwind.css";
</style>
<template>
<div id="app">
<div style="display: inline-block">
<label style="padding: 30px 17px 0 0 ;font-weight: bold" >Choose checkbox selection mode:
</label>
<ejs-dropdownlist index="0" width="150"
:dataSource=" dropdownData" :change="valueChange">
</ejs-dropdownlist>
</div>
<div style="padding: 20px 0px 0px 0px">
<ejs-grid ref="grid" :dataSource='data' height='315px'>
<e-columns>
<e-column type='checkbox' width='50'></e-column>
<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='ShipCity' headerText='Ship City' width=150>
</e-column>
<e-column field='ShipName' headerText='Ship Name' width=150>
</e-column>
</e-columns>
</ejs-grid>
</div>
</div>
</template>
<script>
import { GridComponent, ColumnsDirective, ColumnDirective } from "@syncfusion/ej2-vue-grids";
import { DropDownListComponent } from '@syncfusion/ej2-vue-dropdowns';
import { data } from "./datasource.js";
export default {
name: "App",
components: {
"ejs-dropdownlist":DropDownListComponent,
"ejs-grid":GridComponent,
"e-columns":ColumnsDirective,
"e-column":ColumnDirective
},
data() {
return {
data: data,
dropdownData: [
{ text: 'Default', value: 'Default' },
{ text: 'ResetOnRowClick', value: 'ResetOnRowClick' }
]
};
},
methods:{
valueChange: function (args) {
this.$refs.grid.ej2Instances.selectionSettings.checkboxMode = args.value;
}
}
}
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-buttons/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-calendars/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-dropdowns/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-inputs/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-vue-grids/styles/tailwind.css";
</style>
Hide selectall checkbox in column header
You can hide the select all checkbox in the column header of the Syncfusion Grid. This is a useful feature in various scenarios where you want to customize the appearance and behavior of the checkboxes within the grid.
By default, when you set the column type as checkbox, it renders a column with checkboxes for selection purposes. However, if you want to hide the header checkbox, you can achieve this by defining an empty headerTemplate in the grid Column.
Here’s an example of how to hide selectall checkbox in column header using empty headerTemplate
in the Grid component:
<template>
<div id="app">
<ejs-grid ref="grid" :dataSource="data" :selectionSettings="selectionOptions">
<e-columns>
<e-column type="checkbox" :headerTemplate="'cTemplate'" width="120">
</e-column>
<e-column field="OrderID" headerText="Order ID" width="120" textAlign="Right">
</e-column>
<e-column field="CustomerID" headerText="Customer Name" width="150"></e-column>
<e-column type="date" field="OrderDate" headerText="Order Date" width="130" format="yMd"
textAlign="Right"></e-column>
<e-column field="Freight" headerText="Freight" width="120" format="C2" textAlign="Right"></e-column>
<e-column type="date" field="ShippedDate" headerText="Shipped Date" width="130" format="yMd"
textAlign="Right"></e-column>
<e-column field="ShipCountry" headerText="Ship Country" width="150"></e-column>
<template v-slot:cTemplate>
</template>
</e-columns>
</ejs-grid>
</div>
</template>
<script setup>
import { GridComponent as EjsGrid, ColumnDirective as EColumn, ColumnsDirective as EColumns } from "@syncfusion/ej2-vue-grids";
import { data } from "./datasource.js";
const selectionOptions = { type: 'Multiple' };
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-buttons/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-calendars/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-dropdowns/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-inputs/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-vue-grids/styles/tailwind.css";
</style>
<template>
<div id="app">
<ejs-grid ref="grid" :dataSource="data" :selectionSettings="selectionOptions" >
<e-columns>
<e-column type="checkbox" :headerTemplate="'cTemplate'" width="120" >
</e-column>
<e-column field="OrderID" headerText="Order ID" width="120" textAlign="Right">
</e-column>
<e-column field="CustomerID" headerText="Customer Name" width="150"></e-column>
<e-column type="date" field="OrderDate" headerText="Order Date" width="130" format="yMd"
textAlign="Right"></e-column>
<e-column field="Freight" headerText="Freight" width="120" format="C2"
textAlign="Right"></e-column>
<e-column type="date" field="ShippedDate" headerText="Shipped Date" width="130"
format="yMd" textAlign="Right"></e-column>
<e-column field="ShipCountry" headerText="Ship Country" width="150"></e-column>
<template v-slot:cTemplate >
</template>
</e-columns>
</ejs-grid>
</div>
</template>
<script>
import { GridComponent, ColumnsDirective, ColumnDirective } from "@syncfusion/ej2-vue-grids";
import { data } from "./datasource.js";
export default {
name: "App",
components: {
"ejs-grid":GridComponent,
"e-columns":ColumnsDirective,
"e-column":ColumnDirective
},
data() {
return {
data: data,
selectionOptions :{ type: 'Multiple' }
};
}
}
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-buttons/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-calendars/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-dropdowns/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-inputs/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-vue-grids/styles/tailwind.css";
</style>
Prevent specific rows from being selected in checkbox selection
The checkbox selection mode allows you to select rows either by clicking on checkboxes or by clicking on the rows themselves. However, there might be scenarios where you want to prevent specific rows from being selected based on certain conditions or business requirements.
To achieve this, you can use the rowDataBound event of the Grid. The rowDataBound
event is triggered for each row after it is bound to the data source. In this event, you can check the row data and determine whether the row should be selectable or not. If you want to prevent the row from being selected, you can set the isSelectable argument of the event to false.
In the following sample, the selection of specific rows has been prevented based on the isSelectable
argument in the rowDataBound
event.
<template>
<div id="app">
<ejs-grid ref="grid" :dataSource='data' :allowPaging='true' :allowFiltering='true' :allowSelection='true'
:selectionSettings='selectionOptions' :editSettings='editSettings' :toolbar='toolbar' :pageSettings='pageOptions'
:filterSettings='filterOptions' :rowDataBound='rowDataBound'>
<e-columns>
<e-column type='checkbox' width=120></e-column>
<e-column field='List' headerText='List' width=120></e-column>
<e-column field='OrderID' headerText='Order ID' isPrimaryKey='true' textAlign='Right' width=150></e-column>
<e-column field='CustomerID' headerText='Customer ID' width=150>
</e-column>
<e-column field='EmployeeID' headerText='Employee ID' width=150>
</e-column>
<e-column field='ShipCity' headerText='Ship City' width=150></e-column>
</e-columns>
</ejs-grid>
</div>
</template>
<script setup>
import { provide } from "vue";
import { GridComponent as EjsGrid, ColumnDirective as EColumn, ColumnsDirective as EColumns, Page, Edit, Toolbar, Filter } from "@syncfusion/ej2-vue-grids";
import { data } from "./datasource.js";
for (let i = 0; i < data.length; i++) {
data[i]['List'] = i + 1;
}
const editSettings = { allowEditing: true, allowAdding: true, allowDeleting: true, mode: 'Normal' };
const toolbar = ['Add', 'Edit', 'Delete', 'Update', 'Cancel', 'Search'];
const selectionOptions = { type: 'Multiple', persistSelection: true };
const pageOptions = { pageSize: 5 };
const filterOptions = { type: 'CheckBox' };
const rowDataBound = function (args) {
args.isSelectable = args.data.List % 5 === 0;
}
provide('grid', [Page, Edit, Toolbar, Filter]);
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-buttons/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-calendars/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-dropdowns/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-inputs/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-vue-grids/styles/tailwind.css";
</style>
<template>
<div id="app">
<ejs-grid ref="grid" :dataSource='data' :allowPaging='true' :allowFiltering='true'
:allowSelection='true' :selectionSettings='selectionOptions'
:editSettings='editSettings' :toolbar='toolbar'
:pageSettings='pageOptions' :filterSettings='filterOptions'
:rowDataBound='rowDataBound'>
<e-columns>
<e-column type='checkbox' width=120></e-column>
<e-column field='List' headerText='List' width=120></e-column>
<e-column field='OrderID' headerText='Order ID' isPrimaryKey='true'
textAlign='Right' width=150></e-column>
<e-column field='CustomerID' headerText='Customer ID' width=150>
</e-column>
<e-column field='EmployeeID' headerText='Employee ID' width=150>
</e-column>
<e-column field='ShipCity' headerText='Ship City' width=150></e-column>
</e-columns>
</ejs-grid>
</div>
</template>
<script>
import { GridComponent, ColumnsDirective, ColumnDirective,Page,Edit,Toolbar,Filter} from "@syncfusion/ej2-vue-grids";
import { data } from "./datasource.js";
export default {
name: "App",
components: {
"ejs-grid":GridComponent,
"e-columns":ColumnsDirective,
"e-column":ColumnDirective
},
data() {
for (let i = 0; i < data.length; i++) {
data[i]['List'] = i + 1;
}
return {
data: data,
editSettings : { allowEditing: true, allowAdding: true, allowDeleting: true, mode: 'Normal' },
toolbar : ['Add', 'Edit', 'Delete', 'Update', 'Cancel', 'Search'],
selectionOptions : { type: 'Multiple', persistSelection: true },
pageOptions : { pageSize: 5 },
filterOptions : { type: 'CheckBox' },
};
},
methods:{
rowDataBound: function (args){
args.isSelectable = args.data.List % 5 === 0;
}
},
provide: {
grid: [Page,Edit,Toolbar,Filter]
}
}
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-buttons/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-calendars/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-dropdowns/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-inputs/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-vue-grids/styles/tailwind.css";
</style>
How to select single row in checkbox selection mode
The Vue Grid allows you to select only one row at a time within the Grid. This feature is particularly useful when you want to ensure that only a single row is selected, and any previous selections are cleared when a new row is selected.
To achieve single-row selection in checkbox selection mode within the Grid, you can handle the rowSelecting event and use the clearSelection method to clear any previous selections before selecting a new row. This ensures that only one row is selected at a time, and any prior selections are deselected when a new row is chosen.
- When you set the checkboxMode property to ResetOnRowClick, it will reset the previously selected row when you click on a new row. Please note that this behavior applies to rows and not checkboxes, and it is the default behavior of the grid.
Here’s an example of how to select a single row in checkbox selection mode using the clearSelection
method along with the rowSelecting
event:
<template>
<div id="app">
<ejs-grid ref="grid" :dataSource="data" :rowSelecting="rowselecting" :selectionSettings="selectionOptions">
<e-columns>
<e-column type="checkbox" width="100"></e-column>
<e-column field="OrderID" headerText="Order ID" width="120" textAlign="Right">
</e-column>
<e-column field="CustomerID" headerText="Customer Name" width="150"></e-column>
<e-column type="date" field="OrderDate" headerText="Order Date" width="130" format="yMd"
textAlign="Right"></e-column>
<e-column field="Freight" headerText="Freight" width="120" format="C2" textAlign="Right"></e-column>
<e-column type="date" field="ShippedDate" headerText="Shipped Date" width="130" format="yMd"
textAlign="Right"></e-column>
<e-column field="ShipCountry" headerText="Ship Country" width="150">
</e-column>
</e-columns>
</ejs-grid>
</div>
</template>
<script setup>
import { GridComponent as EjsGrid, ColumnDirective as EColumn, ColumnsDirective as EColumns } from "@syncfusion/ej2-vue-grids";
import { data } from "./datasource.js";
import { ref } from "vue";
const grid = ref(null);
const selectionOptions = { checkboxMode: "ResetOnRowClick" };
const rowselecting = (args) => {
if (args.target && args.target.classList.contains("e-icons"))
grid.value.clearSelection();
};
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-buttons/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-calendars/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-dropdowns/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-inputs/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-vue-grids/styles/tailwind.css";
</style>
<template>
<div id="app">
<ejs-grid ref="grid" :dataSource="data" :rowSelecting="rowselecting" :selectionSettings="selectionOptions" >
<e-columns>
<e-column type="checkbox" width="100"></e-column>
<e-column field="OrderID" headerText="Order ID" width="120" textAlign="Right">
</e-column>
<e-column field="CustomerID" headerText="Customer Name" width="150"></e-column>
<e-column type="date" field="OrderDate" headerText="Order Date" width="130" format="yMd"
textAlign="Right"></e-column>
<e-column field="Freight" headerText="Freight" width="120" format="C2"
textAlign="Right"></e-column>
<e-column type="date" field="ShippedDate" headerText="Shipped Date" width="130"
format="yMd" textAlign="Right"></e-column>
<e-column field="ShipCountry" headerText="Ship Country" width="150">
</e-column>
</e-columns>
</ejs-grid>
</div>
</template>
<script>
import { GridComponent, ColumnsDirective, ColumnDirective } from "@syncfusion/ej2-vue-grids";
import { data } from "./datasource.js";
export default {
name: "App",
components: {
"ejs-grid":GridComponent,
"e-columns":ColumnsDirective,
"e-column":ColumnDirective
},
data() {
return {
data: data,
selectionOptions: { checkboxMode: "ResetOnRowClick" },
};
},
methods: {
rowselecting: function (args) {
if (args.target && args.target.classList.contains("e-icons"))
this.$refs.grid.ej2Instances.clearSelection();
},
},
};
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-buttons/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-calendars/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-dropdowns/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-inputs/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-vue-grids/styles/tailwind.css";
</style>
Allow selection only through checkbox click
By default, the Grid component allows selection by clicking either a grid row or the checkbox within that row. If you want to restrict selection so that it can only be done by clicking the checkboxes, you can set the selectionSettings.checkboxOnly property to true.
Here’s an example of how to enable selection only through checkbox click using checkboxOnly
property:
<template>
<div id="app">
<ejs-grid ref="grid" :dataSource="data" allowPaging="true" :selectionSettings="selectionOptions">
<e-columns>
<e-column type="checkbox" width="100"></e-column>
<e-column field="OrderID" headerText="Order ID" width="120" textAlign="Right"></e-column>
<e-column field="CustomerID" headerText="Customer Name" width="150"></e-column>
<e-column type="date" field="OrderDate" headerText="Order Date" width="130" format="yMd"
textAlign="Right"></e-column>
<e-column field="Freight" headerText="Freight" width="120" format="C2" textAlign="Right"></e-column>
<e-column type="date" field="ShippedDate" headerText="Shipped Date" width="130" format="yMd"
textAlign="Right"></e-column>
<e-column field="ShipCountry" headerText="Ship Country" width="150"></e-column>
</e-columns>
</ejs-grid>
</div>
</template>
<script setup>
import { provide } from "vue";
import { GridComponent as EjsGrid, ColumnDirective as EColumn, ColumnsDirective as EColumns, Page } from "@syncfusion/ej2-vue-grids";
import { data } from "./datasource.js";
const selectionOptions = { checkboxOnly: true };
provide('grid', [Page]);
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-buttons/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-calendars/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-dropdowns/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-inputs/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-vue-grids/styles/tailwind.css";
</style>
<template>
<div id="app">
<ejs-grid ref="grid" :dataSource="data" allowPaging="true"
:selectionSettings="selectionOptions">
<e-columns>
<e-column type="checkbox" width="100"></e-column>
<e-column field="OrderID" headerText="Order ID" width="120"
textAlign="Right"></e-column>
<e-column field="CustomerID" headerText="Customer Name" width="150"></e-column>
<e-column type="date" field="OrderDate" headerText="Order Date" width="130" format="yMd"
textAlign="Right"></e-column>
<e-column field="Freight" headerText="Freight" width="120" format="C2"
textAlign="Right"></e-column>
<e-column type="date" field="ShippedDate" headerText="Shipped Date" width="130"
format="yMd" textAlign="Right"></e-column>
<e-column field="ShipCountry" headerText="Ship Country" width="150"></e-column>
</e-columns>
</ejs-grid>
</div>
</template>
<script>
import { GridComponent, ColumnsDirective, ColumnDirective, Page } from "@syncfusion/ej2-vue-grids";
import { data } from "./datasource.js";
export default {
name: "App",
components: {
"ejs-grid":GridComponent,
"e-columns":ColumnsDirective,
"e-column":ColumnDirective
},
data() {
return {
data: data,
selectionOptions: { checkboxOnly: true },
};
},
provide: {
grid: [Page],
},
};
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-buttons/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-calendars/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-dropdowns/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-inputs/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-vue-grids/styles/tailwind.css";
</style>