Wijmo 5 - FlexGrid

by Troy Taylor

HTML

<script src="http://cdn.wijmo.com/5.latest/controls/wijmo.min.js"></script>
<link rel="stylesheet" href="http://cdn.wijmo.com/5.latest/styles/wijmo.min.css">
<script src="http://cdn.wijmo.com/5.latest/controls/wijmo.input.min.js"></script>
<script src="http://cdn.wijmo.com/5.latest/controls/wijmo.grid.min.js"></script>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<script src="http://cdn.wijmo.com/5.latest/controls/wijmo.grid.filter.min.js"></script>
<div class="container">

  <h1>
   FlexGrid cell selection
  </h1>
  <p>
    Prevent cell selection from changing when a sort is applied to the FlexGrid. The coordinates of the selection will not change, but the data in the selected cell will change upon sort.
  </p>
  <div id="theGrid"></div>

</div>

CSS

.wj-flexgrid {
  height: 350px; 
}

JavaScript

// create some random data
  var countries = 'US,Germany,UK,Japan,Italy,Greece'.split(','),
    data = [];
  for (var i = 0; i < countries.length*2; i++) {
    data.push({
      country: countries[i%countries.length],
      downloads: Math.round(Math.random() * 20000),
      sales: Math.random() * 10000,
      expenses: Math.random() * 5000
    });
  }

  // initialize a grid in code
  var grid = new wijmo.grid.FlexGrid('#theGrid', {
  	autoGenerateColumns: false,
    itemsSource: data,
    selectionMode: "Cell",
    columns: [
      { binding: 'country', header: 'Country' },
      { binding: 'downloads', header: 'Downloads' },
      { binding: 'sales', header: 'Sales', format: 'c' },
      { binding: 'expenses', header: 'Expenses', format: 'c' }
    ],
    selectionChanging: function (s, e) {
      
      // prevent selection from changing if any sort has been applied to the CV
      var sd = s.collectionView.sortDescriptions;
      if (sd.length != 0) {
      	e.cancel = true;
      }
    },
    selectionChanged: function (s, e) {
    	console.log('selection has been changed');
    }
  });

	var filter = new wijmo.grid.filter.FlexGridFilter(grid);