How to save rowcommand button to localstorage?

6 posts, 0 answers
  1. Montassar
    Montassar avatar
    3 posts
    Member since:
    Jun 2015

    Posted 29 Jun 2015 Link to this post

    Hi,

    I am a new user of Telerick, and i want to know if there is any way to save rowcommand button to localstorage?
    i am using a grid view, and for some columns i am implementing button to download some file from the server.
    Everything works well, only when i try to save the state of my grid to the local storage then when i reopen my grid all my buttons are not working any more.
    Thanks in advance.

     Thanks

     Monta

  2. Kiril Nikolov
    Admin
    Kiril Nikolov avatar
    2596 posts

    Posted 01 Jul 2015 Link to this post

    Hello Montassar,

     

    Can you please share with us some code that we can look at? How do you attach the click handlers to these buttons? When the grid state is restored the DOM is redrawn, so the elements that you attach click handlers to, might no longer be available, and this might be causing the issue.

     

    Regards,
    Kiril Nikolov
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. Montassar
    Montassar avatar
    3 posts
    Member since:
    Jun 2015

    Posted 01 Jul 2015 Link to this post

    Hi Kiril,

    Here is the way i am attaching the click :

    col.Command(command => command.Custom("Download").Click("downloadFile")).Title("Contrcat").Width(100);

    And then i am defining the methode downloadFile like this :

     function downloadFile (e) {
                var grid = $('#grid').data('kendoGrid');
                var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
                var codeContrat = dataItem.CodeContrat;
                var codeDemande = dataItem.codeDemande ;
                $.ajax({
                    type: "GET",
                    url: "/Dashboard/CheckForFile",
                    data: { CodeContrat: CodeContrat, codeDemande : codeDemande },
                    datatype: "json",
                    traditional: true,
                    success: function (data) {
                        if (data.FileExist) {
                            location.href = "@Url.Action("DownloadFile")" + "?codeContrat=" + codeContrat + "&codeDemande =" +codeDemande ;
                        } else {
                            window.KendoConfirm({
                                message: '<p>File Not Found  </p>'
                            });
                        }
                    },
                    }
                });
            }

     

    Thanks

    Montassar

  4. Kiril Nikolov
    Admin
    Kiril Nikolov avatar
    2596 posts

    Posted 02 Jul 2015 Link to this post

    Hello Montassar,

     

    I have tried to reproduce the issue in a simple example, but to no avail. Can you please check it out and let me know what I missed:

     

    http://dojo.telerik.com/IzUwA

     

    Regards,
    Kiril Nikolov
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  5. Montassar
    Montassar avatar
    3 posts
    Member since:
    Jun 2015

    Posted 03 Jul 2015 Link to this post

    Hello Kiril,

    I'm saving the state of my grid on Localstorage throw the button savestate :

    $(document).ready(function () {
                var grid = $("#grid").data("kendoGrid");
                var options = localStorage["kendo-grid-options" + '@Html.Raw(HttpUtility.JavaScriptStringEncode(@ViewBag.CurrentUser))'             + '@Html.Raw(HttpUtility.JavaScriptStringEncode(@ViewBag.Role))'];
                if (options) {
                    grid.setOptions(JSON.parse(options));
                    var exportbutton = '<button id="SaveState" class="k-button k-button-icontext"><span></span>Save grid state/button>&nbsp;' +
                        '<button id="InitState" class="k-button k-button-icontext"><span></span>Restore</button></div>';
                    $(".k-grid-toolbar", "#grid").addClass('k-header k-grid-toolbar k-grid-top');
                    $(".k-grid-toolbar", "#grid").html(exportbutton);
                }
                $("#SaveState").click(function (e) {
                    e.preventDefault();
                    localStorage["kendo-grid-options" + '@Html.Raw(HttpUtility.JavaScriptStringEncode(@ViewBag.CurrentUser))' +             '@Html.Raw(HttpUtility.JavaScriptStringEncode(@ViewBag.Role))'] = kendo.stringify(grid.getOptions());
                });
                $("#InitState").click(function (e) {
                    e.preventDefault();
                    localStorage.removeItem("kendo-grid-options" + '@Html.Raw(HttpUtility.JavaScriptStringEncode(@ViewBag.CurrentUser))' + '@Html.Raw(HttpUtility.JavaScriptStringEncode(@ViewBag.Role))');
                    location.reload();
                });

     

    Thanks for your Help.

    Montassar

  6. Kiril Nikolov
    Admin
    Kiril Nikolov avatar
    2596 posts

    Posted 07 Jul 2015 Link to this post

    Hi Montassar,

    I cannot see any issues with your code, would it be possible to edit the example that I sent you in order to reproduce the issue there, so we can take a look and advise you further?

    Regards,
    Kiril Nikolov
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top