0

使用 Kendo-Angular 指令

<div kendo-grid k-data-source="MySource" 
   k-filterable="true" k-pageable="true"></div>

将剑道数据源作为我的范围的一部分

$scope.MySource = new kendo.data.DataSource({
   transport:{
      read : {
         url:"/MyUrl"
      }
   },
   schema:{
      data: "data"
      total:function(response){return response.total},
      model:{
         fields:{
            LastName:{type:"string"}
         }
      }
   },
   pageSize: 10,
   serverFiltering: true,
   serverPaging:true
})

数据加载正常(尽管我有一个字符串问题,它没有分页通过可能与后端更相关的第 4 页。

我所做的只是调用一个 asp.net 控制器路由来返回数据,正如我所提到的,分页似乎工作正常,但是当我尝试使用可过滤的 'get' 查询字符串看起来有点像这样......

/MyUrl?take=10&skip=0&page=1&pageSize=10&filter%5Bfilters%5D%5B0%5Bfield%5D=LastName&filter%5Bfilters%5D.........value%5D=Smith

我的控制器看起来像这样

public JsonResult MyUrl(int pageSize = 10, int skip = 10, string sort = "", string filter="")
{
    // return jsonresult
}

该 URL 是怎么回事,我的控制器设置是否正确?我需要为默认剑道网格设置参数映射吗?

4

2 回答 2

0

Create a class like this

public class PagingOption
{
    public PagingOption()
    {
        PageSizes = new List<int>();`enter code here`
    }

    /// <summary>
    /// Specifies the current page number.
    /// </summary>`enter code here`
    public int take { get; set; }

    /// <summary>
    /// Specifies the number of items to show in a page.
    /// </summary>
    public int skip { get; set; }
    public int page { get; set; }
    public int pagesize { get; set; }
    public List<SortDescription> sort  { get; set; }

    /// <summary>
    /// Specifies different page sizes.
    /// </summary>
    public IList<int> PageSizes { get; set; }
}

public class SortDescription
{
    public string field { get; set; }
    public string dir { get; set; }
}

and pass it as a parameter to your web call on server side

public JsonResult MyUrl(PagingOption pagingoption)
{
    // return jsonresult
}

it will convert the query paramters to paging option class

于 2014-04-24T08:30:25.583 回答
0

这就是默认参数映射的作用——将当前数据源状态传递给 jQuery。您可以将状态作为 JSON 传递:

transport:{
  read : {
     url:"/MyUrl",
     type: "POST",
     contentType: "application/json"
  },
  parameterMap: function(options) {
     return JSON.stringify(options);
  }
},
于 2014-02-24T10:16:20.333 回答