0

を実装しましたKendoUI Grid

でのGrid実装は次のとおりですView

@(Html.Kendo().Grid<Example.Web.UI.ViewModels.ExampleItem>()
.Name("ExampleGrid")
.Columns(columns =>
{
    columns.Bound(p => p.Name);
    columns.Bound(p => p.Label);
    columns.Bound(p => p.Type);
    columns.Bound(p => p.InputType);

    columns.ForeignKey(p => p.ParentId, (System.Collections.IEnumerable)ViewData["items"], "Id", "Name").Title("Parent");

    columns.Command(command => { command.Edit(); command.Destroy(); });
})
.Scrollable()
.Groupable()
.Sortable()
.Pageable(pageable => pageable
    .Refresh(true)
    .PageSizes(true)
    .ButtonCount(5))

.ToolBar(toolbar => toolbar.Create())
.Editable(editable => editable.Mode(GridEditMode.PopUp))
.DataSource(dataSource => dataSource
    .Ajax()
    .PageSize(20)
    .Events(events => events.Error("error_handler"))
    .Model(model =>
            {
                model.Id(p => p.Id);
                model.Field(p => p.Id).DefaultValue(Guid.NewGuid());
                model.Field(p => p.ParentId).DefaultValue(null);
            })
    .Create(update => update.Action("EditingPopup_Create", "Example"))
    .Read(read => read.Action("EditingPopup_Read", "Example"))
    .Update(update => update.Action("EditingPopup_Update", "Example"))
    .Destroy(update => update.Action("EditingPopup_Destroy", "Example"))
)
)

ExampeItemモデルは次のとおりです。

public class ExampleItem
{
    [ScaffoldColumn(false)]
    public Guid Id { get; set; }

    public string Name { get; set; }

    public string Label { get; set; }

    public string Type { get; set; }

    [DisplayName("Input Type")]
    public string InputType { get; set; }

    public ExampleItem Parent { get; set; }

    public Guid ParentId { get; set; }
}

Controllerは次のように外部キー項目を設定しました:

ViewData["items"] = exampleItems; // This is a List<ExampleItem>

ただし、がロードされると、Parent列は空になりますGrid。これはGuid、ID のデータ型として a を使用したためです。

そこで、ビューModelを次のように変更しました。

public class ExampleItem
{
    [ScaffoldColumn(false)]
    public int Id { get; set; }

    public string Name { get; set; }

    public string Label { get; set; }

    public string Type { get; set; }

    [DisplayName("Input Type")]
    public string InputType { get; set; }

    public ExampleItem Parent { get; set; }

    public int? ParentId { get; set; }
}

そして今、すべてが機能します。質問は次のとおりです。

が外部キー フィールドのデータ型を好まKendo UI Gridないのはなぜですか? Guidこれを修正する方法はありますか?

私も astringを使ってみましたが、それもうまくいきませんでした。

UI コンポーネントが s でより適切に機能するように、追加のライブラリをインストールする必要があるGuidのでしょうか?

Guidレコードが別のサーバーに移行される可能性があり、ID が一意である必要があるため、ID を型にする必要があります。

4

0 に答える 0