Selection

By default, the FlexGrid allows you to select a range of cells with the mouse or keyboard, just like Excel. The selectionMode property allows you to change that so that users are restricted to selecting rows, row ranges, non-contiguous rows (like in a list-box), single cells, or nothing at all.

import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; import * as wjGrid from '@grapecity/wijmo.grid'; import * as wjCore from '@grapecity/wijmo'; import * as wjInput from '@grapecity/wijmo.input'; // document.readyState === 'complete' ? init() : window.onload = init; // function init() { // // create some random data var countries = 'US,Germany,UK,Japan,Italy,Greece'.split(','), data = []; for (var i = 0; i < countries.length; i++) { data.push({ country: countries[i], downloads: Math.round(Math.random() * 20000), sales: Math.random() * 10000, expenses: Math.random() * 5000 }); } // // show data in a grid var currSel = document.getElementById('currSel'); var theGrid = new wjGrid.FlexGrid('#theGrid', { alternatingRowStep: 0, itemsSource: data, selectionChanged: function (s, e) { currSel.textContent = wjCore.format('({row},{col})-({row2},{col2})', theGrid.selection); } }); theGrid.onSelectionChanged(null); // initialize selection display // // pick selectionMode var selectionMode = new wjInput.ComboBox('#selectionMode', { itemsSource: 'None,Cell,CellRange,Row,RowRange,ListBox'.split(','), text: 'CellRange', textChanged: function () { theGrid.selectionMode = wjCore.asEnum(selectionMode.selectedIndex, wjGrid.SelectionMode); } }); // // select first four cells in the grid document.getElementById('btnSelect').addEventListener('click', function () { selectionMode.text = 'CellRange'; theGrid.selection = new wjGrid.CellRange(0, 0, 1, 1); }); // // select rows 0, 2, and 4 document.getElementById('btnListSelect').addEventListener('click', function () { selectionMode.text = 'ListBox'; theGrid.select(0, 0); // regular selection still works in listbox mode [0, 2, 4].forEach(function (index) { theGrid.rows[index].isSelected = true; }); }); // } <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Wijmo FlexGrid Seletion Overview</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app'); </script> </head> <body> <div class="container-fluid"> <label> selectionMode <div id="selectionMode"></div> </label> <div id="theGrid"></div> <p> Current selection: <span id="currSel"></span>. </p> <div> <button id="btnSelect" class="btn btn-default"> Select the first four cells </button> <button id="btnListSelect" class="btn btn-default"> Select rows 0, 2, and 4 </button> </div> </div> </body> </html> .wj-flexgrid { max-height: 250px; margin:6px 0; } #currSel { font-weight: bold } body { margin-bottom: 12px; } import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; import { Component, enableProdMode, NgModule, Inject, ViewChild } from '@angular/core'; import { FormsModule } from '@angular/forms'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { BrowserModule } from '@angular/platform-browser'; import { WjGridModule } from '@grapecity/wijmo.angular2.grid'; import { WjInputModule } from '@grapecity/wijmo.angular2.input'; import * as wjCore from '@grapecity/wijmo'; import * as wjInput from '@grapecity/wijmo.input'; import * as wjGrid from '@grapecity/wijmo.grid'; import { DataService, DataItem } from './app.data'; @Component({ selector: 'app-component', templateUrl: 'src/app.component.html' }) export class AppComponent { @ViewChild('flexGrid') flexGrid: wjGrid.FlexGrid; @ViewChild('selectionMode') selectionMode: wjInput.ComboBox; data: DataItem[]; comboBoxData: string[]; currentSelection: string; // DataSvc will be passed by derived classes constructor(@Inject(DataService) dataSvc: DataService) { this.data = dataSvc.getData(); this.comboBoxData = 'None,Cell,CellRange,Row,RowRange,ListBox'.split(','); } // initializeGrid() { this.flexGrid.onSelectionChanged(null); } // onTextChanged() { this.flexGrid.selectionMode = wjCore.asEnum(this.selectionMode.selectedIndex, wjGrid.SelectionMode); } // onSelectionChanged() { this.currentSelection = wjCore.format( '({row},{col})-({row2},{col2})', this.flexGrid.selection); } // onRefreshClick() { this.flexGrid.collectionView.refresh(); } // onSelectClick() { this.selectionMode.text = 'CellRange'; this.flexGrid.selection = new wjGrid.CellRange(0, 0, 1, 1); } // onListSelectClick() { this.selectionMode.text = 'ListBox'; this.flexGrid.select(0, 0); setTimeout(() => { [0, 2, 4].forEach((index) => { this.flexGrid.rows[index].isSelected = true; }); }); } } @NgModule({ imports: [WjGridModule, FormsModule, WjInputModule, BrowserModule], providers: [DataService], declarations: [AppComponent], bootstrap: [AppComponent] }) export class AppModule { } enableProdMode(); // Bootstrap application with hash style navigation and global services. platformBrowserDynamic().bootstrapModule(AppModule); <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Wijmo FlexGrid Seletion Overview</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- Polyfills --> <script src="node_modules/core-js/client/shim.min.js"></script> <script src="node_modules/zone.js/dist/zone.min.js"></script> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.js"></script> <script src="systemjs.config.js"></script> <script> // workaround to load 'rxjs/operators' from the rxjs bundle System.import('rxjs').then(function (m) { System.set(SystemJS.resolveSync('rxjs/operators'), System.newModule(m.operators)); System.import('./src/app.component'); }); </script> </head> <body> <app-component></app-component> </body> </html> <div class="container-fluid"> <label> selectionMode <span id="selectionMode"></span> <wj-combo-box #selectionMode [itemsSource]="comboBoxData" [text]="'CellRange'" (textChanged)="onTextChanged()"></wj-combo-box> </label> <wj-flex-grid #flexGrid [alternatingRowStep]="0" [itemsSource]="data" (initialized)="initializeGrid(flex)" (selectionChanged)="onSelectionChanged()"> </wj-flex-grid> <p> Current selection: <span id="currSel">{{currentSelection}}</span>. </p> <div> <button class="btn btn-default" (click)="onSelectClick()"> Select the first four cells </button> <button class="btn btn-default" (click)="onListSelectClick()"> Select rows 0, 2, and 4 </button> </div> </div> import { Injectable } from '@angular/core'; export interface DataItem { country: string; downloads: number; sales: number; expenses: number; } @Injectable() export class DataService { getData(): DataItem[] { var countries = 'US,Germany,UK,Japan,Italy,Greece'.split(','), data = []; for (var i = 0; i < countries.length; i++) { data.push({ country: countries[i], downloads: Math.round(Math.random() * 20000), sales: Math.random() * 10000, expenses: Math.random() * 5000 }); } return data; } } .wj-flexgrid { max-height: 250px; margin:6px 0; } #currSel { font-weight: bold } body { margin-bottom: 12px; } <template> <div class="container-fluid"> <label>selectionMode <span id="selectionMode"></span> <wj-combo-box :initialized="initCombo" :itemsSource="comboBoxData" :text="'CellRange'" :textChanged="onTextChanged" ></wj-combo-box> </label> <wj-flex-grid :alternatingRowStep="0" :itemsSource="data" :initialized="initializeGrid" :selectionChanged="onSelectionChanged"></wj-flex-grid> <p> Current selection: <span id="currSel">{{currentSelection}}</span>. </p> <div> <button class="btn btn-default" @click="onSelectClick">Select the first four cells</button> <button class="btn btn-default" @click="onListSelectClick">Select rows 0, 2, and 4</button> </div> </div> </template> <script> import "@grapecity/wijmo.styles/wijmo.css"; import "bootstrap.css"; import Vue from "vue"; import "@grapecity/wijmo.vue2.core"; import "@grapecity/wijmo.vue2.grid"; import "@grapecity/wijmo.vue2.input"; import * as wjGrid from "@grapecity/wijmo.grid"; import { getData } from "./data"; let App = Vue.extend({ name: "app", data: function() { return { data: getData(), comboBoxData: "None,Cell,CellRange,Row,RowRange,ListBox".split(","), currentSelection: null, flexGrid: null, selectionMode: null }; }, methods: { initCombo: function(combo) { this.selectionMode = combo; }, initializeGrid: function(flexGrid) { this.flexGrid = flexGrid; this.flexGrid.onSelectionChanged(null); }, onTextChanged: function() { this.flexGrid.selectionMode = wijmo.asEnum( this.selectionMode.selectedIndex, wjGrid.SelectionMode ); }, onSelectionChanged: function() { this.currentSelection = wijmo.format( "({row},{col})-({row2},{col2})", this.flexGrid.selection ); }, onRefreshClick: function() { this.flexGrid.collectionView.refresh(); }, onSelectClick: function() { this.selectionMode.text = "CellRange"; this.flexGrid.selection = new wjGrid.CellRange(0, 0, 1, 1); }, onListSelectClick: function() { this.selectionMode.text = "ListBox"; this.flexGrid.select(0, 0); [0, 2, 4].forEach((index) => { this.flexGrid.rows[index].isSelected = true; }); } } }); new Vue({ render: h => h(App) }).$mount("#app"); </script> <style> .wj-flexgrid { max-height: 250px; margin: 10px; } #currSel { font-weight: bold; } body { margin-bottom: 12px; } </style> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Wijmo FlexGrid Seletion Overview</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/jszip/dist/jszip.js"></script> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app.vue'); </script> </head> <body> <div id="app"> </div> </body> </html> export function getData() { var countries = 'US,Germany,UK,Japan,Italy,Greece'.split(','), data = []; for (var i = 0; i < countries.length; i++) { data.push({ country: countries[i], downloads: Math.round(Math.random() * 20000), sales: Math.random() * 10000, expenses: Math.random() * 5000 }); } return data; } import "@grapecity/wijmo.styles/wijmo.css"; import "bootstrap.css"; import "./app.css"; // import * as React from 'react'; import * as ReactDOM from 'react-dom'; // import * as wjcCore from "@grapecity/wijmo"; import * as wjcGrid from "@grapecity/wijmo.react.grid"; import * as wjGrid from "@grapecity/wijmo.grid"; import * as wjcInput from "@grapecity/wijmo.react.input"; import { getData } from "./data"; class App extends React.Component { constructor(props) { super(props); this.state = { data: getData(), comboBoxData: "None,Cell,CellRange,Row,RowRange,ListBox".split(","), currentSelection: null, currentComboText: "CellRange" }; } render() { return <div className="container-fluid"> <label>selectionMode{' '}<span id="selectionMode"></span> <wjcInput.ComboBox initialized={this.initCombo.bind(this)} itemsSource={this.state.comboBoxData} text={this.state.currentComboText} textChanged={this.onTextChanged.bind(this)}> </wjcInput.ComboBox> </label> <wjcGrid.FlexGrid alternatingRowStep={0} itemsSource={this.state.data} initialized={this.initializeGrid.bind(this)} selectionChanged={this.onSelectionChanged.bind(this)}></wjcGrid.FlexGrid> <p> Current selection: <span id="currSel">{this.state.currentSelection}</span>. </p> <div> <button className="btn btn-default" onClick={this.onSelectClick.bind(this)}>Select the first four cells</button> <button className="btn btn-default" onClick={this.onListSelectClick.bind(this)}>Select rows 0, 2, and 4</button> </div> </div>; } initCombo(combo) { this.combo = combo; } initializeGrid(flexGrid) { this.flexGrid = flexGrid; this.flexGrid.onSelectionChanged(null); } onTextChanged() { console.log("before============" + this.combo.selectedIndex); this.flexGrid.selectionMode = wjcCore.asEnum(this.combo.selectedIndex, wjGrid.SelectionMode); this.setState({ currentComboText: wjcCore.asEnum(this.combo.selectedIndex, wjGrid.SelectionMode) }); } onSelectionChanged() { this.setState({ currentSelection: wjcCore.format("({row},{col})-({row2},{col2})", this.flexGrid.selection) }); } onRefreshClick() { this.flexGrid.collectionView.refresh(); } onSelectClick() { this.combo.text = "CellRange"; this.flexGrid.selection = new wjGrid.CellRange(0, 0, 1, 1); } onListSelectClick() { this.combo.text = "ListBox"; this.flexGrid.select(0, 0); [0, 2, 4].forEach((index) => { this.flexGrid.rows[index].isSelected = true; }); } } ReactDOM.render(<App />, document.getElementById('app')); <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>Grapecity Wijmo OLAP Pivot Chart Overview</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app'); </script> </head> <body> <div id="app"></div> </body> </html> .wj-flexgrid { max-height: 250px; margin: 10px; } #currSel { font-weight: bold; } body { margin-bottom: 12px; } export function getData() { var countries = 'US,Germany,UK,Japan,Italy,Greece'.split(','), data = []; for (var i = 0; i < countries.length; i++) { data.push({ country: countries[i], downloads: Math.round(Math.random() * 20000), sales: Math.random() * 10000, expenses: Math.random() * 5000 }); } return data; }