# Wijmo_React_Grid_Immutable

## Content

<div class="content__tsd">
						<div style="display:flex;justify-content:space-between;align-items:center">
							<h1>
								wijmo.react.grid.immutable Module
							</h1>
						</div>
						<section class="tsd-comment">
							<div class="tsd-comment">
								<div class="lead">
									<p>Wijmo interop module for <a href="https://reactjs.org/" target="_blank">React</a>,
										which provides the <a href="wijmo_react_grid_immutable.html#immutabilityprovider">wijmo.react.grid.immutable.ImmutabilityProvider</a> component and
										its accompanying stuff.
										It allows you to use <a href="wijmo_react_grid.html#flexgrid">wijmo.react.grid.FlexGrid</a> component with immutable data sources,
										while keeping all <strong>FlexGrid</strong> data editing and data transformation capabilities.
										It can be used to incorporate full-featured datagrid components in applications driven
										by state management systems that require data immutability, such as
									<a href="https://redux.js.org/" target="_blank">Redux</a>.</p>
								</div>
							</div>
						</section>
						<section class="tsd-index-group">
							<section class="tsd-index-panel">
								<div class="tsd-index-content">
									<section class="tsd-index-section ">
										<div class="title">
											<div class="gc_api_tree-item_icon_img_wrapper">
												<div class="gc_api_tree-item_icon_img" data-expand="true">
												</div>
											</div>
											<h3>
												Variables
											</h3>
										</div>
										<ul class="tsd-index-list">
											<li class="tsd-kind-variable tsd-parent-kind-external-module"><a href="wijmo_react_grid_immutable.html#immutabilityprovider" class="tsd-kind-icon">Immutability<wbr>Provider</a></li>
										</ul>
									</section>
								</div>
							</section>
						</section>
						<section class="tsd-panel-group tsd-member-group ">
							<h2>Variables</h2>
							<section class="tsd-panel tsd-member tsd-kind-variable tsd-parent-kind-external-module">
								<a name="immutabilityprovider" class="tsd-anchor"></a>
								<h3><span class="tsd-flag ts-flagConst">Const</span> ImmutabilityProvider</h3>
								<div class="tsd-signature tsd-kind-icon">Immutability<wbr>Provider<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">WjForwardRefExoticComponent</span><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">ImmutabilityProviderProps</span><span class="tsd-signature-symbol">&gt;</span></div>
								<aside class="tsd-sources">
								</aside>
								<div class="tsd-comment">
									<div class="lead">
										<p>React component that represents a <a href="../classes/wijmo_grid_immutable.immutabilityprovider.html">wijmo.grid.immutable.ImmutabilityProvider</a> in a <a href="wijmo_react_grid.html#flexgrid">wijmo.react.grid.FlexGrid</a>.</p>
									</div>
									<p>The <a href="wijmo_react_grid_immutable.html#immutabilityprovider">wijmo.react.grid.immutable.ImmutabilityProvider</a> component,
										being added to a <a href="wijmo_react_grid.html#flexgrid">wijmo.react.grid.FlexGrid</a> component,
										allows the latter to perform data edits without mutating the underlying
										data. Instead, this class provides a data change event, which can be used to dispatch
										change actions to the global <em>Store</em>, such as a
									<a href="https://redux.js.org/" target="_blank">Redux</a> <em>Store</em>.</p>
									<p>The controlled <strong>FlexGrid</strong> control should not specify its <strong>itemsSource</strong>. Instead, the
										<strong>itemsSource</strong> property of this class instance should be assigned with the
									immutable array from the <em>Store</em>, which grid will display and edit.</p>
									<p>When a user edits data via the grid,
										the <a href="../classes/wijmo_grid_immutable.immutabilityprovider.html#datachanged">wijmo.grid.immutable.ImmutabilityProvider.dataChanged</a> event is triggered,
										bringing all the necessary information to you about the change (which item is affected,
										if item was changed or added or deleted, and so on). This event should be used to dispatch
									corresponding data change actions to the <em>Store</em>.</p>
									<p>Note that <strong>FlexGrid</strong> edits data on a row level basis, which means that you can change multiple
										cell values in the same row, and only after you move focus out of the row, all the changes
										to the row will be applied simultaneously. Or you can press the <em>Cancel</em> key to cancel all
									the changes in the row. The same is true for adding a row into the datagrid.</p>
									<p>Note also that some changes like pasting a text into the datagrid, or deleting rows,
										can affect multiple rows. In this case <strong>ImmutabilityProvider</strong> will trigger
										the <a href="../classes/wijmo_grid_immutable.immutabilityprovider.html#datachanged">wijmo.grid.immutable.ImmutabilityProvider.dataChanged</a> event
										multiple times, separately for each affected row. This simplifies data change processing
									in the <em>Store</em> reducers.</p>
									<p>This example demonstrates a fully editable <strong>FlexGrid</strong> component, with an associated
										<strong>ImmutabilityProvider</strong> component bound to an array from the <em>Redux Store</em>. The dataChanged
										event handler dispatches corresponding data change actions to the <em>Store</em>.
										The example assumes that <em>Redux Store</em> data and action creator functions are bound
									to the presentation component as properties, using the <em>react-redux</em> <em>connect</em> method.</p>
									<pre><code class="language-typescript">import { DataChangeEventArgs, DataChangeAction } from '@mescius/wijmo.grid.immutable';
import { ImmutabilityProvider } from '@mescius/wijmo.react.grid.immutable';
import { FlexGrid } from '@mescius/wijmo.react.grid';

export class GridView extends React.Component&lt;any, any&gt; {
  render() {
    return &lt;FlexGrid allowAddNew allowDelete&gt;
       &lt;ImmutabilityProvider
          itemsSource={this.props.items}
          dataChanged={this.onGridDataChanged} /&gt;
    &lt;/FlexGrid&gt;
  }
  onGridDataChanged(s: ImmutabilityProvider, e: DataChangeEventArgs) {
      switch (e.action) {
          case DataChangeAction.Add:
              this.props.addItemAction(e.newItem);
              break;
          case DataChangeAction.Remove:
              this.props.removeItemAction(e.newItem, e.itemIndex);
              break;
          case DataChangeAction.Change:
              this.props.changeItemAction(e.newItem, e.itemIndex);
              break;
      }
  }
}</code></pre>
								</div>
							</section>
						</section>
					</div>