Search results

Selection in Vue Spreadsheet component

09 Jun 2021 / 5 minutes to read

Selection provides interactive support to highlight the cell, row, or column that you select. Selection can be done through Mouse, Touch, or Keyboard interaction. To enable selection, set mode as Single | Multiple in selectionSettings. If you set mode to None, it disables the UI selection.

  • The default value for mode in selectionSettings is Multiple.

You have the following options in Selection,

  • Cell selection
  • Row selection
  • Column selection

Cell selection

Cell selection is used to select a single or multiple cells. It can be performed using the selectRange method.

User Interface:

  • Click on a cell to select it (or) use the arrow keys to navigate to it and select it.
  • To select a range, select a cell, then use the left mouse button to select and drag over to other cells (or) use the Shift + arrow keys to select the range.
  • To select non-adjacent cells and cell ranges, hold Ctrl and select the cells.

You can quickly locate and select specific cells or ranges by entering their names or cell references in the Name box, which is located to the left of the formula bar, and also select named or unnamed cells or ranges by using the Go To (Ctrl+G) command.

Row selection

Row selection is used to select a single or multiple rows.

User Interface:

You can perform row selection in any of the following ways,

  • By clicking the row header.
  • To select multiple rows, select a row header with the left mouse button and drag over to other row headers (or) use the Shift + arrow keys to select multiple rows.
  • To select non-adjacent rows, hold Ctrl and select the row header.
  • You can also use the selectRange method for row selection.

The following sample shows the row selection in the spreadsheet, here selecting the 5th row using the selectRange method.

Source
Preview
app.vue
data.js
Copied to clipboard
<template>
  <ejs-spreadsheet ref="spreadsheet" :created="created" :selectionSettings="selectionSettings">
            <e-sheets>
              <e-sheet name="Price Details">
                <e-ranges>
                  <e-range :dataSource="dataSource1"></e-range>
                </e-ranges>
                <e-columns>
                  <e-column :width=100></e-column>
                  <e-column :width=100></e-column>
                  <e-column :width=100></e-column>
                  <e-column :width=100></e-column>
                </e-columns>
              </e-sheet>
            </e-sheets>
          </ejs-spreadsheet>
</template>

<script>
import Vue from "vue";
import { SpreadsheetPlugin, getRangeAddress } from "@syncfusion/ej2-vue-spreadsheet";
import { priceData } from './data.js';
Vue.use(SpreadsheetPlugin);
export default {
   data: () => {
return {
    selectionSettings: { mode: 'Multiple' },
  dataSource1: priceData
}
  },
  methods: {
   created: function () {
   var spreadsheet = this.$refs.spreadsheet;
spreadsheet.cellFormat({ fontWeight: 'bold', textAlign: 'center' }, 'A1:H1');
var colCount = spreadsheet.ej2Instances.getActiveSheet().colCount;
    spreadsheet.selectRange(getRangeAddress([4, 0, 4, colCount]));
  }
}
}
</script>
<style>
 @import "../node_modules/@syncfusion/ej2-vue-spreadsheet/styles/material.css";
 @import '../node_modules/@syncfusion/ej2-base/styles/material.css';  
 @import '../node_modules/@syncfusion/ej2-buttons/styles/material.css';  
 @import '../node_modules/@syncfusion/ej2-dropdowns/styles/material.css';  
 @import '../node_modules/@syncfusion/ej2-inputs/styles/material.css';  
 @import '../node_modules/@syncfusion/ej2-navigations/styles/material.css';
 @import '../node_modules/@syncfusion/ej2-popups/styles/material.css';
 @import '../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css';
 @import '../node_modules/@syncfusion/ej2-grids/styles/material.css';
 @import "../node_modules/@syncfusion/ej2-spreadsheet/styles/material.css";
