1

我有一个 slickgird 保存到数据库和计算工作。但是我的问题是从数据库返回数据以填充 slickgrid 时。我正在调用一个 Ajax 查询,它以以下格式返回数据,

[
{
    '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 条记录)。对我做错了什么有任何想法吗?

4

1 回答 1

1

明白了...必须添加

     data = eval("[" + currentData + "]");

    grid = new Slick.Grid("#myServicesGrid", data, columns, options);

感谢您的关注。

于 2012-10-11T11:42:49.160 回答