Kendo ui kendo网格自定义过滤器,带有本地存储

Kendo ui kendo网格自定义过滤器,带有本地存储,kendo-ui,kendo-grid,kendo-asp.net-mvc,Kendo Ui,Kendo Grid,Kendo Asp.net Mvc,我使用的是Kendo UI版本:“2015.1.318”,该版本设置为在消费者离线切换时使用本地存储。 我的问题是,当我使用客户端自定义过滤器时,它总是请求服务器获取数据。如何使用网格的数据源进行过滤(现在是本地存储) 这是我的网格: @(Html.Kendo().Grid<InventoryModel>() .Name("InventoryIndexGrid") .HtmlAttributes(new { @class = "grid", key = "Invent

我使用的是Kendo UI版本:“2015.1.318”,该版本设置为在消费者离线切换时使用本地存储。 我的问题是,当我使用客户端自定义过滤器时,它总是请求服务器获取数据。如何使用网格的数据源进行过滤(现在是本地存储)

这是我的网格:

@(Html.Kendo().Grid<InventoryModel>()
    .Name("InventoryIndexGrid")
    .HtmlAttributes(new { @class = "grid", key = "InventoryItemGrid", @style = "height:auto !important" })
    .Columns(columns =>
    {
        columns.Bound(o => o.ItemDateStr).Title("Inventory Date").HtmlAttributes(new
        { @style = "text-align: center" }).HeaderHtmlAttributes(new { @style = "text-align: center" })
    .ClientTemplate("<a onclick=\"onSelectDate('#=ItemDateStr#\','#=UserNameDisp#','#=TenantID#')\" class='' >#=ItemDateStr#</a>");
columns.Bound(p =>p.InventoryType).Title("Type").Sortable(false).Filterable(false).Width("8%").HtmlAttributes(new { @style = "text-align: center" }).HeaderHtmlAttributes(new {
@style = "text-align: center" });
    columns.Bound(p => p.UserName).Title("Created By").Sortable(false).Filterable(false).Width("82%").HtmlAttributes(new { @style = "text-align: left" }).HeaderHtmlAttributes(new { @style = "text-align: center"     });
    columns.Bound(p => p.UserNameDisp).Hidden(true);
    })
    .ToolBar(toolbar => toolbar.Custom()
    .Text("")
    .HtmlAttributes(new { @Title = "Create new Inventory", id = "btnAddNew", @class = "btn btn-default btn-crm btn-crm-action fa fa-plus-square-o", @style = "padding-top:10px;height:34px; width:40px" }))
    .AutoBind(true)
    .Reorderable(p => p.Columns(true))
    .Resizable(p => p.Columns(true))
    .Pageable(pageable => pageable.Refresh(true))
    .DataSource(dataSource => dataSource.Ajax().PageSize(1000).Model(model => model.Id(p => p.ItemID))
    .Create(update => update.Action("Save", "MealPeriod"))
    .Read(read =>
    {
        read.Action("GetIndex", "Inventory", new { type = "food" });
        read.Data("InventoryIndexGridAdditionalData");
    })).Events(c => c.DataBound("onDataBoundInventoryIndexGrid"))
    )

请帮忙

没有简单的服装。您的数据在本地存储中,但仍将旧数据源保留在网格中。在这里:

.Read(read =>
    {
        read.Action("GetIndex", "Inventory", new { type = "food" });
        read.Data("InventoryIndexGridAdditionalData");
    })
您正试图从
Inventory/GetIndex
获取数据,但您的js本地存储中已经有了数据,因此我认为它首先会对相同的数据发出两个请求

我建议用JavaScript重写网格,并使用存储中的数据,如下所示:

var keyLocalStorage = 'offline_data_inventory_' + $('#TenantID').val() + '_'     + type + '_' + $('#ItemDate').val();
var tempDataInventory = setaJs.getLocalStorage(keyLocalStorage);

$("#InventoryIndexGrid  ").kendoGrid({
    dataSource: {
        data: tempDataInventory,
        ...
    },
   ...
});
否则,您将使用大量丑陋的JavaScript代码进行过滤和其他数据操作,并且在将来更改/添加任何内容时会遇到问题


下面是JS中本地数据网格的示例:

下次用户访问页面时,是否希望对网格进行预过滤?如果是这样,您可以使用事件和,因为您已经使用了localstorage。但是,我不确定我是否正确理解了您的问题?我想使用自定义筛选器搜索该网格中的数据。网格数据现在从本地存储加载。非常感谢
var keyLocalStorage = 'offline_data_inventory_' + $('#TenantID').val() + '_'     + type + '_' + $('#ItemDate').val();
var tempDataInventory = setaJs.getLocalStorage(keyLocalStorage);

$("#InventoryIndexGrid  ").kendoGrid({
    dataSource: {
        data: tempDataInventory,
        ...
    },
   ...
});