1

Infragistics グリッドがあり、グリッドの primaryKey が dataType 文字列の場合、行を削除できません。

「KIT_001」という形式であるため、primaryKey を dataType 番号として設定できません。削除ボタンを使用して、この種のデータで行を削除できる賢い方法はありますか? おそらく、インクリメントされた ID を設定し、それを削除ボタンに使用する方法はありますか?

var dataSource = [
    {"ProductID": "KIT_001", "Name": "Kit 1", "ProductNumber": "P4857"},
    {"ProductID": "KIT_002", "Name": "Kit 2", "ProductNumber": "P4567"},
    {"ProductID": "KIT_003", "Name": "Kit 3", "ProductNumber": "P4447"}
]
$(function () {
            $("#grid").igGrid({
                autoGenerateColumns: false,
                width: "100%",
                height: "500px",
                columns: [
                    { headerText: "Product ID", key: "ProductID", dataType: "string", width: "10%" },
                    { headerText: "Product Name", key: "Name", dataType: "string", width: "30%" },
                    { headerText: "Product Number", key: "ProductNumber", dataType: "string", width: "25%" },
                    { headerText: "", key: "Delete", dataType: "string", width: "10%", unbound: true, 
                     template: "<input type='button' onclick='deleteRow(${ProductID})' value='Delete' class='delete-button'/>"},
                ],
                primaryKey: "ProductID",
                dataSource: dataSource,
                features: [
                    {
                        name: "Updating",
                        enableAddRow: false,
                        editMode: "row",
                        enableDeleteRow: false,

                    }
                    ]
            });
        });

        function deleteRow(rowId) { console.log('rowId ',rowId)
            var grid = $("#grid").data("igGrid");
            grid.dataSource.deleteRow(rowId);
            grid.commit();
        }
4

1 に答える 1

1

テンプレートで key パラメータを引用符で囲みます。

template: "<input type='button' onclick='deleteRow(\"${ProductID}\")' value='Delete' class='delete-button'/>"
于 2015-09-18T10:40:16.313 に答える