javascript Slickgrid- 获取选定的单元格值、ID 和字段?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19701048/
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
Slickgrid- getting selected cell value , id and field?
提问by Omar Bahir
i'm working with slickgrid and i'm quit new in slickgrid. i want to know is there any function through which i can get the complete info of all the cell to a specific row where user will click ??? also i want to get values before and after editing in the specific cell so that i can measure the change in the cell. for getting the active cell (i.e. where user clicked) i'm using
我正在使用 slickgrid 并且我退出了 slickgrid 的新手。我想知道是否有任何功能可以将所有单元格的完整信息获取到用户将单击的特定行???我还想在特定单元格中编辑之前和之后获取值,以便我可以测量单元格中的变化。用于获取活动单元格(即用户单击的位置)我正在使用
ifkaar_scenarioConfigTable.onClick.subscribe(cellClicked);
and i'm checking where the cell is my desired cell(i.e. where user is allowed to do editing/modification) as following
我正在检查单元格是我想要的单元格的位置(即允许用户进行编辑/修改的位置)如下
function cellClicked(e) {
var cell = ifkaar_scenarioConfigTable.getCellFromEvent(e);
if (col[cell.cell].id == "orderqty") {
console.log("orderqty pressed");
}
}
this is working fine , i.e. when i click on any cell , it tell whether it is "orderqty" or not , but further i want to get its value and other cells' value in order to calculate the changes. I've searched but couldn't find any clear article (or i can't understood properly). any help will be highly appreciated. Thanks
这工作正常,即当我单击任何单元格时,它会判断它是否为“orderqty”,但我还想获取其值和其他单元格的值以计算更改。我已经搜索过但找不到任何明确的文章(或者我无法正确理解)。任何帮助将不胜感激。谢谢
回答by kavun
the onClick
event passes the row as an argument
该onClick
事件将该行作为参数传递
Get the data item for a clicked row
获取被点击行的数据项
function cellClicked(e, args) {
var item = grid.getDataItem(args.row);
}
Check if a click happened in a specific column
检查是否在特定列中发生了点击
function cellClicked(e, args) {
if (args.cell == grid.getColumnIndex('orderqty')) {
console.log("orderqty pressed");
}
}
You could even pull this filtering functionality out into its own function and pass a callback when a click happens in that column
您甚至可以将此过滤功能拉入其自己的函数中,并在该列中发生单击时传递回调
function forColumn(row, cell, columnID, fn) {
var cellNode = grid.getCellNode(row, cell);
var dataContext = grid.getDataItem(row);
if (cellNode && grid.getColumns()[cell].id === columnID) {
fn.call(this, cellNode, dataContext, row, cell);
}
}
function cellClicked(e, args) {
forColumn(args.row, args.cell, 'orderqty', function (cellNode, dataContext, row, cell) {
console.log("orderqty pressed");
});
}
Values before and after edit
编辑前后的值
To get the values of a cell before and after an edit you will need to handle this in the isValueChanged
function in the editor for a column.
要在编辑之前和之后获取单元格的值,您需要isValueChanged
在编辑器中的列函数中处理此问题。
回答by idbehold
function cellClicked(e) {
var grid = ifkaar_scenarioConfigTable;
var cell = grid.getCellFromEvent(e);
var item = grid.getDataItem(cell.row); // all the data in the row
if (cell.cell == grid.getColumnIndex('orderqty')) {
console.log("orderqty pressed");
}
}
回答by Grey Wolf
If you access grid from other control like . click button
如果您从其他控件(如 . 单击按钮
var selectRow = gridInstance.getSelectedRows();
alert(gridInstance.getDataItem(selectRow).columnName)