目前我正在尝试向Kendo Grid添加分页。以下是完整的错误消息:
Error in event handler for (unknown): TypeError: Cannot read property 'url' of null
at Object.tinyFilter.start (chrome-extension://nlfgnnlnfbpcammlnibfkplpnbbbdeli/site.js:61:43)
at chrome-extension://nlfgnnlnfbpcammlnibfkplpnbbbdeli/site.js:137:16
以下是我的控制器中的代码:
public ActionResult ExecuteRule(string ruleId, string ruleSql, List<MatchRuleParam> parameters = null)
{
if (Request.Url != null)
{
var query = PaginationQuery.Parse(Request.QueryString);
var upperLimit = query.FromUpper;
var lowerLimit = query.FromLower;
var dataSource = new MatchDataSource();
var results = dataSource.ExecuteTestRule(ruleId, ruleSql, parameters, upperLimit, lowerLimit).Select(k => new { KEY = k });
var response = new Dictionary<string, object>();
response["result"] = results;
response["rowCount"] = MatchDataSource.GetRowCount(ruleId, ruleSql, parameters);
return Json(response, JsonRequestBehavior.AllowGet);
}
return null;
}
当我尝试在下面的url行的chrome中设置断点时,它不会在我的JavaScript函数中停止:
function execRule() {
$.ajax({
type: 'POST',
url: "ExecuteRule",
contentType: 'application/json; charset=utf-8',
data: JSON.stringify({
ruleId: PageState.Selected.RuleId,
ruleSql: PageState.SqlEditor.RuleSql.getValue(),
parameters: PageState.RuleParameters
}),
schema: {
errors: function(response) {
return response.error;
},
data: function(response) {
return response.result;
},
total: function(response) {
return response.rowCount;
}
},
success: function(matchedList) {
PageState.RuleResult = matchedList.result;
var dataSource = new kendo.data.DataSource({
data: matchedList.result
});
Grids.RuleResultsGrid.setDataSource(dataSource);
PageState.Selected.ChildKey = null;
updateButtonStates();
},
error: function(e) {
var errorObject = JSON.parse(e.xhr.responseText);
var errorMessage = errorObject.Message;
//clear old error message
//TODO: gridWidget.clearErrorMessage("error-message");
// add new error message
//TODO: gridWidget.addErrorMessage("error-message", errorMessage);
},
pageSize: 10,
requestEnd: this.onRequestEnd
});
代码工作正常,但由于某种原因,kendo网格有“undefined”和“NaN”,我在这张图片中突出显示红框:
一旦打开网页,就会发生错误。有没有人对我收到TypeError的原因有任何建议? TIA。
更新
“未定义”和“NaN”问题已经解决,但现在我可以选择各种pageSize值,但是当我进行网格刷新时,它会粘贴值“10”。为什么会这样?
答案 0 :(得分:2)
必须将pageSize放在数据源中:
function execRule() {
$.ajax({
type: 'POST',
url: "ExecuteRule",
contentType: 'application/json; charset=utf-8',
data: JSON.stringify({
ruleId: PageState.Selected.RuleId,
ruleSql: PageState.SqlEditor.RuleSql.getValue(),
parameters: PageState.RuleParameters
}),
schema: {
errors: function(response) {
return response.error;
},
data: function(response) {
return response.result;
},
total: function(response) {
return response.rowCount;
}
},
success: function(matchedList) {
PageState.RuleResult = matchedList.result;
var dataSource = new kendo.data.DataSource({
pageSize: 10,
data: matchedList.result
});
Grids.RuleResultsGrid.setDataSource(dataSource);
PageState.Selected.ChildUwi = null;
updateButtonStates();
},
error: function(e) {
var errorObject = JSON.parse(e.xhr.responseText);
var errorMessage = errorObject.Message;
//clear old error message
Grids.RuleResultsGrid.clearErrorMessage("error-message");
// add new error message
Grids.RuleResultsGrid.addErrorMessage("error-message", errorMessage);
},
});
}
在此处找到解决方案:Pager error in Kendo Grid(Nan-Nan of 1 items)
也就是说,分页现在不接受不同的页面大小,例如10,50,100或500.我可以选择这些值,但它总是默认返回到execRule函数中的10值。有没有人对为什么会这样做有任何建议?
<强>更新强>
通过更新我的绑定功能还包括pageSize:
来解决分页问题function bindRuleResults() {
PageState.Selected.Old.RuleResult = PageState.Selected.RuleResult;
var dataSource = new kendo.data.DataSource({
pageSize: 10,
data: PageState.Selected.RuleResult
});
Grids.RuleResultsGrid.setDataSource(dataSource);
PageState.Selected.RuleResult = null;
}
发现这是一篇有用的文章:http://www.codeproject.com/Articles/606682/Kendo-Grid-In-Action