1

I have an Infragistics grid and am unable to delete a row when the primaryKey of the grid is of dataType string.

I can not set my primaryKey as dataType number because it is of this format: "KIT_001". Is there any clever way of using a delete button and being able to delete rows with this kind of data? Perhaps a way to set an incremented ID and use that for the delete button?

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();
        }
Konstantin Dinev
  • 34,219
  • 14
  • 75
  • 100
mihai6744
  • 164
  • 7

1 Answers1

1

Enclose the key parameter in quotes in your template:

template: "<input type='button' onclick='deleteRow(\"${ProductID}\")' value='Delete' class='delete-button'/>"
Konstantin Dinev
  • 34,219
  • 14
  • 75
  • 100