javascript 如何获取剑道网格特定列的所有值?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30711055/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 12:34:32  来源:igfitidea点击:

How to get all the values of particular column of kendo grid?

javascriptkendo-uikendo-gridkendo-ui-grid

提问by shubham gupta

i have kendo grid with 4 columns in it [mac,level,timestamp,message]. i need to store all the values under timestampcolumn in an array.I tried but couldn't find any way to traverse in a particular column. Any idea how to do this using java script?

我有剑道网格,其中有 4 列 [mac,level,timestamp,message]。我需要将timestamp列下的所有值存储在一个数组中。我尝试过但找不到在特定列中遍历的任何方法。知道如何使用 java 脚本来做到这一点吗?

回答by himawan_r

Since you're using kendo which you must include jQuery. To make life easier why don't try to use jQuery, as per my suggestion at the moment i don't know any other way but to

由于您使用的是剑道,因此您必须包含jQuery。为了让生活更轻松,为什么不尝试使用jQuery,根据我目前的建议,我不知道任何其他方式,只能使用

  • get & loop through the grid datasource

  • get the date and push it into an array

  • 获取并循环遍历网格数据源

  • 获取日期并将其推入数组

For example i create button <button id="test">Click here</button>and kendo console <div class="console"><div>so you can see the result after clicking the button. Here goes the code :

例如,我创建了按钮<button id="test">Click here</button>和剑道控制台,<div class="console"><div>因此您可以在单击按钮后看到结果。这是代码:

$("#test").click(function(){
    var arrayDate = [];
    var data =$("#grid").data("kendoGrid").dataSource._data;
    for(i=0; i<data.length; i++){
      arrayDate.push(data[i].OrderDate);
    }  
    kendoConsole.log(arrayDate);
});

Here is working example for you on kendo dojo

这是您在剑道道场上的工作示例

回答by Dion Dirza

You can access your data through Grid's data source and grab it manually, something like this should work :

您可以通过 Grid 的数据源访问您的数据并手动获取它,这样的事情应该可以工作:

function getGridTimestamps() {
    var grid = $("#grid").getKendoGrid(),
        datas = grid.dataSource.data();

    return $.map(datas, function(data) {
        return data.timestamp;
    });
}

var timestamps = getGridTimestamps();