Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the correct syntax to change options on an existing Kendo Grid?

I've got a Kendo Grid:

$('#myGrid').kendoGrid({
    ...
    scrollable: false,
    ...
});

and then later on I want to change its scrollable property. I've tried all of the following:

$('#myGrid').data("kendoGrid").options.scrollable = true;
$('#myGrid').data("kendoGrid").refresh();

-

$('#myGrid').data("kendoGrid").scrollable = true;
$('#myGrid').data("kendoGrid").refresh();

-

var MyGrid = $('#myGrid').data("kendoGrid");
MyGrid.options.scrollable = true;
MyGrid.refresh();

-

var MyGrid = $('#myGrid').data("kendoGrid");
MyGrid.scrollable = true;
MyGrid.refresh();

Nothing works. How does one change whether a grid is scrollable on the fly?

like image 778
Zook Avatar asked Oct 16 '13 18:10

Zook


People also ask

How do you put a filter on a kendo grid?

With the Kendo UI grid you can enable filter row in its header by setting the grid's filterable->mode property to row.

How do I set data for Kendo grid?

Bind data to Kendo Grid by using AJAX Read action method. Change the datasource on change event of any HTML controls. Normally, a developer can bind the data to Grid by using AJAX Read method. This read method is ActionResult method in MVC which will return JSON DataSourceResult & direclty bind the data to Grid.

What is selectable in kendo grid?

Description. There are situations when you would like to enable the end user to select rows or cells in the grid table, and process data from them or make calculations based on this selection. The Kendo UI grid supports selection by specifying its configuration via its selectable attribute.


2 Answers

This is not supported out of the box, so you'd have to mess with the internals. It's probably easier to just recreate the grid, but if you still think you need it, this fiddle might help point you in the right direction:

http://jsfiddle.net/lhoeppner/AKzzL/

Basically you could try using something like this:

function enableScrolling() {
    if (!grid.options.scrollable) {
        grid.options.scrollable = true;
        grid._thead();
        grid.refresh();
    }
}

function disableScrolling() {
    grid.options.scrollable = false;
    grid.table.unwrap(); // manually remove the wrapper that enables scrolling
}

Making a scrollable grid non-scrollable like that results in the data columns to have the wrong width though, so depending on your requirements, you may need to customize this some more.

like image 89
Lars Höppner Avatar answered Nov 14 '22 23:11

Lars Höppner


Options of the Grid cannot be changed dynamically. You need to re-create the whole Grid with different options in order to disable/enable them dynamically.

EDIT As from Q3 2014, the Grid supports the setOptions method, which does pretty much the same internally, but keeps most of the options and the state of the dataSource in sync.

like image 22
Petur Subev Avatar answered Nov 14 '22 21:11

Petur Subev