简体   繁体   English

Angularjs dataTable stateSave 无法更改路线

[英]Angularjs dataTable stateSave not woking on change routes

I'm using AngularJS datatable and enable save state with .withOption('stateSave', true) .我正在使用 AngularJS 数据表并使用.withOption('stateSave', true)启用保存状态。

when I refresh the page, everything works fine But when I change routes, and came back, stateSave not working.当我刷新页面时,一切正常但是当我改变路线并回来时, stateSave不起作用。


I found that , At each route change, datatable create a localStorage to save current table state with difference key !我发现,在每次路由更改时,数据表都会创建一个localStorage以使用不同的key保存当前表状态! so when change route, saveState not working.所以当改变路线时,saveState 不起作用。

How can I solve the problem?我该如何解决问题?

只需向<table>元素添加一个id属性,例如<table id="xxx" datatable>

Add an attribute id into the table.将属性 id 添加到表中。 And add the following code into your angularjs controller并将以下代码添加到您的 angularjs 控制器中

$scope.vm.dtOptions = DTOptionsBuilder.newOptions()
    .withOption('stateSave', true);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM