Grid.Mvc.Ajax扩展网格初始化 [英] Grid.Mvc.Ajax extension grid initialization

查看:603
本文介绍了Grid.Mvc.Ajax扩展网格初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是很新的使用jQuery和放大器的Web GUI开发; Ajax和我想要得到的NuGet包Grid.MVC.Ajax工作。自述文件规定如下:

Hi I'm very new to Web GUI dev using JQuery & Ajax and I'm trying to get the nuget package Grid.MVC.Ajax working. The readme states the following:

Follow thse steps to use Grid.Mvc.Ajax

1. Include ~/Scripts/gridmvc-ext.js after your ~/Scripts/grimvc.js include.

2. Include ~/Content/ladda-bootstrap/ladda-themeless.min.css CSS after your Bootstrap CSS/LESS include.

3. Include Ladda-bootstrap Javascript via the ~/Scripts/ladda-bootstrap/ladda.min.js
 and ~/Scripts/ladda-bootstrap/spin.min.js.

4. Create a view model for you grid data, for example:
public Person
{
   public string FirstName { get; set; }
   public string LastName { get; set; }
}

5. Add a Razor partial view for your grid data that uses an AjaxGrid<T> as the model type, 
Where T is your view model type:

@using GridMvc.Html
@using GridMvc.Sorting
@model Grid.Mvc.Ajax.GridExtensions.AjaxGrid<Models.Person>

@Html.Grid(Model).Columns(columns =>
    {
      columns.Add(c => c.FirstName);
      columns.Add(c => c.LastName);
    }).Sortable(true).WithPaging(10)

6. Add a controller action to retrieve the data for the first page of data that includes the Ajax pager HTML:

 public JsonResult Persons()
        {
            var vm = new List<Person>()
            {
                new Person() { FirstName = "John", LastName = "Doe" }
            }
            .AsQueryable();
            var ajaxGridFactory = new Grid.Mvc.Ajax.GridExtensions.AjaxGridFactory();
            var grid = ajaxGridFactory.CreateAjaxGrid(vm, 1, false);
        }

7. Add a controller action to retrieve data for paged items that returns a JsonResult without the Ajax page HTML:

 public JsonResult PersonsPaged(int page)
        {
            var vm = new List<Person>()
            {
                new Person() { FirstName = "John", LastName = "Doe" }
            }
            .AsQueryable();
            var ajaxGridFactory = new Grid.Mvc.Ajax.GridExtensions.AjaxGridFactory();
            var grid = ajaxGridFactory.CreateAjaxGrid(vm, page, true);
        }

8. Call the ajaxify Grid.Mvc.Ajax JavaScript plug-in method setting the non-paged and paged controller actions and optionally a form
to apply additional filtering to the grid. All input and select elements in the given form will be passed into your paged and non-paged controller actions:

 $(".grid-mvc").gridmvc().ajaxify({
                getPagedData: '/Home/Persons',
                getData : '/Home/PersonsPaged',
                gridFilterForm: $("#gridFilters")
            });

我已经设置好了的说,但我有在第8步问题,我不知道如何调用JavaScript code,以填充网格。我附上上面的$(文件)。就绪呼叫,但似乎并没有工作:-(任何帮助将是非常美联社preciated。谢谢

I have set things up as stated but I'm having problems in step 8. as I'm not sure how to call the JavaScript code in order to populate the grid. I have enclosed the above in a $(document).ready call but that doesn't seem to work :-( Any help would be much appreciated. Thanks

推荐答案

您有两种选择: loadPage refreshFullPage

这将调用您的PersonsPaged方式:

this will call your PersonsPaged method:

$(".grid-mvc")
   .gridmvc()
   .loadPage()

和这将调用你的人的方法。

and this will call your Persons method.

$(".grid-mvc")
   .gridmvc()
   .refreshFullGrid()

此外,在你的个人和PersonsPaged可以返回这样的JSON:

also, in your Persons and PersonsPaged you can return a JSON like this:

public ActionResult Persons()
{
    var vm = new List<Person>()
    {
        new Person() { FirstName = "John", LastName = "Doe" }
    }.AsQueryable();

    var ajaxGridFactory = new AjaxGridFactory();
    var grid = ajaxGridFactory.CreateAjaxGrid(vm, 1, false);

    return Json(new { Html = grid.ToJson("_YourPartialWithGridCode", this), grid.HasItems },JsonRequestBehavior.AllowGet);
}

这篇关于Grid.Mvc.Ajax扩展网格初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