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
This topic is locked No permission to create posts
sp_Feed Topic RSS sp_Related Related Topics sp_TopicIcon
When Add or first time Edit, there is no call to custom_value function
16/01/2013
10:27
Avatar
elivol
Israel
Member
Members
Forum Posts: 15
Member Since:
01/06/2010
sp_UserOfflineSmall Offline

Hi,

i use 4.4.1 – jQuery Grid

Here is a colModel (without unrellevant fields):

colModel : [
                {name:'id',index:'id', width:70, editable:true, editoptions:{readonly:true}, sorttype:'int'},
                {name:'activity_scope',index:'activity_scope', width:250, editable:true, edittype:'custom',
                    editoptions:{
                        custom_element: function(value, options) {
                            var obj = new Contact();
                            return obj.getActivityScopeElement(value, options);
                        },
                        custom_value: function(elem, operation, value) {
                            var obj = new Contact();
                            return obj.getActivityScopeValue(elem, operation, value);
                        }
                    },
                    formatter: function(cellvalue, options, rowObject) {
                        var scope = $j.parseJSON( Runtime.getParam('scope_activity') );
                        var ret = [];
                        $j.extend(scope.buyer, scope.seller);
                        $j.each(scope.buyer, function(i, el) {
                            if(cellvalue & i) {
                                ret.push(el) ;
                            }
                        });
                        return ret.slice(', ') + '<input type="hidden" value="'+cellvalue+'" />';
                    },
                    unformat:function(cellvalue, options, rowObject) {
                        return $j(rowObject).find('input[type=hidden]').val();
                    },
                    sorttype:'string'}
            ]

The problem is in Add – recieve element values from a previous edit; and first time Edit – no element values have been set.

I checked with firebug and fount that there is no call to custom_value function in these cases.

When I close the Edit popup and open it again, for any row, there are no problems.

Thanks

16/01/2013
12:08
Avatar
tony
Sofia, Bulgaria
Moderator
Members

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

Hello,

Check for documentation for custom value function.

There are parameter operation which you should pay attention.

In the docs there is example how to use it.

Regards

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.

16/01/2013
12:18
Avatar
elivol
Israel
Member
Members
Forum Posts: 15
Member Since:
01/06/2010
sp_UserOfflineSmall Offline

I saw it and I use it:

this.getActivityScopeValue = function(elem, operation, value) {
        if(operation === 'get') {
            var val = 0;
            $j(elem).find("input:checked").each(function(i, el){
                val += parseInt( $j(el).val() );
            });
            return val;
        } else if(operation === 'set') {
            $j(elem).find("input").each(function(i, el){
                var checked = (parseInt( $j(el).val() ) & value) > 0;
                $j(el).attr('checked', checked);
            });
        }
    };

but as I've explaned this function has not been called in first Edit or Add actions.

Thanks

16/01/2013
12:29
Avatar
tony
Sofia, Bulgaria
Moderator
Members

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

Hello,

What content return the custom_element in your code?

Regards

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.

16/01/2013
12:35
Avatar
tony
Sofia, Bulgaria
Moderator
Members

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

Hello,

You can do a simple trace like this:

this.getActivityScopeValue = function(elem, operation, value) {
       
alert(operation);
if(operation === 'get') {
            var val = 0;
            $j(elem).find("input:checked").each(function(i, el){
                val += parseInt( $j(el).val() );
            });
            return val;
        } else if(operation === 'set') {
            $j(elem).find("input").each(function(i, el){
                var checked = (parseInt( $j(el).val() ) & value) > 0;
                $j(el).attr('checked', checked);
            });
        }
    };

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.

16/01/2013
17:19
Avatar
elivol
Israel
Member
Members
Forum Posts: 15
Member Since:
01/06/2010
sp_UserOfflineSmall Offline

tony said:

What content return the custom_element in your code?


it returns the set of checkboxes:

this.getActivityScopeElement = function(value, options) {
        var scope = $j.parseJSON( Runtime.getParam('scope_activity') );
        var elemStr = '<table class="activity_scope"><thead><tr><th>Buyer's side</th><th>Seller's side</th></tr></thead><tbody>';
        elemStr += '<tr>';
        elemStr += '<td>';
        $j.each(scope.buyer, function(i, el) {
            elemStr += '<div><input type="checkbox" name="activity_scope" value="'+ i +'" /><label>'+ el +'</label></div>';
        });
        elemStr += '</td>';

        elemStr += '<td>';
        $j.each(scope.seller, function(i, el) {
            elemStr += '<div><input type="checkbox" name="activity_scope" value="'+ i +'" /><label>'+ el +'</label></div>';
        });
        elemStr += '</td>';

        elemStr += '</tr>';
        elemStr += '</tbody></table>';
        return $j(elemStr)[0];
    };

16/01/2013
17:28
Avatar
elivol
Israel
Member
Members
Forum Posts: 15
Member Since:
01/06/2010
sp_UserOfflineSmall Offline

tony said:

Hello,

You can do a simple trace like this:

this.getActivityScopeValue = function(elem, operation, value) {
       
alert(operation);
if(operation === 'get') {
            var val = 0;
            $j(elem).find("input:checked").each(function(i, el){
                val += parseInt( $j(el).val() );
            });
            return val;
        } else if(operation === 'set') {
            $j(elem).find("input").each(function(i, el){
                var checked = (parseInt( $j(el).val() ) & value) > 0;
                $j(el).attr('checked', checked);
            });
        }
    };

