在asp.net中使用默认属性创建kendo网格

时间:2017-10-20 17:31:17

标签: c# kendo-ui kendo-grid

我使用kendo ASP.NET MVC并且我经常使用kendo网格。大多数时候我设置相同的属性,如使用自定义消息过滤,分组,分页等。我想知道是否有办法在某处设置此默认设置或为某些类似的kendo网格创建某种包装。

1 个答案:

答案 0 :(得分:3)

我为网格,下拉菜单和日期选择器制作了几个Html扩展程序,我已经通过这种方式清理了很多html。另外,我已插入语言设置和全局事件。我给你一个我的一般搜索结果网格的例子作为指南。

public static Kendo.Mvc.UI.Fluent.GridBuilder<T> SearchConfigGrid<T>(this HtmlHelper helper)
        where T : class
    {
        var gcw = "GridCommandWord";
        return helper.Kendo().Grid<T>()
            .Navigatable()
            .Scrollable(s => s.Enabled(true).Height("auto"))
            .HtmlAttributes(new { @class = "hide-vertical-scrollbar"})
            .NoRecords(_resources.GetResource(gcw, "NoRecordsFound"))
            .Groupable(groupable => groupable.Messages(m => m.Empty(_resources.GetResource(gcw, "GroupableMessage"))))
            .Sortable(sortable => sortable
                .SortMode(GridSortMode.MultipleColumn))
            .Filterable(filterable => filterable
                .Extra(false)
                .Operators(operators => operators
                    .ForString(str => str.Clear()
                        .StartsWith(_resources.GetResource(gcw, "StartsWith"))
                        .Contains(_resources.GetResource(gcw, "Contains"))
                        .IsEqualTo(_resources.GetResource(gcw, "IsEqualTo"))
                        .IsNotEqualTo(_resources.GetResource(gcw, "IsNotEqualTo")))
                    .ForDate(dt => dt.Clear()
                        .IsGreaterThan(_resources.GetResource(gcw, "IsGreaterThan"))
                        .IsGreaterThanOrEqualTo(_resources.GetResource(gcw, "IsGreaterThanOrEqualTo"))
                        .IsLessThan(_resources.GetResource(gcw, "IsLessThan"))
                        .IsLessThanOrEqualTo(_resources.GetResource(gcw, "IsLessThanOrEqualTo")))
                    .ForNumber(dt => dt.Clear()
                        .IsEqualTo(_resources.GetResource(gcw, "IsEqualTo"))
                        .IsNotEqualTo(_resources.GetResource(gcw, "IsNotEqualTo"))
                        .IsGreaterThan(_resources.GetResource(gcw, "IsGreaterThan"))
                        .IsGreaterThanOrEqualTo(_resources.GetResource(gcw, "IsGreaterThanOrEqualTo"))
                        .IsLessThan(_resources.GetResource(gcw, "IsLessThan"))
                        .IsLessThanOrEqualTo(_resources.GetResource(gcw, "IsLessThanOrEqualTo"))))
                .Messages(m => m.Info(_resources.GetResource(gcw, "Info"))
                    .And(_resources.GetResource(gcw, "And"))
                    .Or(_resources.GetResource(gcw, "Or"))
                    .Clear(_resources.GetResource(gcw, "Clear"))
                    .Filter(_resources.GetResource(gcw, "Filter"))
                    .CheckAll(_resources.GetResource(gcw, "CheckAll"))
                    .IsFalse("&nbsp;" + _resources.GetResource(gcw, "No"))
                    .IsTrue("&nbsp;" + _resources.GetResource(gcw, "Yes") + "&nbsp;&nbsp;&nbsp;")
                    .Info(_resources.GetResource(gcw, "ShowRecords"))
                    .SelectedItemsFormat(_resources.GetResource(gcw, "SelectedItemsFormat"))))
            .Pageable(pageable => pageable
                .Refresh(true)
                .PageSizes(true)
                .ButtonCount(5)
                .Messages(m => m
                    .Display(_resources.GetResource(gcw, "Display"))
                    .ItemsPerPage(_resources.GetResource(gcw, "ItemsPerPage"))
                    .Empty(_resources.GetResource(gcw, "Empty"))
                    .Page(_resources.GetResource(gcw, "Page"))
                    .Of(_resources.GetResource(gcw, "Of"))
                    .First(_resources.GetResource(gcw, "First"))
                    .Previous(_resources.GetResource(gcw, "Previous"))
                    .Next(_resources.GetResource(gcw, "Next"))
                    .Last(_resources.GetResource(gcw, "Last"))
                    .Refresh(_resources.GetResource(gcw, "Refresh"))
                    .MorePages(_resources.GetResource(gcw, "MorePages"))));
    }