PDA

View Full Version : How to save grid columns show up?



hmnth1
1 Oct 2013, 3:01 AM
While showing the grid we are having the option to show/hide the columns which we want to view.

If i unchecked a specific column it is is not showing in the grid. Upto this ok.
If i refresh the grid again the column is showing up.

But i need like this,

1. If i unchecked a particular column then it should not be visible in future to the user who did that one.
2. That column should be visible for other users other than the first user who unchecked a column.
3. If the user wants to show that in the grid then user can check that column and it should be shown.

Farish
1 Oct 2013, 3:46 AM
this can be done with cookies. read some basis tutorial on cookies and you will find out how to use them. there are functions available to read, set and delete cookies in these tutorials.

other than this, you can use Ext.state.Stateful by setting stateful to true and assigning a stateId to the component. This works for height, width etc. see if it also works for column hide/show states. First try it with stateful and if it doesnt store this info, then you can do it yourself with cookies.

hmnth1
1 Oct 2013, 4:37 AM
Yes i am doing the same thing as you specified.
like in my grid

i am specifying stateId and stateful :true and i am creating cookies like this

Ext.state.Manager.setProvider(Ext.create('Ext.state.CookieProvider'));

But if grid reloads data is not showed up correctly , data is replicating for some of the columns.

And if i click refresh icon there again the hidden column is appearing and data is appearing fine


Also can you please suggest where to intialize that cookieprovider line while developing a grid with some example code

Farish
1 Oct 2013, 4:42 AM
take a look at this example and view its source (right click -> View Page Source):

http://docs.sencha.com/extjs/4.2.2/extjs-build/examples/state/state.html

hmnth1
1 Oct 2013, 4:48 AM
The same example which i was looked into and implemented.

But i am using MVC architecture in my application. So i need exactly that where the below line should be kept.

Ext.state.Manager.setProvider(Ext.create('Ext.state.CookieProvider'));

Farish
1 Oct 2013, 4:50 AM
In the launch function of your application:

http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.app.Application-method-launch

hmnth1
1 Oct 2013, 4:53 AM
Thank you very much
I am just doing like that one.

I will test and let you know whether it is resolved or not

hmnth1
1 Oct 2013, 4:54 AM
Yes it is working. Thank you again

hmnth1
2 Oct 2013, 11:15 PM
Hi Farish,
Extra problems coming with this cookie manager. The grid is behaving abnormally. The columns are reordered by its own. I dont know why?
And
I want only the cookie part to remember is the show and hide of columns not the sort order etc.,

Is there any way to save the show, hide of columns in database and show up only those fields next time.

I think in the "model" also we have to modify that only the fields to be displayed that are saved in the database which are under category to be shown.