KB - Wijmo 5 - Edit Row With Popup

Object - FlexGrid Properties: - ListBox selector - Country text filter - FlexGrid filter w/ CSS

by Joel Parks

HTML

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

  <h1>
    FlexGrid Edit Row With Popup
  </h1>
    
  <button id="rowCopy" class="btn btn-primary" style="margin-bottom:10px;">
    Edit Row
  </button>
  <div id="popup">
    <div class="wj-dialog-header">
      Showing Popup
    </div>
    <div class="wj-dialog-body" tabindex="-1">
      <div id="countryComboBox"></div>
    </div>
    <div class="wj-dialog-footer">
      <button class="btn btn-primary wj-hide-ok">Save</button>
      <button class="btn btn-default wj-hide">Cancel</button>  
    </div>
  </div>

  <div id="flexGrid" class="custom-icons" style="font-family:Courier New"></div>

CSS

.wj-flexgrid {
  max-height: 250px;
  margin-bottom: 12px;
}

.header {
  display: inline-block;
  width: 150px;
  text-align: right;
  font-weight: normal;
}

// Changes the icon for filtering the grid
.custom-icons .wj-glyph-filter {
    background-image:url('http://icons.iconseeker.com/png/fullsize/aspnet/filter-1.png');
    background-repeat: no-repeat;
    background-position: bottom right;
    margin-top: 4px;
    width: 1em; height: 1em;
    border: none;
}
.custom-icons .wj-glyph-filter:after {
    display: none;
}
/* make active filter images 25% larger */
.custom-icons .wj-filter-on .wj-glyph-filter {
    transform: scale(1.25)
}

JavaScript

onload = function() {

  // Creates a vector of strings, and a data variable to hold a list of items
  var countries = 'US,Germany,UK,Japan,Italy,Greece'.split(','),
    data = [];
  for (var i = 0; i < 100; i++) {
    // Creates attributes and assigns values to each of them for each item in the 'data' variable
    data.push({
      id: i,
      country: countries[i%countries.length],
      active: i % 5 != 0,
      downloads: Math.round(Math.random() * 200000),
      sales: Math.random() * 100000,
      expenses: Math.random() * 50000
    });
  }

  // Creates a view for a ListBox and FlexGrid to manipulate the same data
  var gridView = new wijmo.collections.CollectionView(data);

  // Binds the grid to a Wijmo FlexGrid array
  var gridArray = new wijmo.grid.FlexGrid('#flexGrid', {
    // Changes the header of the binded value to what is stored in the 'header' attribute
    // You can leave columns out of the table; the 'Active' column is left out
    autoGenerateColumns: false,
    isReadOnly: true,
    columns: [{
      binding: "id",
      header: "ID"
    }, {
      binding: "country",
      header: "COUNTRY",
      // StarWidth expands/contracts a field so that the FlexGrid isn't too wide/narrow
      width: "*"
    }, {
      binding: "downloads",
      header: "DOWNLOADS"
    }, {
      binding: "sales",
      header: "SALES"
    }, {
      binding: "expenses",
      header: "EXPENSES"
    }],
    itemsSource: gridView,
    allowDragging: 2,
    selectionMode: 3
  });
  
  var countryComboBox1 = new wijmo.input.ComboBox('#countryComboBox');
  countryComboBox1.itemsSource = countries;
  countryComboBox1.isEditable = true;
  
  // Popup controls
  var popup = new wijmo.input.Popup('#popup');
  document.getElementById('rowCopy').addEventListener('click', function() {
  	popup.show(true, function(sender) {
      switch (sender.dialogResult) {
        case 'wj-hide-ok':
        	gridArray.selectedRows[0].dataItem.country = countryComboBox1.selectedValue;
    ...