在 jQuery 中使用复合主键更新基础设施 igGrid

Update infragistics igGrid with composite primaryKeys in jQuery

我正在使用 Infragistics igGrid,我有多个主键:

 $("#grid_selector").igGrid({
            autoCommit: true,
            width: "100%",
            height: '500px',
            autoGenerateColumns: false,
            primaryKey: "TrackTrainId,ClassCode",
            columns: [
                { headerText: "Class Code", key: "ClassCode", dataType: "string" },
                { headerText: "Track/Train", key: "TrackTrainId", dataType: "string" },
                { headerText: "Cars", key: "NumberOfCars", dataType: "number" },
                { headerText: "Loads", key: "LoadEquipments", dataType: "string" },
                { headerText: "Empties", key: "EmptyEquipments", dataType: "string" },
                { headerText: "Tons", key: "Tons", dataType: "number" },
                { headerText: "Feet", key: "Feet", dataType: "number" },
            ],
            features: [
                {
                    name: "Updating",
                    editMode: "none",
                    enableAddRow: false,
                    enableDeleteRow: false
                }
            ]
        });

网格最初不会有任何数据。当用户点击添加行按钮时,它会调用另一个函数在网格中添加新行。以下是添加行的代码,效果很好:

//add rows to the grid to show selected equipments first time
AddRowForEquipmentSelectedGrid = function (track_info, ul_eq) {
var selctd = $('#' + ul_eq + ' li.ui-selected'),
    grid = $("#grid_selector");

var rowObj = {
    "TrackTrainId": track_info.TrackTrainId,
    "ClassCode": track_info.ClassCode,
    "NumberOfCars": track_info.NumberOfCars,
    "LoadEquipments": track_info.LoadEquipments,
    "EmptyEquipments": track_info.EmptyEquipments,
    "Tons": track_info.Tons,
    "Feet": track_info.Feet
};

grid.igGridUpdating("addRow", rowObj);
};

当我尝试更新网格行时出现问题。如何传递主键。如果我有任何一个主键,那么这段代码就可以正常工作。我将多个键作为 { "TrackTrainId": track_id, "ClassCode": class_code }.

传递
//on update equipment
UpdateEquipmentGrid = function (track_id, class_code, total_cars, txt_load, txt_emp, txt_tons, txt_feet) {
var rowObj = {
    "NumberOfCars": total_cars,
    "LoadEquipments": txt_load,
    "EmptyEquipments": txt_emp,
    "Tons": txt_tons,
    "Feet": txt_feet
};
$('#grid_selector').igGridUpdating("updateRow", { "TrackTrainId": track_id, "ClassCode": class_code }, rowObj);
}

不知道这是否正确。任何建议我在这里做错了什么。

目前igGrid不支持复合主键。 您可以将不同列的值组合到一个字段中,并将其用作主键。 例如:

 rowObj.CompositeKey = rowObj.ClassCode + "|" + rowObj.TrackTrainId;

并且您可以根据该复合值更新相关行:

 $("#grid").igGridUpdating("updateRow", "another random string|some random string", { NumberOfCars: 1000 });

你可以在这里参考下面的JSFiddle例子: http://jsfiddle.net/2uf32hm3/2/