SpreadJS Documentation
Getting Cell Index from Mouse Click

You can get the cell index when clicking on a cell.

Using Code

This example gets the cell index.

JavaScript
Copy Code
$("#ss").click(function (e) {
    //Acquire cell index from mouse-clicked point of regular cells which are neither fixed rows/columns nor row/column headers.
    var offset = $("#ss").offset();
    var x = e.pageX - offset.left;
    var y = e.pageY - offset.top;
    var target = $("#ss").data("spread").getActiveSheet().hitTest(x, y);

    if(target &&
        (target.rowViewportIndex === 0 || target.rowViewportIndex === 1) &&
        (target.colViewportIndex === 0 || target.colViewportIndex === 1)){
        console.log("Row index of mouse-clicked cells: " + target.row);
        console.log("Column index of mouse-clicked cells: " + target.col);
    }
});

 

 


Copyright © GrapeCity, inc. All rights reserved.

Send comments on this topic.