</style>
Copied to clipboard
define(["require", "exports"], function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    exports.priceData = [
        {
            'Item Name': 'Casual Shoes',
            'Date': '02/14/2019',
            'Time': '11:34:32 AM',
            'Quantity': 10,
            'Price': 20,
            'Amount': '=D2*E2',
            'Discount': 1,
            'Profit': 10
        },
        {
            'Item Name': 'Sports Shoes',
            'Date': '06/11/2019',
            'Time': '05:56:32 AM',
            'Quantity': 20,
            'Price': 30,
            'Amount': '=D3*E3',
            'Discount': 5,
            'Profit': 50
        },
        {
            'Item Name': 'Formal Shoes',
            'Date': '07/27/2019',
            'Time': '03:32:44 AM',
            'Quantity': 20,
            'Price': 15,
            'Amount': '=D4*E4',
            'Discount': 7,
            'Profit': 27
        },
        {
            'Item Name': 'Sandals & Floaters',
            'Date': '11/21/2019',
            'Time': '06:23:54 AM',
            'Quantity': 15,
            'Price': 20,
            'Amount': '=D5*E5',
            'Discount': 11,
            'Profit': 67
        },
        {
            'Item Name': 'Flip- Flops & Slippers',
            'Date': '06/23/2019',
            'Time': '12:43:59 AM',
            'Quantity': 30,
            'Price': 10,
            'Amount': '=D6*E6',
            'Discount': 10,
            'Profit': 70
        },
        {
            'Item Name': 'Sneakers',
            'Date': '07/22/2019',
            'Time': '10:55:53 AM',
            'Quantity': 40,
            'Price': 20,
            'Amount': '=D7*E7',
            'Discount': 13,
            'Profit': 66
        },
        {
            'Item Name': 'Running Shoes',
            'Date': '02/04/2019',
            'Time': '03:44:34 AM',
            'Quantity': 20,
            'Price': 10,
            'Amount': '=D8*E8',
            'Discount': 3,
            'Profit': 14
        },
        {
            'Item Name': 'Loafers',
            'Date': '11/30/2019',
            'Time': '03:12:52 AM',
            'Quantity': 31,
            'Price': 10,
            'Amount': '=D9*E9',
            'Discount': 6,
            'Profit': 29
        },
        {
            'Item Name': 'Cricket Shoes',
            'Date': '07/09/2019',
            'Time': '11:32:14 AM',
            'Quantity': 41,
            'Price': 30,
            'Amount': '=D10*E10',
            'Discount': 12,
            'Profit': 166
        },
        {
            'Item Name': 'T-Shirts',
            'Date': '10/31/2019',
            'Time': '12:01:44 AM',
            'Quantity': 50,
            'Price': 10,
            'Amount': '=D11*E11',
            'Discount': 9,
            'Profit': 55
        }
      ];
      exports.budgetData = [
        {
          'Expense Type': 'Housing',
          'Projected Cost': 7000,
          'Actual Cost': 7500,
          'Difference': -500,
        },
        {
          'Expense Type': 'Transportation',
          'Projected Cost': 500,
          'Actual Cost': 500,
          'Difference': 0,
        },
        {
          'Expense Type': 'Insurance',
          'Projected Cost': 1000,
          'Actual Cost': 1000,
          'Difference': 0,
        },
        {
          'Expense Type': 'Food',
          'Projected Cost': 2000,
          'Actual Cost': 1800,
          'Difference': 200,
        },
        {
          'Expense Type': 'Pets',
          'Projected Cost': 300,
          'Actual Cost': 200,
          'Difference': 100,
        },
        {
          'Expense Type': 'Personel Care',
          'Projected Cost': 500,
          'Actual Cost': 500,
          'Difference': 0,
        },
        {
          'Expense Type': 'Loan',
          'Projected Cost': 1000,
          'Actual Cost': 1000,
          'Difference': 0,
        },
        {
          'Expense Type': 'Tax',
          'Projected Cost': 200,
          'Actual Cost': 200,
          'Difference': 0,
        },
        {
          'Expense Type': 'Savings',
          'Projected Cost': 1000,
          'Actual Cost': 900,
          'Difference': 100,
        },
        {
          'Expense Type': 'Total',
          'Projected Cost': 13500,
          'Actual Cost': 13600,
          'Difference': -100,
        }
      ];
});

Column selection

Column selection is used to select a single or multiple columns.

User Interface:

You can perform column selection in any of the following ways,

  • By clicking the column header.
  • To select multiple columns, select a column header with the left mouse button and drag over to other column headers (or) use the Shift + arrow keys to select the multiple columns.
  • To select non-adjacent columns, hold Ctrl and select the column header.
  • You can also use the selectRange method for row selection.

The following sample shows the column selection in the spreadsheet, here selecting the 3rd column using the selectRange method.

