with custom button select cell value

1 Answer 60 Views
Button Spreadsheet
kypdk
Top achievements
Rank 1
Iron
kypdk asked on 30 May 2022, 06:27 AM | edited on 30 May 2022, 08:15 AM

Hello,

What should I write to get the value inside the cell? I run in angular, I want to assign the cell value I selected to the variable.


  @ViewChild('spreadsheet') spreadsheetEl!: ElementRef;

  constructor(private hostEl: ElementRef) {}

  ngAfterViewInit() {
    kendo.jQuery(this.spreadsheetEl.nativeElement).kendoSpreadsheet({
           columns: 3,
           //rows: 10,
           sheetsbar: false,
           toolbar: {
            home: [
              "open", "exportAs",

              {
                  type: "button",
                  text: "Material select",
                  showText: "both",
                  icon: "k-icon k-i-cog",
                  click: function(e: any) {



                    var sheet = this.spreadsheetEl.nativeElement.activeSheet();
                    var range = sheet.selection();
                  }
              }
          ],
            insert: false,
            data: false,
            },
...

thank you

regards

1 Answer, 1 is accepted

Sort by
0
Accepted
Neli
Telerik team
answered on 01 Jun 2022, 01:55 PM

Hello,

You can use the Range value method in order to retrieve the current value of the selected cell:

var sheet = $("#spreadsheet").data('kendoSpreadsheet').activeSheet();
var range = sheet.selection();
var current = range.value()
console.log(current)

Here is a small example based on the provided snippet. 

I hope this helps.

Regards,
Neli
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

kypdk
Top achievements
Rank 1
Iron
commented on 29 Jun 2022, 11:48 AM | edited

ERROR TypeError: Cannot read properties of undefined (reading 'activeSheet') at init.click (submaterial.component.ts:49:75)

i am getting error. I couldn't run it in angular.

<div id="spreadsheet" class="spreadsheet" #spreadsheet></div>

 

works

thank you so much

Neli
Telerik team
commented on 04 Jul 2022, 07:17 AM

Hi Okay,

Below you will find a link to a StackBlitz example of a Kendo jQuery Spreadsheet initialized in Angular 2+ enviornment.

https://stackblitz.com/edit/angular-4j46pk?file=src%2Fapp%2Fapp.component.ts

If this does not help you could also open a thread in the Kendo UI for Angular forum https://www.telerik.com/forums/kendo-angular-ui

Regards,

Neli

Tags
Button Spreadsheet
Asked by
kypdk
Top achievements
Rank 1
Iron
Answers by
Neli
Telerik team
Share this question
or