Leave a fixed option in a PivotTable - JS

1

I have a PivotTable, which changes according to the user's select done in HTML. However, every time the page updates the selected option it also changes.

I thought of two possibilities that might work for what I want:

  • Create a variable and pass the current choice to this variable. Create a button called "Load" and every time this button fires, it will load whatever is within that variable;
  • Best way: create a default option and update this default option according to the user's choice.

The first option I even managed to do, but it continues to "refresh" the page and losing the value.

Here is the example code: link

Thanks,

    
asked by anonymous 03.04.2017 / 21:57

1 answer

1

To do this, store the value of select in localStorage , when loading page, update select value and call change event.

var dynamicTable = (function() {
    ...
})();

$(document).ready(function(e) {        
    var data1 = [...];        
    var data2 = [...];        
    var dt = dynamicTable.config(...);        

    $('.montadoras').change(function() {
        localStorage.setItem('montadoras_value', this.value);
        ...
    });

    var montadoraAtual = localStorage.getItem('montadoras_value');
    $('.montadoras').val(montadoraAtual).trigger("change");
});
    
03.04.2017 / 22:07