Wijmo 5 - Dynamic DataMap

by Manish Gupta

HTML

<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
<link rel="stylesheet" href="http://cdn.wijmo.com/5.latest/styles/wijmo.min.css">
<script src="http://cdn.wijmo.com/5.latest/controls/wijmo.min.js"></script>
<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>
<div class="container">

  <h1>Dynamic DataMap</h1>

  <p>
    This grid changes the data map for the "City" column
    depending on the row being edited:</p>
  <div id="theGrid"></div>
</div>

JavaScript

onload = function() {

	// create the grid
	var theGrid = new wijmo.grid.FlexGrid('#theGrid', {
    selectionMode: 'Row',
    autoGenerateColumns: false,
    columns: [
    	{ binding: 'country', header: 'Country', dataMap: getCountries() },
      { binding: 'city', header: 'City', dataMap: getCities() },
      { binding: 'downloads', header: 'Downloads' },
      { binding: 'sales', header: 'Sales' }
		],
    itemsSource: getData(),
   
		itemFormatter:function(panel,r,c,cell){
		if(panel.cellType==1){
			if(!wijmo.hasClass(cell,"wj-state-selected") && cell.querySelector(".wj-glyph-down") != null){
				cell.querySelector(".wj-glyph-down").parentElement.style.display="none";
			}
		}
		
	},
    // update cities data map depending on country
    beginningEdit: function(s, e) {
      var col = s.columns[e.col];
      if (col.binding == 'city') {
        switch (s.rows[e.row].dataItem.country) {
          case 'US':
            col.dataMap = ['Washington', 'Miami', 'Seattle'];
            break;
          case 'UK':
            col.dataMap = ['London', 'Oxford', 'Bath'];
            break;
          case 'Japan':
            col.dataMap = ['Tokyio', 'Sendai', 'Kobe'];
            break;
          case 'Greece':
            col.dataMap = ['Athens', 'Santorini', 'Thebes'];
            break;
          case 'Germany':
            col.dataMap = ['Bonn', 'Munich', 'Kiel'];
            break;
          case 'Italy':
            col.dataMap = ['Rome', 'Florence', 'Milan'];
            break;
          default:
            col.dataMap = ['Unknown Country!'];
            break;
        }
      }
    },
	selectionChanging:function(s,e){
		s.itemFormatter=function(panel,r,c,cell){
		if(panel.cellType==1){
			if(!wijmo.hasClass(cell,"wj-state-selected") && cell.querySelector(".wj-glyph-down") != null){
				cell.querySelector(".wj-glyph-down").parentElement.style.display="none";
			}
		}
		}
	},
	
	});

  // some random data
  function getCountries() {
    return...