save columns state

Show cool things you have done with our products


Post Reply
User avatar
Dev_Coppelis
Premium Member
Premium Member
Posts: 287
Joined: Thu Oct 05, 2017 3:38 pm

save columns state

Post by Dev_Coppelis »

i need to save the states of columns like order, sorting,.....
but i found 4 events for that

Code: Select all

stateEvents: [
        'columnmove',
        'columnresize',
        'columnhide',
        'columnshow'
    ]
but when adding new columns its state doesn't be saved so there is any solution for this ? :roll: :roll:

User avatar
Terence
Core Developer
Core Developer
Posts: 1528
Joined: Tue Apr 01, 2014 2:23 pm

Re: save columns state

Post by Terence »

If you add a new column it will probably trigger the show event, then it's state is stored.

User avatar
Dev_Coppelis
Premium Member
Premium Member
Posts: 287
Joined: Thu Oct 05, 2017 3:38 pm

Re: save columns state

Post by Dev_Coppelis »

Code: Select all

stateful: true,
    stateId: 'stateGrid',
    stateEvents: [
        'columnmove',
        'columnresize',
        'columnhide',
        'columnshow'
    ]
here are the steps to save the state of columns order.
are there any missing steps to follow ?

User avatar
Terence
Core Developer
Core Developer
Posts: 1528
Joined: Tue Apr 01, 2014 2:23 pm

Re: save columns state

Post by Terence »

I think you should follow sencha's guides about the stateful mechanism.
https://docs.sencha.com/extjs/6.2.0/cla ... g-stateful

The stateEvents are only triggered when the state is saved. More important is which properties to save.
Setting the grid to stateful should handle the sorting of your columns. When something additional needs to be done you can customise the getState and setState functions of a component. I think you will find more answers about this on Sencha's forum.

User avatar
vandries
Premium Member
Premium Member
Posts: 145
Joined: Mon Mar 06, 2017 1:36 pm

Re: save columns state

Post by vandries »

hi,
it looks like

Code: Select all

                    stateId: 'gantt-cols',
                    stateful: {
                        columns: true
                    },

properties might do the job.

but it's for only these columns that are defined in the app,
I mean by columns property.

Scenario1 (I've used fiddle app for testing from examples dir)
1. click on Duration column action icon (arrow down) - to hide it (uncheck for col list)
2. refresh;
3. it will be hidden
4. 1. click on Duration column action icon (arrow down) - to show it (check for col list)
5. refresh
6. the duration column will be visible;

Scenario2
same 1-3 steps
4. click add new column - and pick duration to show duration column
5. refresh;
6. no change - duration col is not visible
but
if we
7. click on start and check Duration column on
8. hmm now I see 2 duration options - why?
two Duration cols, why?
two Duration cols, why?
Screen Shot 2018-10-10 at 15.02.40.png (29.98 KiB) Viewed 4386 times
imho add new column should simple activate if column already exists in the list (hidden) - but that's my 2c

I'm not sure how to make add new columns to save the state.
Sencha tells that if property is changed - then the state is saved in the "storage".
I don't see how new columns is affecting columns property - since it doesn't trigger state manger to save the state.
Shouldn't adding new column at least triggers columnchanged,columnshow event?

User avatar
pmiklashevich
Core Developer
Core Developer
Posts: 3070
Joined: Fri Apr 01, 2016 11:08 am

Re: save columns state

Post by pmiklashevich »

Hello,

"Add new column" just adds a new instance of a column to the grid. You can have as many columns with the same xtype as you wish. Since default column title is the same you see 2 duration columns in the dropdown list. But in fact they are 2 different columns. "Add new column" feature shouldn't affect the process of saving the column state.

I'm afraid saving the column state is a bit out of the scope of this forum, it's better to ask for a solution on Sencha forums.

I assume you are looking at Advanced sample and using column set from the sample. To simplify your application you can try to remove 'addnewcolumn' from the columns definition.

Best regards,
Pavel Miklashevich - Core Developer

Post Reply