Javascript 获取 slickgrid 中选定行的数据

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7944325/
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-08-24 04:09:38  来源:igfitidea点击:

get data of selected rows in slickgrid

javascriptslickgrid

提问by Preli

I have a slickgrid in which some rows are hidden by a filter (DataView).

我有一个 slickgrid,其中一些行被过滤器 (DataView) 隐藏。

When I now call the getSelectedRows method of the grid I get the indices of the visibly selected rows. But I need the actual data of the selected rows.

当我现在调用网格的 getSelectedRows 方法时,我得到了可见选择行的索引。但我需要所选行的实际数据。

回答by matma

You must do something like this:

你必须做这样的事情:

var selectedData = [],
    selectedIndexes;

selectedIndexes = _grid.getSelectedRows();
jQuery.each(selectedIndexes, function (index, value) {
  selectedData.push(_grid.getData()[value]);
});

Right now the selectedDatavariable contains data for selected rows.

现在selectedData变量包含选定行的数据。

回答by eliprodigy

You have a mistake. It needs to be "getDataItem" and not "getData".

你有一个错误。它需要是“getDataItem”而不是“getData”。

var selectedData = [],enter code here`selectedIndexes;

selectedIndexes = _grid.getSelectedRows();
jQuery.each(selectedIndexes, function (index, value) {
    selectedData.push(_grid.getDataItem(value));
});

回答by Axle

You can also use this line in the .each loop to pull the data from the dataView instead of using getData() from the grid object, since that seems to be inconsistent depending on the fork:

您还可以在 .each 循环中使用这一行从 dataView 中提取数据,而不是使用来自网格对象的 getData() ,因为这似乎不一致,具体取决于 fork:

var selectedData = [],
    selectedIndexes;

selectedIndexes = _grid.getSelectedRows();
jQuery.each(selectedIndexes, function (index, value) {
    selectedData.push(_dataView.getItemById(value));
});

回答by Emma Gasca

hObjMarcado  = ( grid.getSelectedRows());
for( var a_id in hObjMarcado ) {
    vres.push( dataview.getItem( hObjMarcado[a_id] ));
    //la opcion getItem obtiene el elemento especifico,
    //aun con filtro.
}
return vres;

回答by Grey Wolf

If you access grid from other control like . click button

如果您从其他控件(如 . 单击按钮

var selectRow = gridInstance.getSelectedRows();
alert(gridInstance.getDataItem(selectRow).columnName)