【问题标题】:Get all values from a specific kendo grid column从特定剑道网格列中获取所有值
【发布时间】:2017-06-18 11:34:24
【问题描述】:

我需要从剑道网格的一列中获取所有数据,我已经搜索了很多但没有找到有用的东西。我基于来自 API API/LogService/ReadAllLog 的 JSON 创建了一个剑道网格。无论如何我都在使用 AngularJS。

我的代码:

$scope.gridColumns = [{
  field: "SystemName",
  editable: false,
  title: _t("Title.SystemName"),
  allownull: false,
  width: 100
}, {
  field: "FormName",
  editable: false,
  title: _t("CommonTitle.SystemFeatureForm"),
  allownull: false,
  width: 100
}]

然后我这样填写:

$scope.gridConfig = {
  autoBind: true,
  inlineOperationalUrl: {
    read: {
      url: webAccess + "api/LogService/ReadAllLog",
    }
  }
};

这是我视图中的网格(注意:pn-gridview 是从角度网格视图创建的自定义指令,并进行了一些更改):

<pn-gridview id="SystemsGrid"
      config="gridConfig"
      columns="gridColumns"
</pn-gridview>

【问题讨论】:

  • 如何创建网格(数据源)?请添加一些代码和你得到的最小示例。
  • api/LogService/ReadAllLog是什么类型的数据?
  • 它来自 MongoDB 数据库。
  • 是的,但它是什么类型的数据? JSON、XML、.. ?
  • 这是一个 .net 类的列表

标签: javascript html angularjs json kendo-grid


【解决方案1】:

使用简单的辅助函数收集一列中的所有值:

function getColumnValues(selector, columnName) {

  //Init
  var columnData = [];
  var data = $(selector).data("kendoGrid").dataSource._data;

  //collect each valueof given columnName
  for (i = 0; i < data.length; i++) {
    if (typeof data[i][columnName] !== "undefined") {
        columnData.push(data[i][columnName]);
    }
  }

  //return column data as array
  return columnData;
}

> DEMO FIDDLE

在您的情况下,您需要调用此辅助函数,例如:

var myColumnData = getColumnValues('#SystemsGrid', 'SystemName');


您可以通过以下方式访问特定的数据:

var myRowData = $("#SystemsGrid").data().kendoGrid.dataSource.at(index);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-07-14
    • 1970-01-01
    • 1970-01-01
    • 2014-07-09
    • 1970-01-01
    • 2017-04-08
    • 1970-01-01
    • 2014-01-29
    相关资源
    最近更新 更多