代码之家  ›  专栏  ›  技术社区  ›  mihai6744

使用字符串primaryKey删除行

  •  1
  • mihai6744  · 技术社区  · 9 年前

    我有一个Infregistics网格,当网格的primaryKey是dataType字符串时,我无法删除行。

    我无法将primaryKey设置为dataType编号,因为它的格式为:“KIT_001”。有没有什么巧妙的方法可以使用删除按钮并删除包含此类数据的行?也许有一种方法可以设置递增的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();
            }
    
    1 回复  |  直到 9 年前
        1
  •  1
  •   Konstantin Dinev    9 年前

    在模板中用引号将关键参数括起来:

    template: "<input type='button' onclick='deleteRow(\"${ProductID}\")' value='Delete' class='delete-button'/>"