setting grid options with grid.setOptions on load

1 Answer 334 Views
Grid
Roel
Top achievements
Rank 1
Iron
Veteran
Roel asked on 10 Nov 2021, 01:15 PM

Hi,

At the moment I am searching for a way to set the options of the grid on load. We use the MVC grid. I know that it is not possible to set the grid options by events or datasource related functions. All examples I see are with a button. I like to set the options on document ready but the grid is undefined then.

Any idea?

Roel

1 Answer, 1 is accepted

Sort by
0
Yanislav
Telerik team
answered on 12 Nov 2021, 01:35 PM

Hi, Roel

You can set the options of the Grid on document.ready, provided the Grid is initialized on the page and is not loaded later than document.ready.

Here is a simple example of how to do it:

    $(document).ready(function () {
        var grid = $("#YourGridName").getKendoGrid(); // get a reference 
        var options = {
            resizable:true
        } //configure the options
        grid.setOptions(options)
    })

As you see in this example we get a reference to our Grid by its Name. We configure the desired options and pass them to the 'setOptions' function.

Regards,
Yanislav
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Roel
Top achievements
Rank 1
Iron
Veteran
commented on 23 Nov 2021, 07:38 AM

Hi Yanislav,

In my case the order of the columns has to be set like this. Is this possible with getConfig / setConfig? My other question is that I use a MVC grid in this case. Is the grid already an object when document is ready is fired?

Roel

Yanislav
Telerik team
commented on 23 Nov 2021, 09:16 AM

Hi Roel,

Please review the following sample. It demonstrates the Grid columns reordering functionality:

https://dojo.telerik.com/AbiZEkav

The same approach is applicable to the MVC Grid, since it has the same API as the Kendo UI Grid.

About the question, yes, when document.ready fires the Grid is initialized and you can get a reference to its client-side object. The 'dataBound' event is fired after the Grid is bound to data. So if accessing data is needed, you can use the 'dataBound' event. 

Regards,
Yanislav
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Grid
Asked by
Roel
Top achievements
Rank 1
Iron
Veteran
Answers by
Yanislav
Telerik team
Share this question
or