Van*_*ale 13
SlickGrid存储库中的AJAX示例非常复杂,因为它试图通过缓存等方式变得棘手.例如,它会跟踪已发送的所有行,并且只会从服务器请求新行.它也是Digg故事的具体例子的硬编码.文档非常缺乏,并且jQuery版本1.5+(它改变了ajax的处理方式)似乎有些错误.
通过使用SlickGrid的Andrew Childs fork,我可以更轻松地开始使用它,它包含有关如何在README底部使用AJAX的非常简单直接的说明:
存储库位于https://github.com/andrewchilds/SlickGrid
asp.net页面中的一个示例.webservice myData返回一个需要匹配网格列的json字符串.
$(function () {
$.ajax({
url: "WS.asmx/myData",
global: false,
type: "POST",
data: "{}",
contentType: "application/json",
dataType: "json",
async: false,
success: function (json) {
data = eval('(' + json.d + ')');
if (!data) { alert('no data'); };
},
error: function (msg) {
var errorText = eval('(' + msg.responseText + ')');
alert('Error : \n--------\n' + errorText.Message);
}
}
);
if (data) {
dataView = new GridNic.Data.DataView();
grid = new GridNic.Grid($("#myGrid"), dataView.rows, columns, options);
var pager = new GridNic.Controls.Pager(dataView, grid, $("#pager"), columns);
var columnpicker = new GridNic.Controls.ColumnPicker(columns, grid, options);
Run Code Online (Sandbox Code Playgroud)
... 等等
在Asp.Net中,默认情况下限制json字符串的大小.如果遇到问题,您必须在web.config中声明更大的大小,例如:
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="5000000">
</jsonSerialization>
</webServices>
</scripting>
</system.web.extensions>
Run Code Online (Sandbox Code Playgroud)