Forum
Hi,
i use 4.4.1 – jQuery Grid
Here is a colModel (without unrellevant fields):
{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
12:08
Moderators
30/10/2007
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.
I saw it and I use it:
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
12:29
Moderators
30/10/2007
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.
12:35
Moderators
30/10/2007
Hello,
You can do a simple trace like this:
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.
tony said:
What content return the custom_element in your code?
it returns the set of checkboxes:
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];
};
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.
18:26
Moderators
30/10/2007
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.
Thanks, I really appreciate your help.
I also tried another custom element, without formatting, and got the same problem.
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);
}
}
}
}
10:15
10/08/2009
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
11:25
Moderators
30/10/2007
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.
🙁 it doesn't help
I 've added a defaultValue to 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.
13:18
Moderators
30/10/2007
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.
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 :
recreateForm: 1
});
before initiating my grid. But it doesn't solve my problem. I even changed recreateForm : true, in editGridRow function.
But nothing ...
15:01
Moderators
30/10/2007
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.
15:09
Moderators
30/10/2007
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.
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
never run.
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.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66