如何在服务器端接收KendoGrid serverPaging请求

时间:2014-12-17 18:47:39

标签: .net c#-4.0 kendo-ui kendo-grid sparql

我初始化了一个kendoGrid对象,其中serverPaging设置为true。但是,通过kendoGrid的read属性的datasource属性调用的远程Web服务在每次发出服务器请求时都会加载整个JSON树。此服务发出SPARQL请求,该请求针对本体类型数据库进行查询。我的SPARQL查询是硬编码的;因此,为了接收kendoGrid的页面实例,我需要将页面传递给我的查询。 C#函数如下所示:

public ResponseData[] RetrieveAllColumns()
    {
        DataManagerClient dmsClient = new DataManagerClient();
        QueryRequestContract qryRequest = new QueryRequestContract
        {
            Graph = "someGraphName",
            WithImports = true,
            DataFormatType = DataFormatTypes.JSON,
            Sparql = @"SELECT DISTINCT ?result ?label ?table ?state ?schema ?database ?server
                        WHERE { ?result a database_onto:Column . 
                                ?result rdfs:label ?label . 
                                ?tableVar database_onto:tableHasColumn ?result .
                                ?tableVar rdfs:label ?table . 
                                ?result database_onto:columnHasState ?stateVar .
                                ?stateVar rdfs:label ?state .
                                ?schemaVar database_onto:schemaHasTable ?tableVar .
                                ?schemaVar rdfs:label ?schema .
                                ?databaseVar database_onto:databaseHasSchema ?schemaVar .
                                ?databaseVar rdfs:label ?database .
                                ?serverVar database_onto:serverHasDatabase ?databaseVar .
                                ?serverVar rdfs:label ?server .
                            } ORDER BY (LCASE(?label))" // serverPaging would be added here as OFFSET and LIMIT for the query
        };

        QueryResponseContract qryResponse = dmsClient.Query(qryRequest);
        RDFServiceResponse jsonData = JsonConvert.DeserializeObject<RDFServiceResponse>(qryResponse.ReturnData);
        List<ResponseData> lstRspData = new List<ResponseData>();

        foreach (BindingsObj bndData in jsonData.results.bindings)
        {
            lstRspData.Add(new ResponseData
            {
                Name = Regex.Replace(bndData.label.value, @"\(.*?\)", ""),
                Link = bndData.result.value,
                Table = bndData.table != null ? Regex.Replace(bndData.table.value, @"\(.*?\)", "") : null,
                State = bndData.state != null ? bndData.state.value : null,
                Database = bndData.database != null ? Regex.Replace(bndData.database.value, @"\(.*?\)", "") : null,
                Schemas = bndData.schema != null ? Regex.Replace(bndData.schema.value, @"\(.*?\)", "") : null,
                Server = bndData.server != null ? Regex.Replace(bndData.server.value, @"\(.*?\)", "") : null
            });
        }

        return lstRspData.ToArray();
    }

;其中ResponseData[]是数组模型,RDFServiceResponse是RDF数组模型。

这是我的控制者:

public CountResponse Get()
{
    return this.cmlData.RetrieveColumnTotal();
}

重申我的问题,如何将KendoGrid的数据源分页属性(特定于页面实例和页面大小)传递给我的服务,以便我可以对服务器端查询进行必要的调整?

1 个答案:

答案 0 :(得分:1)

如果您在Kendo UI网格上设置了serverPaging: true,那么skiptakepage会自动作为查询字符串参数附加在您的GET请求的网址中

http://localhost/controller/CountResponse?skip=0&take=100&page=1

您需要做的就是将这些参数按名称添加到控制器操作中,并在服务器端处理它们,这样您只返回客户端请求的数据页。

public CountResponse Get(int skip, int take) {
  return this.cmlData.RetrieveColumnTotal(skip, take);
}