Source
Preview
app.vue
data.js
Copied to clipboard
<template>
  <ejs-spreadsheet ref="spreadsheet" :created="created" :selectionSettings="selectionSettings">
            <e-sheets>
              <e-sheet name="Price Details">
                <e-ranges>
                  <e-range :dataSource="dataSource1"></e-range>
                </e-ranges>
                <e-columns>
                  <e-column :width=100></e-column>
                  <e-column :width=100></e-column>
                  <e-column :width=100></e-column>
                  <e-column :width=100></e-column>
                </e-columns>
              </e-sheet>
            </e-sheets>
          </ejs-spreadsheet>
</template>

<script>
import Vue from "vue";
import { SpreadsheetPlugin, getRangeAddress } from "@syncfusion/ej2-vue-spreadsheet";
import { priceData } from './data.js';
Vue.use(SpreadsheetPlugin);
export default {
   data: () => {
return {
    selectionSettings: { mode: 'Multiple' },
  dataSource1: priceData
}
  },
  methods: {
   created: function () {
   var spreadsheet = this.$refs.spreadsheet;
spreadsheet.cellFormat({ fontWeight: 'bold', textAlign: 'center' }, 'A1:H1');
var rowCount = spreadsheet.ej2Instances.getActiveSheet().rowCount;
    spreadsheet.selectRange(getRangeAddress([0, 2, rowCount, 2]));
  }
}
}
</script>
<style>
 @import "../node_modules/@syncfusion/ej2-vue-spreadsheet/styles/material.css";
 @import '../node_modules/@syncfusion/ej2-base/styles/material.css';  
 @import '../node_modules/@syncfusion/ej2-buttons/styles/material.css';  
 @import '../node_modules/@syncfusion/ej2-dropdowns/styles/material.css';  
 @import '../node_modules/@syncfusion/ej2-inputs/styles/material.css';  
 @import '../node_modules/@syncfusion/ej2-navigations/styles/material.css';
 @import '../node_modules/@syncfusion/ej2-popups/styles/material.css';
 @import '../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css';
 @import '../node_modules/@syncfusion/ej2-grids/styles/material.css';
 @import "../node_modules/@syncfusion/ej2-spreadsheet/styles/material.css";
</style>
Copied to clipboard
define(["require", "exports"], function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    exports.priceData = [
        {
            'Item Name': 'Casual Shoes',
            'Date': '02/14/2019',
            'Time': '11:34:32 AM',
            'Quantity': 10,
            'Price': 20,
            'Amount': '=D2*E2',
            'Discount': 1,
            'Profit': 10
        },
        {
            'Item Name': 'Sports Shoes',
            'Date': '06/11/2019',
            'Time': '05:56:32 AM',
            'Quantity': 20,
            'Price': 30,
            'Amount': '=D3*E3',
            'Discount': 5,
            'Profit': 50
        },
        {
            'Item Name': 'Formal Shoes',
            'Date': '07/27/2019',
            'Time': '03:32:44 AM',
            'Quantity': 20,
            'Price': 15,
            'Amount': '=D4*E4',
            'Discount': 7,
            'Profit': 27
        },
        {
            'Item Name': 'Sandals & Floaters',
            'Date': '11/21/2019',
            'Time': '06:23:54 AM',
            'Quantity': 15,
            'Price': 20,
            'Amount': '=D5*E5',
            'Discount': 11,
            'Profit': 67
        },
        {
            'Item Name': 'Flip- Flops & Slippers',
            'Date': '06/23/2019',
            'Time': '12:43:59 AM',
            'Quantity': 30,
            'Price': 10,
            'Amount': '=D6*E6',
            'Discount': 10,
            'Profit': 70
        },
        {
            'Item Name': 'Sneakers',
            'Date': '07/22/2019',
            'Time': '10:55:53 AM',
            'Quantity': 40,
            'Price': 20,
            'Amount': '=D7*E7',
            'Discount': 13,
            'Profit': 66
        },
        {
            'Item Name': 'Running Shoes',
            'Date': '02/04/2019',
            'Time': '03:44:34 AM',
            'Quantity': 20,
            'Price': 10,
            'Amount': '=D8*E8',
            'Discount': 3,
            'Profit': 14
        },
        {
            'Item Name': 'Loafers',
            'Date': '11/30/2019',
            'Time': '03:12:52 AM',
            'Quantity': 31,
            'Price': 10,
            'Amount': '=D9*E9',
            'Discount': 6,
            'Profit': 29
        },
        {
            'Item Name': 'Cricket Shoes',
            'Date': '07/09/2019',
            'Time': '11:32:14 AM',
            'Quantity': 41,
            'Price': 30,
            'Amount': '=D10*E10',
            'Discount': 12,
            'Profit': 166
        },
        {
            'Item Name': 'T-Shirts',
            'Date': '10/31/2019',
            'Time': '12:01:44 AM',
            'Quantity': 50,
            'Price': 10,
            'Amount': '=D11*E11',
            'Discount': 9,
            'Profit': 55
        }
      ];
      exports.budgetData = [
        {
          'Expense Type': 'Housing',
          'Projected Cost': 7000,
          'Actual Cost': 7500,
          'Difference': -500,
        },
        {
          'Expense Type': 'Transportation',
          'Projected Cost': 500,
          'Actual Cost': 500,
          'Difference': 0,
        },
        {
          'Expense Type': 'Insurance',
          'Projected Cost': 1000,
          'Actual Cost': 1000,
          'Difference': 0,
        },
        {
          'Expense Type': 'Food',
          'Projected Cost': 2000,
          'Actual Cost': 1800,
          'Difference': 200,
        },
        {
          'Expense Type': 'Pets',
          'Projected Cost': 300,
          'Actual Cost': 200,
          'Difference': 100,
        },
        {
          'Expense Type': 'Personel Care',
          'Projected Cost': 500,
          'Actual Cost': 500,
          'Difference': 0,
        },
        {
          'Expense Type': 'Loan',
          'Projected Cost': 1000,
          'Actual Cost': 1000,
          'Difference': 0,
        },
        {
          'Expense Type': 'Tax',
          'Projected Cost': 200,
          'Actual Cost': 200,
          'Difference': 0,
        },
        {
          'Expense Type': 'Savings',
          'Projected Cost': 1000,
          'Actual Cost': 900,
          'Difference': 100,
        },
        {
          'Expense Type': 'Total',
          'Projected Cost': 13500,
          'Actual Cost': 13600,
          'Difference': -100,
        }
      ];
});

