Using ExtJS to develop MIS system (3): Saving client state with database

Source: Internet
Author: User

As we all know, a tool like Vs.net remembers when we last closed: the position of each window, size, toolbar status, custom menu items, and so on. This is undoubtedly a function to use. ExtJS also contains a state-saving mechanism whose main controls: Girdpanel,formpanel, and so on, all provide state-saving functionality. What we need is just to provide it with the right provider.

1, save the state of the client

Let's take a look at the process of persisting the control state when a control state changes in a ExtJS:

The first two steps (red) in the process are responsible for the control. When a control state changes, it uses JSON to serialize its state, and then calls the Ext.state.Manager.getProvider () static method to obtain the provider of the current program configuration, and then invokes the provider set method to save its state. What we need to do is to provide a provider, and when its set method is invoked, it is OK to save the state of the control passed over to the server. The code for the provider is as follows:

1:srims.providerctor = Ext.extend (Ext.state.Provider, {
2:
3:get:function (name, defaultvalue) {
4://alert (' get: ' + name + ': ' + srims.provider._state[name]);
5://return DefaultValue;
6:
7:if (Srims.provider._state[name])
8:return Ext.util.JSON.decode (Srims.provider._state[name]);
9:
10:return DefaultValue;
11:},
12:set:function (name, value) {
//alert (' Set: ' + name + ' + Ext.util.JSON.encode (value));
14:var valuestring = Ext.util.JSON.encode (value)
15:srims.provider._state[name] = valuestring;
16:
17:ext.ajax.request ({
18:url: '/user.asmx/setextclientstate ',
19:method: ' POST ',
20:params: {
21:key:name,
22:value:valuestring
23:}
24:});
25:},
26:clear:function (name) {
27:srims.provider._state[name] = undefined;
28:}
29:});
30:
31:srims.provider = new Srims.providerctor ();
32:srims.provider._state = new function () {
33:};

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.