I added alert(operation);

it jumps only on secont and more Edit (but not in first time) and never in Add action.

16/01/2013
18:26
Avatar
tony
Sofia, Bulgaria
Moderator
Members

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

Hello,

Thanks. Seems to be a problem. Will look at this tomorrow and let you know.

Regards

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.

17/01/2013
09:28
Avatar
elivol
Israel
Member
Members
Forum Posts: 15
Member Since:
01/06/2010
sp_UserOfflineSmall Offline

Thanks, I really appreciate your help.

I also tried another custom element, without formatting, and got the same problem.

{name:'created',index:'created', width:150, editable:true, editoptions:{readonly:true}, sorttype:'string', edittype:'custom', editoptions:{
                        custom_element: function(value, options) {
                            return '<span></span>';
                        },
                        custom_value: function(elem, operation, value) {
                            if(operation === 'get') {
                                return $j(elem).text();
                            } else if(operation === 'set') {
                                $j(elem).text(value);
                            }
                        }
                    }
                }

17/01/2013
10:15
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

I suppose that you have just an old problem with requirement to use recreateForm: true. See the answer for example.

I suggested Tony multiple times (see here for example) to change default value of recreateForm from false to true.

Best regards
Oleg 

17/01/2013
11:22
Avatar
elivol
Israel
Member
Members
Forum Posts: 15
Member Since:
01/06/2010
sp_UserOfflineSmall Offline

Thanks, but it doesn't help.

If i set recreateForm:true it never works, but if :

jQuery.extend(jQuery.jgrid.edit, {
                recreateForm: 1
            });

it returns to the original problem - doesn't work on a first Edit or Add.

17/01/2013
11:25
Avatar
tony
Sofia, Bulgaria
Moderator
Members

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

Hello,

Thanks.

I just fixed the problem in GitHub.

For the add mode you will need to use defaultValue event - see docs.

Please let me know if it is ok now.

@Oleg,

The problem was not in recreateForm, but we miss calling the default_value immediate the element is created.

Thank you all.

Kind 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.

17/01/2013
12:07
Avatar
elivol
Israel
Member
Members
Forum Posts: 15
Member Since:
01/06/2010
sp_UserOfflineSmall Offline

🙁 it doesn't help

I 've added a defaultValue to editoptions:

editoptions:{
                        custom_element: function(value, options) {
                            var obj = new Contact();
                            return obj.getActivityScopeElement(value, options);
                        },
                        custom_value: function(elem, operation, value) {
                            var obj = new Contact();
                            return obj.getActivityScopeValue(elem, operation, value);
                        },
                        defaultValue: function() {
                            return 0;
                        }
                    }

the function defaultValue has been called on each Add, but custom_element called only on first time Add, that's why elements in Add form get values from a previous Edit.

17/01/2013
12:21
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

You should use recreateForm: true in any way, but with new code fixed by Tony.

17/01/2013
13:18
Avatar
tony
Sofia, Bulgaria
Moderator
Members

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

Hello,

If you want to call custom_element every time you open the form in add and edit mode you should follow the Oleg suggestion.

Regards

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.

17/01/2013
13:46
Avatar
elivol
Israel
Member
Members
Forum Posts: 15
Member Since:
01/06/2010
sp_UserOfflineSmall Offline

Hello guys,

So, I should to put a new code:

if($.isFunction(opt.custom_value) && rowid !== "_empty" ) {
  opt.custom_value.call($t, $("#"+nm,"#"+frmgr),'set',tmp);
}

$.jgrid.bindEv( elc, opt, $t);// this line also missing

into jquery.jqGrid.src.js and than minimize it?

Thanks

17/01/2013
14:51
Avatar
elivol
Israel
Member
Members
Forum Posts: 15
Member Since:
01/06/2010
sp_UserOfflineSmall Offline

I put a new code to jquery.jqGrid.src.js (I temporay use it instead of jquery.jqGrid.min.js) to the function createData.

Line $.jgrid.bindEv( elc, opt, $t); throws an error, so I removed it.

I also use a :

jQuery.extend(jQuery.jgrid.edit, {
                recreateForm: 1
            });

before initiating my grid. But it doesn't solve my problem. I even changed recreateForm : true, in editGridRow function.

But nothing ...

17/01/2013
15:01
Avatar
tony
Sofia, Bulgaria
Moderator
Members

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

Hello,

You make a mistake adding the bindEv. Please add only the code that is canged. Not sure if you do it right.

Clear browser cache and try - this is very important .

Regards

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.

17/01/2013
15:09
Avatar
tony
Sofia, Bulgaria
Moderator
Members

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

Also recreateForm is a option which should be set as edit option for add and edit - please consult the docs ....

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.

17/01/2013
15:16
Avatar
elivol
Israel
Member
Members
Forum Posts: 15
Member Since:
01/06/2010
sp_UserOfflineSmall Offline

Hello

As I noticed, I removed the problematic line $.jgrid.bindEv( elc, opt, $t); .

I also see a new added code in Firebug, so it loaded.

I debugged the code, function createData called on Add action, and also I have to notice that row

opt.custom_value.call($t, $("#"+nm,"#"+frmgr),'set',tmp);

never run.

This topic is locked No permission to create posts
Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
53 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