我有一個保存到數據庫和calculatons工作的slickgird。 但是我的問題是從數據庫返回數據以填充slickgrid時。我正在調用一個Ajax查詢,它以下列格式返回數據:SlickGrid沒有從Ajax調用返回JSON正確填充
[
{
'HeaderService': 'ServicerReview',
'Service': '',
'Numberof': '',
'at': '',
'Charged': '',
'Total': '',
'Total2': '',
'Discount': '',
'FFO': '',
'EC': '',
'ECat': '',
'ECCost': '',
'ECCostTotal': '',
'ECCostTotal2': '',
'Margin': ''
},
{
'HeaderService': '',
'Service': 'SeniorReviewer',
'Numberof': '1',
'at': '@',
'Charged': '£600.00',
'Total': '£600.00',
'Total2': '',
'Discount': '',
'FFO': '',
'EC': '1',
'ECat': '',
'ECCost': '£350.00',
'ECCostTotal': '£350.00',
'ECCostTotal2': '',
'Margin': ''
},
.. and so on.
]
(。是其他相同結構的記錄)。它填充了一個名爲currentData
後來我通過
var columns = [{ id: "HeaderService", name: "Category", field: "HeaderService", options: serviceHeaders, editor: Slick.Editors.SelectOption, width: 200 },
{ id: "Service", name: "Service", field: "Service", options: serviceActuals, editor: Slick.Editors.SelectOption, width: 150 },
{ id: "Numberof", name: "No", field: "Numberof", editor: Slick.Editors.Text, width: 50 },
{ id: "at", name: "", field: "at", width: 30 },
{ id: "Charged", name: "Per Unit", field: "Charged", editor: Slick.Editors.Text },
{ id: "Total", name: "Total", field: "Total", editor: Slick.Editors.Text },
{ id: "Total2", name: "Sub Total", field: "Total2", editor: Slick.Editors.Text },
{ id: "Discount", name: "Discount", field: "Discount", options: ",Yes", editor: Slick.Editors.SelectOption, cssClass: "greenbackground", width: 50 },
{ id: "FFO", name: "Fixed Fee", field: "FFO", editor: Slick.Editors.Text, cssClass: "greenbackground" },
{ id: "EC", name: "EC", field: "EC", editor: Slick.Editors.Text, width: 50 },
{ id: "ECat", name: "Cat", field: "ECat", editor: Slick.Editors.Text, width: 30 },
{ id: "ECCost", name: "Cost", field: "ECCost", editor: Slick.Editors.Text },
{ id: "ECCostTotal", name: "CostTotal", field: "ECCostTotal", editor: Slick.Editors.Text },
{ id: "ECCostTotal2", name: "CostTotal2", field: "ECCostTotal2", editor: Slick.Editors.Text },
{ id: "Margin", name: "Margin", field: "Margin", editor: Slick.Editors.Text }, ];
var options = {
enableCellNavigation: true,
enableColumnReorder: false,
editable: true,
cellHighlightCssClass: "changed"
};
var currentData;
$(function() {
var json = null;
$.ajax({
async: false,
global: false,
type: 'GET',
url: '@Url.Action("GetDetailsforQuote")',
dataType: "json",
success: function (data) {
currentData = "[" + data.toString() + "]";
debugger;
return data;
}
});
data = currentData;
alert(data);
grid = new Slick.Grid("#myServicesGrid", data, columns, options);
裝飾格但後來,網格顯示在屏幕上,列有正常,但僅僅是空行的負載,沒有數據(該數據應變量有6條記錄)。任何想法,我在做什麼錯?
由於您沒有提供列或選項,所以需要檢查更廣泛的代碼部分。 – kanngard
你可以發佈你的ajax調用的json輸出嗎? – ganeshk