FlexGrid
OData Defer Commits
The default value for this property is false, which causes any changes to the data to be immediately committed to the database.
Features
Sample
Settings
Description
The default value for this property is false, which causes any changes to the data to be immediately committed to the database.
If you set this property to true, any changes to the data (including edits, additions, and removals) will be tracked but not committed to the database until you click Commit button to commit the changes, or Cancel button to discard all pending changes
Source
ODataDeferCommitsController.cs
using System.Data.Entity.Validation; using MvcExplorer.Models; using System; using System.Collections.Generic; using System.Linq; using System.Web.Mvc; using C1.Web.Mvc.Serialization; using C1.Web.Mvc; using System.Data; using System.Data.Entity; using System.Collections; using System.Globalization; namespace MvcExplorer.Controllers { public partial class FlexGridController : Controller { // // GET: /ODataDeferCommits/ private readonly ControlOptions _oDataDeferCommitsSetting = new ControlOptions { Options = new OptionDictionary { {"Defer Commits", new OptionItem{Values = new List<string> {"True", "False"}, CurrentValue = "False"}} } }; public ActionResult ODataDeferCommits(FormCollection collection) { IValueProvider data = collection; if (CallbackManager.CurrentIsCallback) { var request = CallbackManager.GetCurrentCallbackData<CollectionViewRequest<object>>(); if (request != null && request.ExtraRequestData != null) { var extraData = request.ExtraRequestData.Cast<DictionaryEntry>() .ToDictionary(kvp => (string)kvp.Key, kvp => kvp.Value.ToString()); data = new DictionaryValueProvider<string>(extraData, CultureInfo.CurrentCulture); } } _oDataDeferCommitsSetting.LoadPostData(data); ViewBag.DemoOptions = _oDataDeferCommitsSetting; return View(); } } }
ODataDeferCommits.cshtml
@model IEnumerable<Category> @section Styles{ <style> .queryErrorMessage { color: #f00; } </style> } @{ ControlOptions optionsModel = ViewBag.DemoOptions; ViewBag.DemoSettings = true; } @section Scripts{ <script type="text/javascript"> var cv, oDataDeferCommits, minHeight; c1.documentReady(function () { oDataDeferCommits = wijmo.Control.getControl('#oDataDeferCommits'); cv = oDataDeferCommits.collectionView; }); function commitEdits() { cv.commitChanges(function (r) { setQueryMessage('@(Resources.FlexGrid.ODataDeferCommits_Done_Text0)'); }); var isChanged = (cv.itemsEdited && cv.itemsEdited.length); if (isChanged) { setQueryMessage('@(Resources.FlexGrid.ODataDeferCommits_Updating_Text0)'); } else { setQueryMessage('@(Resources.FlexGrid.ODataDeferCommits_No_Change_Text0)'); } } function cancelChanges() { cv.cancelChanges(); setQueryMessage('');//clear message } function setQueryMessage(message, className) { var element = document.getElementById('queryMessage'); element.innerHTML = message; element.className = className; } </script> } <input type="button" value="Commit" class="btn" onclick="commitEdits()" /> <input type="button" value="Cancel" class="btn" onclick="cancelChanges()" /> <span id="queryMessage"></span> @( Html.C1().FlexGrid<Category>() .Id("oDataDeferCommits").AutoGenerateColumns(false) .Columns(columns => columns .Add(c => c.Binding("@odata.id").Header("OData Id").IsReadOnly(true)) .Add(c => c.Binding("@odata.editLink").Header("OData edit link").IsReadOnly(true)) .Add(c => c.Binding("AirlineCode").Header("Airline Code")) .Add(c => c.Binding("Name"))) .BindODataSource(odsb => odsb.ServiceUrl("https://services.odata.org/V4/(S(3vn0jej2dr3ebcgodm1zxcys))/TripPinServiceRW/") .TableName("Airlines") .Keys("AirlineCode") .DeferCommits(Convert.ToBoolean(optionsModel.Options["Defer Commits"].CurrentValue))) ) @section Settings{ @Html.Partial("_OptionsMenu", optionsModel) } @section Description{ <p>@Html.Raw(Resources.FlexGrid.ODataDeferCommits_Description_Text0)</p> <p>@Html.Raw(Resources.FlexGrid.ODataDeferCommits_Description_Text1)</p> } @section Summary{ @Html.Raw(Resources.FlexGrid.ODataDeferCommits_Summary_Text0) }
Documentation