Using this code:
var grid = $("#gridDiv1").data("kendoGrid");
var options = localStorage["kendo-grid-options"];
if (options) {
grid.setOptions(JSON.parse(options));
}
It restores the column order and sizes (which I want), but messes up some of the header filtering. I have a two row header, customized to show either the filter button in the upper row or a filter cell in the lower row, or both. When reloading the state, the settings are lost. For example, and the most important glitch, I have a filter cell that is KendoNumericTextBox on which I do not want the spinners, but they appear on load state.
I tried accessing the item programmatically and resetting the spinners = false setting, but had no luck, and that would be insufficient to solve the problem anyway.
Thanks, Bob Graham
11 Answers, 1 is accepted
Hello Robert,
Can you please check the following example and edit it in order to show your exact setup so we can take a
look?
http://dojo.telerik.com/ehUDO
This is needed because, we need to know your exact setup and be able to reproduce the issue.
Thank you for the cooperation.
Regards,
Telerik
The only real difference I can see between the example and my code is that I'm using a local datasource.
I'm curious, what information is actually being saved when saving state? Upon inspecting the JSON string it seems that not only the grid state but the actual data is being stored. Is there a way to just store column order + settings and currently applied filters only? I already have a way of doing this thats faster and works though would be nice to have this feature built in.
getOptions() method will save all the options of the Kendo UI Grid and its dataSource. If you set the data as an option passed to the data option of the dataSource, then it will be saved with the getOptions() as well. If you bind the data using the transport option, then the data will not be saved.
As for the issue that you are facing - send us a sample that we can look at and we will be happy to assist you on resolving the issue.
Regards,
Kiril Nikolov
Telerik
Hi Kiril,
I'm using the kendo.stringify(grid.getOptions()) and grid.setOptions(JSON.parse(options)) and the filter rows are loaded successfully. The problem is that I´m using a toolbar template and when I load the grid state, the toolbar is disappearing.
How could I recover the custom toolbar?
Best regards
​
Hello Oscar Agusti,
Please check the following sample project and let me know if it helps:
Regards,
Kiril Nikolov
Telerik
Hi Kiril,
Thanks for the information. Now, the toolbar is preserved fine.
Best regards
Hello Oscar Agusti,
I am happy to hear that the issue is resolved.
In case you have any further questions, please do not hesitate to contact us.
Regards,
Kiril Nikolov
Telerik
Hello Kiril,
I have similar situation. My grid has function to initialize
filer - grid_GroupFilter. But getOptions() does not save it. Is it a bug?
Grid:
$("#grid").kendoGrid({
dataSource: dataSource,
pageable: {
pageSize: 15, pageSizes: [10, 15, 20], info: true,
input: true, previousNext: true, refresh: true
},
toolbar: ["create"],
columns: [
{
field: "name", title: "Group",
template: "#=name# <a
href='\\#' onclick='openGroupInfo(#= groupId #);return false;'
class='btn-open-info'></a>",
filterable: { ui: grid_GroupFilter, messages: { filter: "Search", info: ""}
}
},
{
title: "Members",
template: "<a href='\\#'
onclick='openApprovalGroupUser(#= groupId #);return
false;'>Members</a>", filterable: false
},
{
field: "active", title: "Active", width: "70px",
template: "<input type='checkbox' #=
active?'checked':'' # disabled/>", filterable: false
},
{
command: ["edit", "destroy"], title: " ", width: "220px" }
],
editable: "inline",
mobile: true,
filterable: { extra: false },
filterMenuInit: grid_filterMenuInit
});
}
getOptions() string:
{"prefix":"","name":"Grid","columns":[{"encoded":true,"field":"name","title":"Group","template":"#=name# <a
href='\\#' onclick='openGroupInfo(#= groupId #);return false;'
class='btn-open-info'></a>","filterable":{"messages":{"filter":"Search","info":""}},"headerAttributes":{"id":"6f0b6a3b-a58d-47a3-bb83-5fb7b827086e"}},{"encoded":true,"title":"Members","template":"<a
href='\\#' onclick='openApprovalGroupUser(#= groupId #);return
false;'>Members</a>","filterable":false,"headerAttributes":{"id":"3ced0d7c-cdfa-4f03-9969-1f6277af31b8"}},{"encoded":true,"field":"active","title":"Active","width":"70px","template":"<input
type='checkbox' #= active?'checked':'' #
disabled/>","filterable":false,"headerAttributes":{"id":"b84cc60c-bc93-4c41-950b-5b0356921e3c"}},{"encoded":true,"command":["edit","destroy"],"title":" ","width":"220px","headerAttributes":{"id":"5ceb0318-d77d-4edb-b756-fd24513dba1f"}}],"toolbar":["create"],"autoBind":true,"filterable":{"extra":false},"scrollable":true,"sortable":false,"selectable":false,"allowCopy":false,"navigatable":false,"pageable":{"pageSize":15,"pageSizes":[10,15,20],"info":true,"input":true,"previousNext":true,"refresh":true},"editable":"inline","groupable":false,"rowTemplate":"","altRowTemplate":"","noRecords":false,"dataSource":{"data":null,"schema":{"model":{"id":"groupId","fields":{"groupId":{"editable":false,"type":"number"},"name":{"validation":{"required":true},"type":"string"},"active":{"type":"boolean","defaultValue":true}}}},"offlineStorage":null,"serverSorting":false,"serverPaging":true,"serverFiltering":true,"serverGrouping":false,"serverAggregates":false,"batch":false,"transport":{"dataSource":null},"pageSize":15,"page":1,"filter":null,"group":[]},"height":null,"resizable":false,"reorderable":false,"columnMenu":false,"detailTemplate":null,"columnResizeHandleWidth":3,"mobile":true,"messages":{"editable":{"cancelDelete":"Cancel","confirmation":"Are
you sure you want to delete this
record?","confirmDelete":"Delete"},"commands":{"create":"Add
new record","cancel":"Cancel
changes","save":"Save
changes","destroy":"Delete","edit":"Edit","update":"Update","canceledit":"Cancel","excel":"Export
to Excel","pdf":"Export to
PDF"},"noRecords":"No records
available."},"excel":{"proxyURL":"","allPages":false,"filterable":false,"fileName":"Export.xlsx"},"pdf":{"fileName":"Export.pdf","proxyURL":"","paperSize":"auto","allPages":false,"landscape":false,"margin":null,"title":null,"author":null,"subject":null,"keywords":null,"creator":"Kendo
UI PDF Generator","date":null}}
Hello Ruben,
Would it be possible to create a separate support request, with more details about the issue that you are having, and we will be happy to help.
Regards,
Kiril Nikolov
Telerik
Hello Kiril,
Thank you for reply. I have created new thread http://www.telerik.com/forums/problem-with-filter-using-getoptions-setoptions