4

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

Omar Bahir
  • 1,237
  • 5
  • 20
  • 48

3 Answers3

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.

kavun
  • 3,358
  • 3
  • 25
  • 45
  • Thank you @Kavun :) its working great , this is what i was looking for to get the data from a specific cell. thanks ! now can you please tell is there any function to disable (make non-editable) a single cell ??? i'm talking about a single cell , not a whole column. i have implemented a method which makes a complete column editable or non-editable, but i need when user will click a specific row , this whole row should(only that specific row) become non-editable.Is it possible ? – Omar Bahir Nov 02 '13 at 07:49
  • 1
    Yes, you will need to implement a custom `getItemMetadata` function that returns null for the editor for the column if it should be uneditable. ie: `function getItemMetadata(row) { return { columns: { 'ColumnID': { editor: null } } }; }` or you could do it [this way](http://stackoverflow.com/questions/10491676/disabling-specific-cell-edit-in-slick-grid) – kavun Nov 03 '13 at 03:51
2
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");
  }
}
idbehold
  • 16,833
  • 5
  • 47
  • 74
  • Thank you @ibdehold for you response , but this thing is already working , i can get the name of column(i.e. i can check which column is clicked) through the method i have mentioned in question, now i want to get the value of that specific cell (i.e. may be 1000 or 500 in the orderqty cell). so i was asking is there any build-in method something like grid.getColumnIndex('orderqty').value; to get the specific cell's value ? – Omar Bahir Nov 02 '13 at 07:16
  • 1
    @Omar `grid.getDataItem(500).orderqty` or `grid.getDataItem(1000).orderqty`. – idbehold Nov 02 '13 at 16:42
1

If you access grid from other control like . click button

var selectRow = gridInstance.getSelectedRows();
alert(gridInstance.getDataItem(selectRow).columnName)
Wolf
  • 6,361
  • 2
  • 28
  • 25