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
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

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
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:
Regards,
Kiril Nikolov
Telerik

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> ' +
'<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
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