How to remove selection in the spreadsheet

The following sample shows, how to remove the selection in the spreadsheet. Here changing the mode as None in selectionSettings to disable’s the UI selection.

Source
Preview
app.vue
data.js
Copied to clipboard
<template>
  <ejs-spreadsheet ref="spreadsheet" :created="created" :cellEdit="cellEdit" :selectionSettings="selectionSettings">
            <e-sheets>
              <e-sheet name="Price Details">
                <e-ranges>
                  <e-range :dataSource="dataSource1"></e-range>
                </e-ranges>
                <e-columns>
                  <e-column :width=100></e-column>
                  <e-column :width=100></e-column>
                  <e-column :width=100></e-column>
                  <e-column :width=100></e-column>
                </e-columns>
              </e-sheet>
            </e-sheets>
          </ejs-spreadsheet>
</template>

<script>
import Vue from "vue";
import { SpreadsheetPlugin, getRangeAddress } from "@syncfusion/ej2-vue-spreadsheet";
import { priceData  } from './data.js';
Vue.use(SpreadsheetPlugin);
export default {
   data: () => {
return {
    selectionSettings: { mode: 'None' },
  dataSource1: priceData
}
  },
  methods: {
   created: function () {
   var spreadsheet = this.$refs.spreadsheet;
spreadsheet.cellFormat({ fontWeight: 'bold', textAlign: 'center' }, 'A1:H1');
  },
  cellEdit: function(args) {
    args.cancel = true;
    }
}
}
</script>
<style>
 @import "../node_modules/@syncfusion/ej2-vue-spreadsheet/styles/material.css";
 @import '../node_modules/@syncfusion/ej2-base/styles/material.css';  
 @import '../node_modules/@syncfusion/ej2-buttons/styles/material.css';  
 @import '../node_modules/@syncfusion/ej2-dropdowns/styles/material.css';  
 @import '../node_modules/@syncfusion/ej2-inputs/styles/material.css';  
 @import '../node_modules/@syncfusion/ej2-navigations/styles/material.css';
 @import '../node_modules/@syncfusion/ej2-popups/styles/material.css';
 @import '../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css';
 @import '../node_modules/@syncfusion/ej2-grids/styles/material.css';
 @import "../node_modules/@syncfusion/ej2-spreadsheet/styles/material.css";
