首页 文章

如何使用新数据刷新kendo网格

提问于
浏览 1257 次
0

加载kendo网格后,我想使用点击按钮刷新/重新加载网格 .

控制器:

using Kendo.Mvc;
    using Kendo.Mvc.Extensions;
    using Kendo.Mvc.Infrastructure;
    using Kendo.Mvc.UI;

    public ActionResult FollowUpGrid_Read([DataSourceRequest]DataSourceRequest request, string name, string id)
{
List<vmFollowUpGrid> FUPList = new List<vmFollowUpGrid>();
FUPList = (from u in db.usrUserBldgLists 
                join e in db.entEntities on u.EntID equals e.EntID
                join d in db.entDistricts on e.FANo equals d.DistNo
                join ed in db.entDistricts on e.OANo equals ed.DistNo
                join b in db.entBuildings on e.OBNo equals b.BuildNo
                where u.UserID == "A1036719" && u.FANO == id
                select new vmFollowUpGrid { FANo = u.FANO, FAName = d.DistrictName, OANo = u.OANO, District = ed.DistrictName, OBNo = u.OBNo, Building = b.BuildName}).Take(50).ToList();
var FUList = FUPList.ToDataSourceResult(request);
return Json(FUList, JsonRequestBehavior.AllowGet);                         
}

cshtml页面:

@(Html.Kendo().Grid<MDEFollowUp.Models.vmFollowUpGrid>()
.Name("FollowUpGrid")
.Columns(columns =>
{
    columns.Bound(p => p.FANo);
    columns.Bound(p => p.FAName);
    columns.Bound(p => p.OANo);
    columns.Bound(p => p.District);
    columns.Bound(p => p.OBNo);
    columns.Bound(p => p.Building);
})
   .Pageable(pageable => pageable
            .Refresh(true)
            .PageSizes(true)
            .ButtonCount(5))
    .Sortable()
    .Scrollable()
    .Filterable()
    .DataSource(dataSource => dataSource
        .Ajax()
        .PageSize(20)
                .Read(read => read.Action("FollowUpGrid_Read", "FollowUp").Data("additionalAgencyInfo")))
        )

然后按一下按钮单击事件以使用新数据刷新网格,但这似乎无法识别网格分配 .

$("#btnclick").click(function () {

        var grid = $("#FollowUpGrid").data("tGrid");
        var params = {
            name: "Agency",
            id: "63190"
        };
        var dataSource = new kendo.data.DataSource({ data: params });
        //grid.rebind(params);
        grid.setDataSource(dataSource);
    })

我应该如何在按钮中分配网格来完成此操作?

1 回答

  • 2

    在描述的场景中有两个主要任务要处理:

    • dataSource.data 应该指向一个数组,而不是一个对象

    • 如果新数据将包含完全不同的字段,您还需要替换Grid列

    设置新DataSource和新列的可能方法是通过setOptions .

    这是一个例子:

    http://dojo.telerik.com/oWahO

    UPDATE

    如果重新加载数据后列将保持不变,则可以使用以下方法:

    $("#btnclick").click(function () {
        var grid = $("#FollowUpGrid").data("tGrid");
        var params = {
            name: "Agency",
            id: "63190"
        };
        grid.dataSource.read(params);
    })
    

    这会将 nameid 参数传递给action方法,并保留现有的DataSource实例及其设置 .

    http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#methods-read

相关问题