Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_TopicIcon
Default options, multiselect, extend
22/07/2008
16:10
Avatar
Creativebyte
Munich / Germany
Member
Members
Forum Posts: 17
Member Since:
22/07/2008
sp_UserOfflineSmall Offline

Hi,

I use jqGrid in some table with multiselect. Since I tend to have everything that belongs together in data structures (which are msot of the time seperate files) I did the same with all my grid options. I did my setup in a way:

var gridoptions = {

'grid_1': {url:...,datatype:...},
'grid_2':{....}

}

The problem is: when I use multiselect and open the page again and again, new rows with checkboxes are added all the time. I did a lot of research on this and finally came up with the solution: When the default optiosn and the user options are merged, the function $.extend from jQuery is used. In a normal case, where you specify your options directly in the code (and not like in my case in a seperate data structure) this is fine. But I store everything in my structure, so $.extend manipulates my setup instead of doing it only jqGrid internal. I think it has something to do with my multi-level object structure, but anyway: there is a simple solution: $.extend has another first option, that can be set to true. If this is done (and this is quite well hidden in the documentation), not a simple copy of the data structure is done (which is causing my problems), but a deep copy is done, like a recursive copy. So when I modify the code to $.extend(true,....) everything is working fine.

Long story short: In future versions, please enable deep copy for extend, it keeps me from changing the code every time again when a new version is coming out.

Thank you!

Creativebyte

23/07/2008
03:09
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Creativebyte,

Thank you very much for this. To be a honest I do not known

of this feature of $.extend. I will add this, but before this I should

do some tests.

Thank you

Best Regards

Tony

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

23/07/2008
10:44
Avatar
Creativebyte
Munich / Germany
Member
Members
Forum Posts: 17
Member Since:
22/07/2008
sp_UserOfflineSmall Offline

Hi Tony,

Neither did I, it took me a couple of days a going through raw jquery source code to know what's happening. As I said: I did the modification and it's working perfectly for me. The only difference in the extend behaviour is, that the complete object is really copied and not only the first level ("lower" levels are passed on by reference). jQuery sourcecode on this function is quite easy to read, if you do you will notice there is nothing to fear about.

I also did a quick snippet werwe you can see the effect:

<html>
    <head>
        <script type="text/javascript" src="jquery.js"></script>
    </head>
    <body>
        <script type="text/javascript">
        settings =   { a:1, b:2, c:[1,2,3]};
        def = { a:0, b:0, c:[0,0,0]};
       
        p = $.extend(def, settings ||{});
            p.c[0] = 25;
       
        console.log(settings);
        </script>
    </body>
</html>

If you call it like this, the settings object will me modified (c[0] will actually be 25 and not 0 like it should be). If you insert an boolean true as first parameter to extend, you will notice that the settings object remains untouched by operations on p (like it should be).

BR,

Creativebyte

23/07/2008
10:52
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Added in 3.2.1

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

25/07/2008
11:29
Avatar
Creativebyte
Munich / Germany
Member
Members
Forum Posts: 17
Member Since:
22/07/2008
sp_UserOfflineSmall Offline

Thanks a lot!

29/07/2008
09:39
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

But there is a big problem with this in your case:

$.extend($.jgrid.defaults,{rowList:[10,20,30]});

$("#mygrid").jqGrid({

.....

rowList: [],

..

});

rowList remain [10,20,30]

You can test this.

That means that the current settings of the grid are overwriten.

Maybe I will disable this in next release.

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

29/07/2008
14:01
Avatar
Creativebyte
Munich / Germany
Member
Members
Forum Posts: 17
Member Since:
22/07/2008
sp_UserOfflineSmall Offline

Hi tony,

I got no problem since I don't overwrite the default array. All I do is to store all my jqgrid options for all grids I use in my app in a big array-structure and since you do a deep copy now everything works fine for me.

30/07/2008
05:41
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

I think that we should support a wide range of possibilities. By example in my project I want to have in all grids this option rowList:[10,20,30], but in particular page I do not want this. Setting the rowList as common option have sence in relative big project, but what to do in a particular case when I do not want this? I think that this have sence. What do you think?

Best Regards

Tony

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

01/08/2008
08:02
Avatar
Creativebyte
Munich / Germany
Member
Members
Forum Posts: 17
Member Since:
22/07/2008
sp_UserOfflineSmall Offline

Hello tony,

I read your previous post again and you fell for the same mistake that was the basis for this bug report: You did a simple exted and not a deep copy! It seems that the second level of the options array (in your case the rowList) is not copied but linked, which causes the overwrite. So, if you do a deep copy like I suggested

$.extend(true,$.jgrid.defaults,{rowList:[10,20,30]});

you won't have any problems 🙂

On the other side, I use a different approach. I don't want to mess with the defaults since you never know if you won't get a new module in the app where you need to change it all back. Most of my grids (90%) use a lot of common options and they only differ in minor things (like postData and stuff).

My solution was quite simple. I have a default array per "grid group" where I store all common options and a specific options array for each grid in that group to set the specific options or even override the ones in my default array.

Having this, I run the extend function (deep copy!) on both arrays and get a combination of both in return. After doing this, I pass this array on to jqGrid. By doing this, the jqgrid default array remains untouched but I can define my own defautl array per group. maybe, this could be an enhancement for the library?

My idea would be: let the developer define multiple default arrays (named) when setting up the library.THis default woudl sit on top of the standard default array.

On each grid, he can choose whether to use the standard default array or one of the ones he specified before. Afterwards, he could overwrite those values as well as he can do now with the standard default array.

So, all I want to say is: why not bring an additional layer in between the standard default array and the grid specific options? In my code this would be really helpful (that's why I do this already but outside the library).

04/08/2008
04:30
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Thanks,

I will try this.

Regards

Tony

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
68 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

OlegK: 1255

markw65: 179

kobruleht: 144

phicarre: 132

YamilBracho: 124

Renso: 118

Member Stats:

Guest Posters: 447

Members: 11373

Moderators: 2

Admins: 1

Forum Stats:

Groups: 1

Forums: 8

Topics: 10592

Posts: 31289

Newest Members:

, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information