Author Topic: colModel not save state  (Read 3276 times)

omerix

  • Pro Enterprise
  • Full Member
  • *
  • Posts: 148
    • View Profile
colModel not save state
« on: February 12, 2019, 08:09:37 pm »
Hello,

"colModel" column orders not work. I am using codes below.

saveState Code
Code: [Select]
grid.saveState();

stateKeys  Code
Code: [Select]
,stateKeys : {columnBorders:1,menuIcon:1,filterModel:['on','menuIcon','gridOptions','mode','header','timeout','type']}


create Code
Code: [Select]
,create: function(){
this.loadState({refresh: false});
var state = JSON.parse(localStorage.getItem("pq-grid"+this.element[0].id));
if (state!=null) {
this.option('filterModel', state.filterModel);
this.option('menuIcon', state.menuIcon);
this.option('columnBorders', state.columnBorders);
};

}

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: colModel not save state
« Reply #1 on: February 13, 2019, 02:26:19 pm »
Please restore individual filterModel properties of interest instead of restoring whole filterModel.

Code: [Select]
create: function () {
                //restore state of grid.                               
                this.loadState({ refresh: false });
var state = JSON.parse(localStorage.getItem("pq-grid"+this.element[0].id));
if (state!=null) {
var filterModel = state.filterModel || {};
this.option('filterModel.header', filterModel.header);
this.option('menuIcon', state.menuIcon);
this.option('columnBorders', state.columnBorders);
};
            },

omerix

  • Pro Enterprise
  • Full Member
  • *
  • Posts: 148
    • View Profile
Re: colModel not save state
« Reply #2 on: February 13, 2019, 04:02:22 pm »
Hello param,

I'm having trouble with colModel.

I think this happens because of the column merger.


The following figure needs a test.
https://paramquery.com/pro/demos/grid_state

Restoring column width. But the column does not load the order.
No problem with saveState. "Chrome" -> "F12" -> "Application" -> "Local storage" -> "Json" = True

Test Code Please. ({ title: "Shipping",colModel:[..........]})
Code: [Select]
        var colM = [
            { title: "ShipCountry", width: 100, dataIndx: "ShipCountry",
                filter: { crules:[{ condition: 'begin'}] }
            },
            { title: "Customer Name", width: 120, dataIndx: "ContactName",
                filter: { crules:[{ condition: 'begin' }] }
            },
            { title: "Order ID", minWidth: 130, dataIndx: "OrderID", dataType: "integer",
                filter: { crules:[{ condition: "between" }] }
            },
    { title: "Order Date", minWidth: "190", dataIndx: "OrderDate", dataType: "date" },
            { title: "Shipping Region", width: 140, dataIndx: "ShipRegion",
                filter: {
                    crules:[{ condition: 'range' }],
                    groupIndx: "ShipCountry"
                }
            },
            { title: "Paid", width: 100, dataIndx: "paid", dataType: "bool", align: "center",
                filter: { crules:[{ condition: "equal" }] }
            },
    { title: "Shipping Via", width: 130, dataIndx: "ShipVia",
        filter: {
            crules:[{ condition: 'range' }]
        }
    },
    { title: "Required Date", width: 100, dataIndx: "RequiredDate", dataType: "date" },
    { title: "Shipped Date", width: 100, dataIndx: "ShippedDate", dataType: "date" },
            { title: "Freight", width: 120, align: "right", dataIndx: "Freight", dataType: "float" },
            { title: "Shipping",colModel:[
            { title: "Name", width: 150, dataIndx: "ShipName" },
            { title: "Address", width: 270, dataIndx: "ShipAddress" },
            { title: "City", width: 100, dataIndx: "ShipCity" },
            { title: "Postal Code", width: 150, dataIndx: "ShipPostalCode" }
]}
];

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: colModel not save state
« Reply #3 on: February 13, 2019, 07:01:07 pm »
ok you have grouped columns.

Sorry, column order is not restored with loadState in case of grouped columns.

omerix

  • Pro Enterprise
  • Full Member
  • *
  • Posts: 148
    • View Profile
Re: colModel not save state
« Reply #4 on: February 13, 2019, 07:06:08 pm »
Thanks for the answer.



ok you have grouped columns.

Sorry, column order is not restored with loadState in case of grouped columns.