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

2 posts, 0 answers
  1. Steven
    Steven avatar
    1 posts
    Member since:
    Jul 2013

    Posted 04 May 2017 Link to this post

    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()?

  2. Stefan
    Admin
    Stefan avatar
    2892 posts

    Posted 09 May 2017 Link to this post

    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 visualization (charts) and form elements.
Back to Top