您好,选中整行需要设置选中模式为Row,如果执行多次选择可能会导致多次事件的触发,不过从您提供的代码里没发现这个问题。我按照您的逻辑改了一版代码,参考:
- 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) {
- console.log("查看控制台,selectionChanged被触发了多少次?");
- 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 = 'Row'; // 设置选中行规则
- var view = theGrid.collectionView;//獲得當前視圖
- view.remove(view.currentItem);//移除當前數據(這裡會自動觸發selection-changed 事件,並且觸發多次!)
- theGrid.selection = new wjGrid.CellRange(0, 0); //選中行
- });
- //
- // 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;
- });
- });
- //
- }
复制代码
Demo地址:
https://www.grapecity.com/wijmo/ ... ion/Overview/purejs |