bthread
bthread

Reputation: 45

Kendo Grid: Clear Column Widths

I've got a grid that's width is 100%. The columns size equals out among all columns when the grid first loads. The user can then re-size columns to fit their need. Now I need a way to reset all the columns back to defaults without reloading the page.

I tried refreshing the grid but that didn't work after the grid has already been bound: .data().kendoGrid.refresh()

Upvotes: 1

Views: 1731

Answers (1)

OnaBai
OnaBai

Reputation: 40887

You might try a little trick (this is not perfect and might fail depending on your custom grid formatting). The trick is setting the widths to the same amount (ex. 100px). Something like:

Grid definition:

var grid = $("#grid").kendoGrid({
    dataSource: ds,
    resizable : true,
    pageable  : true,
    columns   :
    [
        { field: "FirstName", title: "First Name" },
        { field: "LastName", title: "Last Name" },
        { field: "City" }
    ]
}).data("kendoGrid");

Code for resizing:

$("col", grid.element).css("width", "100px");

In addition, you might be interested on doing:

$("table", grid.element).css("width", "100%");

This resizes the "table" columns to use all the original space otherwise (just doing the col resizing) you might end-up with equally spaced cols but not using all the original width of the table).

You can see how it works here: http://jsfiddle.net/OnaBai/a9QSr/

Upvotes: 1

Related Questions