最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Slickgrid- getting selected cell value , id and field? - Stack Overflow

programmeradmin0浏览0评论

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

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

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

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

Share Improve this question asked Oct 31, 2013 at 7:58 Omar BahirOmar Bahir 1,2575 gold badges21 silver badges50 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 14

the onClick event passes the row as an argument

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.

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");
  }
}

If you access grid from other control like . click button

var selectRow = gridInstance.getSelectedRows();
alert(gridInstance.getDataItem(selectRow).columnName)
发布评论

评论列表(0)

  1. 暂无评论