This is a migrated thread and some comments may be shown as answers.

How to save rowcommand button to localstorage?

5 Answers 125 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Montassar
Top achievements
Rank 1
Montassar asked on 29 Jun 2015, 02:14 PM

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

5 Answers, 1 is accepted

Sort by
0
Kiril Nikolov
Telerik team
answered on 01 Jul 2015, 08:35 AM

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
0
Montassar
Top achievements
Rank 1
answered on 01 Jul 2015, 01:24 PM

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

0
Kiril Nikolov
Telerik team
answered on 02 Jul 2015, 08:18 AM

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
0
Montassar
Top achievements
Rank 1
answered on 03 Jul 2015, 09:26 AM

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

0
Kiril Nikolov
Telerik team
answered on 07 Jul 2015, 06:22 AM
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
Tags
Grid
Asked by
Montassar
Top achievements
Rank 1
Answers by
Kiril Nikolov
Telerik team
Montassar
Top achievements
Rank 1
Share this question
or