使用分页从Kendo Grid中删除行

时间:2016-08-08 14:47:54

标签: javascript jquery pagination kendo-grid datasource

我有一些kendo网格(启用了分页功能)和一些条目。说,我有5页,我从每个页面选择了一行(单击复选框),然后单击顶级操作DELETE。我无法弄清楚如何从网格和数据源中删除条目?

我尝试了下面的代码,它删除了网格中可见的条目(在屏幕上)

        var grid = $("#grid").data("kendoGrid");
        var userSelectionInfo = usersService.getUserSelectionInfo();
        for(var userName in userSelectionInfo) {
            if(userSelectionInfo[userName]) {
                var selector = '#' + userName+ '_actions';
                grid.removeRow($(selector).closest('tr'));
            }
        }

我尝试了另一种方法:

我创建了一个对象数组,这些对象在从原始对象数组删除操作后仍然保留,然后添加到网格数据源中。

    var newData = [];
    var userSelectionInfo = usersService.getUserSelectionInfo();
    for(var i = 0; i < users.length; i++) {
        if(users[i].userName&& !userSelectionInfo[users[i].userName]) {
            newData.push(users[i]);
        }
    }
    loadUsersIntoGrid(newData);

我缺少哪种更好的方法或kendo API? 提前谢谢。

1 个答案:

答案 0 :(得分:0)

您可以从dataSource而不是grid中删除。首先将每个所选项的id推送到数组,比如DeleteList。然后,您可以在单击顶部DELETE时从数据源中删除。

.side-nav{
  position: fixed;
  z-index: 100;
  right: 0;
  margin-top: 15vh;

  ul {
    list-style: none;
    background: red;
    border-style: solid;
    border-right-style: none;
    border-width: 3px;
    border-color: blue;
    @include border-radius(20px, 0, 20px, 0);
    width: 1cm !important;
  }

  li {
    position: relative;
    display: block;
    right: 0;
    width: 1cm;

    span {
      white-space: pre;

      &.short {
        color: black;
        display: block;
      }

      &.long {
        display: none;
        color: white;
      }
    }

    &:hover {
      right:200%;
      width: 3cm;
      @include border-radius(20px, 0, 20px, 0);
      border-style: solid;
      border-right-style: none;
      border-width: 3px;
      border-color: blue;
      background: red;
      margin: -3px 0;

      span {
        &.short {
          display: none;
        }

        &.long {
          display: block;
        }
      }
    }
  }

  a {
    position: relative;
    display: block;
    text-decoration: none;

    padding: 10px 0;
    text-align: center;
  }
}