</style>
Copied to clipboard
define(["require", "exports"], function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    exports.priceData = [
        {
            'Item Name': 'Casual Shoes',
            'Date': '02/14/2019',
            'Time': '11:34:32 AM',
            'Quantity': 10,
            'Price': 20,
            'Amount': '=D2*E2',
            'Discount': 1,
            'Profit': 10
        },
        {
            'Item Name': 'Sports Shoes',
            'Date': '06/11/2019',
            'Time': '05:56:32 AM',
            'Quantity': 20,
            'Price': 30,
            'Amount': '=D3*E3',
            'Discount': 5,
            'Profit': 50
        },
        {
            'Item Name': 'Formal Shoes',
            'Date': '07/27/2019',
            'Time': '03:32:44 AM',
            'Quantity': 20,
            'Price': 15,
            'Amount': '=D4*E4',
            'Discount': 7,
            'Profit': 27
        },
        {
            'Item Name': 'Sandals & Floaters',
            'Date': '11/21/2019',
            'Time': '06:23:54 AM',
            'Quantity': 15,
            'Price': 20,
            'Amount': '=D5*E5',
            'Discount': 11,
            'Profit': 67
        },
        {
            'Item Name': 'Flip- Flops & Slippers',
            'Date': '06/23/2019',
            'Time': '12:43:59 AM',
            'Quantity': 30,
            'Price': 10,
            'Amount': '=D6*E6',
            'Discount': 10,
            'Profit': 70
        },
        {
            'Item Name': 'Sneakers',
            'Date': '07/22/2019',
            'Time': '10:55:53 AM',
            'Quantity': 40,
            'Price': 20,
            'Amount': '=D7*E7',
            'Discount': 13,
            'Profit': 66
        },
        {
            'Item Name': 'Running Shoes',
            'Date': '02/04/2019',
            'Time': '03:44:34 AM',
            'Quantity': 20,
            'Price': 10,
            'Amount': '=D8*E8',
            'Discount': 3,
            'Profit': 14
        },
        {
            'Item Name': 'Loafers',
            'Date': '11/30/2019',
            'Time': '03:12:52 AM',
            'Quantity': 31,
            'Price': 10,
            'Amount': '=D9*E9',
            'Discount': 6,
            'Profit': 29
        },
        {
            'Item Name': 'Cricket Shoes',
            'Date': '07/09/2019',
            'Time': '11:32:14 AM',
            'Quantity': 41,
            'Price': 30,
            'Amount': '=D10*E10',
            'Discount': 12,
            'Profit': 166
        },
        {
            'Item Name': 'T-Shirts',
            'Date': '10/31/2019',
            'Time': '12:01:44 AM',
            'Quantity': 50,
            'Price': 10,
            'Amount': '=D11*E11',
            'Discount': 9,
            'Profit': 55
        }
      ];
      exports.budgetData = [
        {
          'Expense Type': 'Housing',
          'Projected Cost': 7000,
          'Actual Cost': 7500,
          'Difference': -500,
        },
        {
          'Expense Type': 'Transportation',
          'Projected Cost': 500,
          'Actual Cost': 500,
          'Difference': 0,
        },
        {
          'Expense Type': 'Insurance',
          'Projected Cost': 1000,
          'Actual Cost': 1000,
          'Difference': 0,
        },
        {
          'Expense Type': 'Food',
          'Projected Cost': 2000,
          'Actual Cost': 1800,
          'Difference': 200,
        },
        {
          'Expense Type': 'Pets',
          'Projected Cost': 300,
          'Actual Cost': 200,
          'Difference': 100,
        },
        {
          'Expense Type': 'Personel Care',
          'Projected Cost': 500,
          'Actual Cost': 500,
          'Difference': 0,
        },
        {
          'Expense Type': 'Loan',
          'Projected Cost': 1000,
          'Actual Cost': 1000,
          'Difference': 0,
        },
        {
          'Expense Type': 'Tax',
          'Projected Cost': 200,
          'Actual Cost': 200,
          'Difference': 0,
        },
        {
          'Expense Type': 'Savings',
          'Projected Cost': 1000,
          'Actual Cost': 900,
          'Difference': 100,
        },
        {
          'Expense Type': 'Total',
          'Projected Cost': 13500,
          'Actual Cost': 13600,
          'Difference': -100,
        }
      ];
});

Limitations

  • We have a limitation while performing the Select All(ctrl + A). You can do this only by clicking the Select All button at the top left corner.