infragistics igGrid:如何使用 javascript 删除一行

infragistics igGrid: how to remove a row with javascript

我认为我的问题很简单,但我仍然没有找到适合我的答案,无论是在这里还是在那里.. 所以如果有人能帮助我,我会很高兴,不管是提供有用的链接还是其他什么...

我想要达到的目标: 我有一个 Ignite UI 网格 (igGrid),我想在其中使用 javascript 删除一行。哪个都不重要。简单吧?

到目前为止我尝试过的:

现在是代码片段:

    $sender = $(this).attr('id');
    $varTablName = gridMap.getVarTable($sender);
    var rowCount = $("#" + $varTablName).igGrid("widget").igGrid('rows').length;

    $("#" + $varTablName).igGrid("widget").igGrid('rows').each(function (index) {
        var row = $("#" + $varTablName).igGrid("widget").igGrid("rowAt", index);
        if (rowCount > 1) {
            $(row).remove(); //the not quite working part
        }

这是可行的,对吧?没有必要一路走下去,用c#写,然后用js调用,对吧..?对吗??^^

您可以试试这个或一些 jquery 等价物。我不知道它会如何影响 ultragrid,所以请仔细检查你是否保留了所有其他功能。

var row = document.querySelector('myRowReference');
row.parentNode.removeChild(row);

Infragistics guide to deleting a row programmatically

$('#grid').igGridUpdating('deleteRow', "AFG");  
$('#grid').igGridUpdating('deleteRow', 1, $('#grid').igGrid("rowAt", 0));

跟随igGrid的api docs -- thnx @KonstantinDinev -- the code above will delete a row from the grid, creating a transaction and updates the UI. This functionality depends on autoCommit选项

API 应该永远是第一个选项 ^^

我们也可以定位 dom 元素并自行删除或隐藏它。删除后,显示的行数会发生变化,但需要更新数据源

http://jsfiddle.net/gtw916um/6/

$(function() {
  $("#grid").igGrid({});

  //hides 2nd row (index starts at 0)
  $("#grid").igGrid("allRows").each(function(index) {
    if (index == 1) {
      $(this).css("display", 'none');
    }
  });

  //deletes 4th row (index starts at 0)
  var row = $("#grid").igGrid("widget").igGrid("rowAt", 3);
  $(row).remove();

  //un-hiding 2nd row (index starts at 0)
  row = $("#grid").igGrid("widget").igGrid("rowAt", 1);
  $(row).css("display", 'table-row');

});

未测试更新数据方法

$("#grid").data("igGrid").dataSource.deleteRow(3, true);
$("#grid").data("igGrid").commit();

deleteRow 是您正在寻找的方法,因为 . For this method you can provide the row element as parameter, or the row ID. Here's the API docs.

代码如下:

var row = $("#" + $varTablName).igGrid("rowAt", index);
$("#" + $varTablName).igGridUpdating("deleteRow", row);