Cell selection in Vue Grid component
16 Mar 20234 minutes to read
Cell Selection can be done through simple Mouse down or Arrow keys(up, down, left and right).
Grid supports two types of cell selection mode which can be set by using
selectionSettings.cellSelectionMode
. They are:
-
Flow
- TheFlow
value is set by default.Select range of cells between the start index and end index which includes in between cells of rows. -
Box
- Select range of cells within the start and end column indexes which includes in between cells of rows within the range.
<template>
<div id="app">
<ejs-grid :dataSource='data' :selectionSettings='selectionOptions' height='315px'>
<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='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 Vue from "vue";
import { GridPlugin } from "@syncfusion/ej2-vue-grids";
import { data } from './datasource.js';
Vue.use(GridPlugin);
export default {
data() {
return {
data: data,
selectionOptions: { cellSelectionMode: 'Box', type: 'Multiple', mode: 'Cell' }
};
}
}
</script>
<style>
@import "../node_modules/@syncfusion/ej2-vue-grids/styles/material.css";
</style>
Cell Selection requires the
selectionSettings.mode
to beCell
orBoth
andtype
should beMultiple
.
Toggle selection
The Toggle selection allows to perform selection and unselection of the particular row or cell or column. To enable toggle selection, set enableToggle
property of the selectionSettings as true. If you click on the selected row or cell or column then it will be unselected and vice versa.
<template>
<div id="app">
<ejs-grid :dataSource='data' :selectionSettings='selectionOptions' 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 Vue from "vue";
import { GridPlugin } from "@syncfusion/ej2-vue-grids";
import { data } from './datasource.js';
Vue.use(GridPlugin);
export default {
data() {
return {
data: data,
selectionOptions: { enableToggle: true}
};
}
}
</script>
<style>
@import "../node_modules/@syncfusion/ej2-vue-grids/styles/material.css";
</style>
If multi selection is enabled, then first click on any selected row (without pressing Ctrl key), it will clear the multi selection and in second click on the same row, it will be unselected.