我有一个Infragistics网格,当网格的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();
}
答案 0 :(得分:1)
将关键参数括在模板中的引号中:
template: "<input type='button' onclick='deleteRow(\"${ProductID}\")' value='Delete' class='delete-button'/>"