Spreadsheet select event shows previous cell selected. How to get the cell just clicked on?

1 Answer 22 Views
Spreadsheet
George
Top achievements
Rank 2
Iron
Iron
Iron
George asked on 06 Jun 2024, 08:22 PM

Hi,

I am wondering why on the select event for the Spreadsheet control I am seeing the previous active cell and not the one I just clicked on? Is there any way I can get the cell I last clicked on?

 

The function I am calling from the select event looks like this:


  function onSelect(e) {

    var spreadsheet = e.sender; // Get the Spreadsheet widget
    var selectedCell = spreadsheet.activeSheet().activeCell();


    console.log("on select event the cell value " + selectedCell);

  }
Am I not understanding the select event?

 

Here is a Dojo link with an example:

Calling Read From dataSource Transport: | Kendo UI Dojo (telerik.com)

 

Thanks,

George

George
Top achievements
Rank 2
Iron
Iron
Iron
commented on 06 Jun 2024, 09:15 PM

For some reason when I try the changing event in this demo:

changing - API Reference - Kendo UI Spreadsheet - Kendo UI for jQuery (telerik.com)

I get the correct cell range/ identifier... the one I just changed.

When I added this code to my spreadsheet code I got the previously selected cell...just like before.

-George

1 Answer, 1 is accepted

Sort by
0
George
Top achievements
Rank 2
Iron
Iron
Iron
answered on 07 Jun 2024, 03:29 PM | edited on 07 Jun 2024, 03:29 PM

Hi,

So my work around until I can get the select event to reference the cell I just clicked on and not the "activeCell()" which might be the previous one by design...dunno.. is to do something similar in the change event:

Here is the code to the change event:

$("#spreadsheet").kendoSpreadsheet({
      columns: 100,
      rows: 1000,
      toolbar: false,
      sheetsbar: false,
      change: onChange,     
    // . . . schema/dataSource... other stuff below this.
});

//Then the onChange event handler:
  function onChange (e) {

    console.log("IN change handler(): SOMETHING CHANGED!")
    var spreadsheet = e.sender; // Get the Spreadsheet widget
    var selectedCell = spreadsheet.activeSheet().activeCell();
    console.log("AFTER change event: the cell value: " + selectedCell);

    let selStrCell = selectedCell.toString();

    // I want the user to know if they are editing a field that
    //   is read only or editable: false:
    if (selStrCell.startsWith("A") 
        || selStrCell.startsWith("B") 
        || selStrCell.startsWith("C")) {
      
      // Probably want a kendo alert window here probably...but this will work.
      alert("The column for cell: [" + selStrCell.split(':',1) + "] is NOT editable");

      // IF sheet has a dataSource defined, then reverse/cancel the changes.
      if (spreadsheet.activeSheet().dataSource != undefined) { 
        spreadsheet.activeSheet().dataSource.cancelChanges();
      }
      return;
    }
  }

Here is the flow:

Nikolay
Telerik team
commented on 11 Jun 2024, 09:00 AM | edited

Hi George,

This approach looks good to me. Thank you for sharing it with the community. I am sure others will benefit from it.

Regards,

Nikolay

Tags
Spreadsheet
Asked by
George
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
George
Top achievements
Rank 2
Iron
Iron
Iron
Share this question
or