Slickgrid 动态加载不显示(MVC 5)
Slickgrid dynamic loading doesn't display (MVC 5)
我已经从我的控制器转换了我的数据表:
public string GetReportResults(int ID)
{
UserInterface engine = new UserInterface();
UserStandardReport rpt = engine.GetStandardReport(CreateLoggedInUser(), ID);
DataTable dt = engine.GetQueryData(CreateLoggedInUser(), rpt);
System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>();
Dictionary<string, object> row;
foreach (DataRow dr in dt.Rows)
{
row = new Dictionary<string, object>();
foreach (DataColumn col in dt.Columns)
row.Add(col.ColumnName, dr[col]);
rows.Add(row);
}
return serializer.Serialize(rows);
}
返回的数据片段:
[{"Customer City":null,"Customer Address Line 1":null,"Customer Address Line 2":null,"Customer Name (Firm or Full Name)":"","Customer State":null,"Customer Zip":null },{"Customer City":null,"Customer Address Line 1":null,"Customer Address Line 2":null,"Customer Name (Firm or Full Name)":"1 个位置","Customer State":null,"Customer Zip":null},{"Customer City":null,"Customer Address Line 1":null,"Customer Address Line 2":null,"Customer Name (Firm or Full Name)":"2 位置","Customer State":null,"Customer Zip":null},{"Customer City":null,"Customer Address Line 1":null,"Customer Address Line 2":null,"Customer Name (Firm or Full Name)":"3 位置","Customer State":空,"Customer Zip":空}]
在我看来,我正在使用这个:
$(function () {
var columnName;
var columns = @Html.Raw(Json.Encode(Model.columns));
for (var n=0; n< columns.length; n++)
{
columnName = columns[n];
cols.push({
id: columnName,
name: columnName,
field: columnName
});
}
$.getJSON("/Home/GetReportResults", {ID: @Model.ID}).done(function(data){
slickdata = data;
});
dataview = new Slick.Data.DataView({inlineFilters: true});
grid = new Slick.Grid("#availableGrid", dataview, cols, options);
dataview.beginUpdate();
dataview.setItems(slickdata);
dataview.endUpdate();
});
我的 Model.columns 是一个列表,其中包含列名称 {"Customer City"、"Customer Address Line 1"、"Customer Address Line 2"、"Customer Name (Firm or Full Name)"、"Customer State"、 "Customer Zip"}。这些将根据返回的结果进行更改。
目前,我在网格中看到了我的列,但显示了我的 none 数据。我仔细检查了 Firebug。没有错误。我缺少什么网格?
将对 dataview.setItems(slickdata)
的调用置于 $.getJSON()
回调中。
我已经从我的控制器转换了我的数据表:
public string GetReportResults(int ID)
{
UserInterface engine = new UserInterface();
UserStandardReport rpt = engine.GetStandardReport(CreateLoggedInUser(), ID);
DataTable dt = engine.GetQueryData(CreateLoggedInUser(), rpt);
System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>();
Dictionary<string, object> row;
foreach (DataRow dr in dt.Rows)
{
row = new Dictionary<string, object>();
foreach (DataColumn col in dt.Columns)
row.Add(col.ColumnName, dr[col]);
rows.Add(row);
}
return serializer.Serialize(rows);
}
返回的数据片段: [{"Customer City":null,"Customer Address Line 1":null,"Customer Address Line 2":null,"Customer Name (Firm or Full Name)":"","Customer State":null,"Customer Zip":null },{"Customer City":null,"Customer Address Line 1":null,"Customer Address Line 2":null,"Customer Name (Firm or Full Name)":"1 个位置","Customer State":null,"Customer Zip":null},{"Customer City":null,"Customer Address Line 1":null,"Customer Address Line 2":null,"Customer Name (Firm or Full Name)":"2 位置","Customer State":null,"Customer Zip":null},{"Customer City":null,"Customer Address Line 1":null,"Customer Address Line 2":null,"Customer Name (Firm or Full Name)":"3 位置","Customer State":空,"Customer Zip":空}]
在我看来,我正在使用这个:
$(function () {
var columnName;
var columns = @Html.Raw(Json.Encode(Model.columns));
for (var n=0; n< columns.length; n++)
{
columnName = columns[n];
cols.push({
id: columnName,
name: columnName,
field: columnName
});
}
$.getJSON("/Home/GetReportResults", {ID: @Model.ID}).done(function(data){
slickdata = data;
});
dataview = new Slick.Data.DataView({inlineFilters: true});
grid = new Slick.Grid("#availableGrid", dataview, cols, options);
dataview.beginUpdate();
dataview.setItems(slickdata);
dataview.endUpdate();
});
我的 Model.columns 是一个列表,其中包含列名称 {"Customer City"、"Customer Address Line 1"、"Customer Address Line 2"、"Customer Name (Firm or Full Name)"、"Customer State"、 "Customer Zip"}。这些将根据返回的结果进行更改。
目前,我在网格中看到了我的列,但显示了我的 none 数据。我仔细检查了 Firebug。没有错误。我缺少什么网格?
将对 dataview.setItems(slickdata)
的调用置于 $.getJSON()
回调中。