This is a migrated thread and some comments may be shown as answers.

How to get selection mode

3 Answers 113 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mikael
Top achievements
Rank 1
Mikael asked on 24 Mar 2021, 08:16 PM

Hi,

Two questions in one:

1. What is the proper way to determine the selection mode in a grid?

Right now, I use this code in TypeScript:

isMultipleSelection(grid: kendo.ui.Grid): boolean {
    // @ts-ignore
    if (grid && grid.selectable) {
        // @ts-ignore
        return grid.selectable.options.multiple;
    }
    return false;
}

Note how I must use ts-ignore, or else I get "Property 'selectable' does not exist on type 'Grid'."

In other words, Grid.selectable does not seem to be a "public" property, also I dislike having to use ts-ignore.

2. In general, is there a way to get access to the grid's current configuration?

 

3 Answers, 1 is accepted

Sort by
0
Mihaela
Telerik team
answered on 26 Mar 2021, 04:00 PM

Hello Fredrik,

Thank you for sharing the code snippet.

1. You could get the selection mode of the grid via the property "grid.options.selectable":

 

function isMultipleSelection(grid: kendo.ui.Grid): string | boolean {
  if (grid && grid.options.selectable) {
    return grid.options.selectable;
  }
  return false;
}

 

If "selectable" is enabled and "selectable.mode" is set, then the returned value will be the selected mode as a String ("row", "cell", "multiple, row" or "multiple, cell"). Otherwise, if only the property "selectable" is added in the grid configuration, the function will return a boolean (true or false).

Basically, the grid's properties are accessible through the "options" (kendo.ui.Grid.options: kendo.ui.GridOptions). 

2. In order to access the current configuration of the grid, you could use the method getOptions(). For example:

 

function getGridSettings(grid: kendo.ui.Grid) : Object {
  return grid.getOptions();
}

 

If you have any other questions, don't hesitate to let me know.

 

Regards, Mihaela Lukanova 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.

0
Mikael
Top achievements
Rank 1
answered on 26 Mar 2021, 09:32 PM

Thanks, don't know how I missed grid.options.

Is there any difference between grid.options and grid.getOptions()?

0
Mihaela
Telerik team
answered on 29 Mar 2021, 04:09 PM

Hello Fredrik,

Both return an object, which contains the options that are currently enabled or disabled on the grid. 'getOptions()' is a method that returns a cloned object of the options. Whereas the 'options' is a property of the Kendo UI Grid that upon modifying might result in unexpected behavior in the grid. Therefore, it is important to gather the options via the API mehtod.

Let me know if you have any other questions.

 

Regards, Mihaela Lukanova 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.

Tags
Grid
Asked by
Mikael
Top achievements
Rank 1
Answers by
Mihaela
Telerik team
Mikael
Top achievements
Rank 1
Share this question
or