FlexGrid
OData サービス連結
機能
サンプル
ODataCollectionView
ODataVirtualCollectionView
設定
説明
この例は、FlexGrid と OData サービスを連結する方法を示します。
ODataCollectionView クラスは、コントロールをODataソースに接続する簡単な方法を提供します。 ODataCollectionView を作成すると、ソースのデータのロードが開始されます。 ODataVirtualCollectionView は、 ODataCollectionView を拡張して、データのオンデマンドロードを提供します。 サーバーからデータを自動的にロードしません。 代わりに、 setWindow メソッドに依存して、データフラグメント(ウィンドウ)をオンデマンドでロードします。 上記のグリッドは、両方のクラスがどのように機能するかを示しています。 上部のグリッドに、徐々にロードされるデータが表示されることに注意してください。 下部のグリッドにはすぐに完全なレコードカウントが表示されますが、下にスクロールするまでデータはロードされません。
ソース
ODataBindController.cs
using C1.Web.Mvc;
using C1.Web.Mvc.Serialization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using MvcExplorer.Models;
using System.Collections.Generic;
namespace MvcExplorer.Controllers
{
public partial class FlexGridController : Controller
{
private readonly ControlOptions _oDataBindSetting = new ControlOptions
{
Options = new OptionDictionary
{
{"Sort On Server", new OptionItem{Values = new List<string> {"True", "False"}, CurrentValue = "True"}},
{"Filter On Server", new OptionItem{Values = new List<string> {"True", "False"}, CurrentValue = "True"}}
}
};
public ActionResult ODataBind(IFormCollection collection)
{
_oDataBindSetting.LoadPostData(collection);
ViewBag.DemoOptions = _oDataBindSetting;
// NETCORE 3.0 doesn't not fully support ODataServer yet, so the local source is not working.
#if ODATA_SERVER && !NETCORE31
// C1WEB-28691: Set to ReadOnly for all like in Wijmo sample, due to adding/updating/deleting doesn't work properly for all.
ViewBag.IsReadOnly = true;
#else
ViewBag.IsReadOnly = true;
#endif
return View();
}
}
}
ODataBind.cshtml
@{
ControlOptions optionsModel = ViewBag.DemoOptions;
ViewBag.DemoSettings = true;
bool isReadOnly = ViewBag.IsReadOnly;
}
@if (isReadOnly)
{
<h4>ODataCollectionView</h4>
<p id="itemCount"></p>
<c1-flex-grid id="ODataCollectionView" is-read-only="true" allow-add-new="false" allow-delete="false" style="height:400px" loaded-rows="oDataCVLoaded">
<c1-odata-source service-url="https://services.odata.org/Northwind/Northwind.svc" table-name="Orders" keys="OrderID"
sort-on-server="@(Convert.ToBoolean(optionsModel.Options["Sort On Server"].CurrentValue))"
filter-on-server="@(Convert.ToBoolean(optionsModel.Options["Filter On Server"].CurrentValue))"></c1-odata-source>
<c1-flex-grid-filter default-filter-type="Both"></c1-flex-grid-filter>
</c1-flex-grid>
<h4>ODataVirtualCollectionView</h4>
<p id="totalItemCount"></p>
<c1-flex-grid id="ODataVirtualCollectionView" is-read-only="true" allow-add-new="false" allow-delete="false" style="height:400px" scroll-position-changed="scrollPositionChanged" loaded-rows="oDataVCVLoaded">
<c1-odata-virtual-source service-url="https://services.odata.org/Northwind/Northwind.svc" table-name="Orders" keys="OrderID"></c1-odata-virtual-source>
<c1-flex-grid-filter default-filter-type="Both"></c1-flex-grid-filter>
</c1-flex-grid>
}
else
{
<h4>ODataCollectionView</h4>
<p id="itemCount"></p>
<c1-flex-grid id="ODataCollectionView" allow-add-new="true" allow-delete="true" style="height:400px" loaded-rows="oDataCVLoaded">
<c1-odata-source service-url="~/MyNorthWind" table-name="Orders" keys="OrderID"
sort-on-server="@(Convert.ToBoolean(optionsModel.Options["Sort On Server"].CurrentValue))"
filter-on-server="@(Convert.ToBoolean(optionsModel.Options["Filter On Server"].CurrentValue))"></c1-odata-source>
<c1-flex-grid-filter default-filter-type="Both"></c1-flex-grid-filter>
</c1-flex-grid>
<h4>ODataVirtualCollectionView</h4>
<p id="totalItemCount"></p>
<c1-flex-grid id="ODataVirtualCollectionView" allow-add-new="true" allow-delete="true" style="height:400px" scroll-position-changed="scrollPositionChanged" loaded-rows="oDataVCVLoaded">
<c1-odata-virtual-source service-url="~/MyNorthWind" table-name="Orders" keys="OrderID"></c1-odata-virtual-source>
<c1-flex-grid-filter default-filter-type="Both"></c1-flex-grid-filter>
</c1-flex-grid>
}
@section Scripts{
<script type="text/javascript">
function customChangeSortOnServer(grid, value) {
if (grid && grid.collectionView) {
grid.collectionView.sortOnServer = value;
}
}
function customChangeFilterOnServer(grid, value) {
if (grid && grid.collectionView) {
grid.collectionView.filterOnServer = value;
}
}
function scrollPositionChanged(grid) {
var rng = grid.viewRange;
grid.collectionView.setWindow(rng.row, rng.row2);
}
function oDataCVLoaded(grid, e) {
var el = document.getElementById('itemCount');
el.innerHTML = wijmo.format('{length:n0} items', grid.rows);
}
function oDataVCVLoaded(grid, e) {
var el = document.getElementById('totalItemCount');
el.innerHTML = wijmo.format('{length:n0} items', grid.rows);
}
</script>
}
@section Settings{
@await Html.PartialAsync("_OptionsMenu", optionsModel)
}
@section Description{
<p>@Html.Raw(FlexGridRes.ODataBind_Text0)</p>
<p>@Html.Raw(FlexGridRes.ODataBind_Text1)</p>
}
マニュアル