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

How do i declare common options in MVVM for the grid?

1 Answer 20 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Steven
Top achievements
Rank 1
Steven asked on 04 May 2017, 05:51 PM

Hi,

Using non-MVVM the grid has the setOptions function. There is no equivalent in MVVM. I want to create options that are standard on every grid across every one of my pages without having to declare those options every time.

Things like filterable, sortable, etc. need to be the same across all of my grids and declaring data-sortable="true" on every page seems pointless and can lead to mistakes. How do I do this in MVVM? In non-MVVM I could just have a central function like this:

    var setupStandardGridOptions = function(target) {
        if (target) {
            $(target).data("kendoGrid").setOptions({
                navigatable: true,
                filterable: true,
                sortable: true,
                resizable: true,
                selectable: true,
                pageable: {
                    pageSize: 20,
                    pageSizes: [20, 50, 100],
                    numeric: true
                }
            });
        }
    };

If I call this method in the init() of the view model it does not work. I can call it AFTER the view model is bound outside of the view model but any jquery like that for specific controls in the init() of the view model does no work. How do I set the options INSIDE the view model itself in either a single field or in a method during the init()?

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 09 May 2017, 07:23 AM
Hello Steven,

Apologies for the delayed response, we were short staff due to a national holiday.

Based on the provided information I can assume that this is probably a timing issue.

The setOptions method is called only on already initialized widgets.

Please ensure that the widget is available at the time when the function is called:

http://dojo.telerik.com/UYIZe

Also, this article may be helpful:

http://www.telerik.com/blogs/the-difference-between-kendo.bind-and-kendo.init 

If I missed an important detail, please send a runnable example, and I will gladly assist.

Regards,
Stefan
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data (charts) and form elements.
Tags
Grid
Asked by
Steven
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or