SpreadJS 13
SpreadJS Documentation / Sample Code / Sample Code for Cells / Getting Header Cell Index from Mouse Click
In This Topic
    Getting Header Cell Index from Mouse Click
    In This Topic

    You can get the index of the header cell when selecting it with the mouse.

    Using Code

    This example gets the index for the header cell.

    JavaScript
    Copy Code
    var spread = new GC.Spread.Sheets.Workbook($("#ss")[0]);
    var activeSheet = spread.getActiveSheet();
    activeSheet.setRowCount(4, GC.Spread.Sheets.SheetArea.colHeader);
    $("#ss").click(function (e) 
    {   
        // Acquire cell index from the mouse-clicked point of column header cells.
        var offset = $("#ss").offset();
        var x = e.pageX - offset.left;
        var y = e.pageY - offset.top;
        var target = spread.getActiveSheet().hitTest(x, y);
        if(target &&
        target.rowViewportIndex === -1 &&
        (target.colViewportIndex === 0 || target.colViewportIndex === 1))
         {
         console.log("Row index of mouse-clicked column header cells: " + target.row);
         console.log("Column index of mouse-clicked column header cells: " + target.col);
         }
    });