Excel export settings don't work after setOptions()

2 posts, 0 answers
  1. Paweł
    Paweł avatar
    1 posts
    Member since:
    Mar 2015

    Posted 05 Mar 2015 Link to this post


    I'm using 2014.3.1119.440 version of Kendo MVC UI.
    I configured the grid to export all data and a custom filename, and a custom toolbar with export to excel button.

    It works fine, when I don't restore grid options using setOptions function.
    When I restore it, with my custom toolbar preserve, it looks, like the export options are ignored.
    There are only records from current page exported and exported file has a standard name.

    I found the settings are correct in the page source.

    Do I need some extra steps to make the settings working after restoring grid options?

    Here's my razor grid code:

    @{ Html.Kendo().Grid<Vectra.CPN.CPNLibrary.ViewModel.TRANSFER_IN_V>()
            .ToolBar(toolBar => toolBar.Template(@<text>
                    <input class="t-button" type="button" id="ShowCreateNewExtFormId" name="ShowCreateNewExtForm" value="@Resources.Create" onclick="location.assign('@Url.Content("~/" + ControllerName + "/New")')"/>
                    <input class="t-button" type="button" id="ShowEditFormId" name="ShowEditForm" value="@Resources.Edit" />
                    <input class="t-button" type="button" id="ShowDetailFormId" name="ShowDetailForm" value="@Resources.Details" />
                    <a class="k-button k-button-icontext k-grid-excel" href="#"><span class="k-icon k-i-excel"></span>Zapisz do Excela</a>
                    <a href="" class="k-button" id="save">Save View</a>
                    <a href="" class="k-button" id="load">Restore View</a>
            .Excel(ex => ex.AllPages(true).FileName("cpn_do_vectry_" + DateTime.Now.ToShortDateString() + ".xlsx"))
            .ColumnMenu(column => column.Columns(true))
            .Columns(columns => columns.LoadSettings((IEnumerable<GridColumnSettings>)ViewBag.GridColumns))
            .Reorderable(reorder => reorder.Columns(true))
            .Sortable(sortable => sortable.Enabled(true).SortMode(GridSortMode.SingleColumn).AllowUnsort(true))
            .Pageable(pageable => pageable.Enabled(true).Refresh(true).ButtonCount(5).PageSizes(true).PageSizes(new int[] { 5, 10, 20, 50 }))
            .Filterable(filtering => filtering.Enabled(true))
            .Selectable(s => s.Mode(Kendo.Mvc.UI.GridSelectionMode.Single).Type(GridSelectionType.Row))
            .Events(events => events.Change("onChange"))
            .DataSource(dataSource => dataSource
                .Read(read => read.Action("TransferIn_Read", "TransferIn"))
                .Model(model => model.Id(o => o.TRANSFER_ID))

    and here's the part of my javascript for saving and restoring grid options:

    var localStorageKey = "MainTransferInOptions";
    var areOptionsLoaded = false;
    function bindSaveRestoreCliks()
        var grid = $("#MainGrid").data("kendoGrid");
        $("#save").click(function (e) {
            localStorage[localStorageKey] = kendo.stringify(grid.getOptions());
        $("#load").click(function (e) {
    function loadGridOptions(e)
        if (e == undefined || e.type == "click" || (!areOptionsLoaded && e.type == "read"))
            var rawGrid = $("#MainGrid");
            var grid = $("#MainGrid").data("kendoGrid");
            var options = localStorage[localStorageKey];
            var toolbar = $("#MainGrid").find(".k-grid-toolbar").html();
            if (options) {
            else if (!areOptionsLoaded && e == undefined)
            var newtoolbar = $("#MainGrid").find(".k-grid-toolbar");
            areOptionsLoaded = true;

    I restore the settings on page load:

    $(window).ready(function (e) {

    Thanks in advance.

  2. Petur Subev
    Petur Subev avatar
    1882 posts

    Posted 07 Mar 2015 Link to this post

    Hello Pawel,

    I posted a reply in the other thread that you opened on the same subject. For reference I will paste it here too:


    When the MVC wrappers are used and there is toolbar template (which is a server-side template and it might contain server logic) the setOptions will wipe the toolbar settings and we cannot re-execute the logic. What we provided as a work-around is shared here:


    Please give a try and let us know your findings.

    Kind Regards,
    Petur Subev

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

Back to Top