Hi,
is there a way to modify the values of a status field in the colModel dynamically? Lets say we have a col Model with a field like:
... field ... name: "state",type: "select",
editoptions: {value: "0:state0;1:state1;2:state2;3:state3;4:state4"}
So I get a select field for my states with this values. But I need to dynamicaly decide which selectfields should be possible. If the state of the current row is state0, only state0 and state1 should be displayed. If state is state1, display should be state0, state1 and state2 and so on up to state 4 which should display only stae3 and state4.
Am I able to solve this with a formatter, or is there any other way to do such a thing.
To make it more difficult, lets say the states which are displayed generally are dependend on a user who is logged in, in my application. In a way the user only can see state0, state2 and state4. This can be made even more complicated, cause the transistion between state3 and state4 is not allowed to the current user.
Nevertheless, the states themself are dynamicaly either. Would it be helpful to dynamically generate the javascript for an object in my application, which represents a general state-class and use this object to generate my needed output in the formatter? So I can encapsulate the logic within this object, how my output is generated and additionaly I get only the states the user is able to see.
Should get me to kill two birds with one stone.
After rereading I hope its clear what I want to do, if not tell me and I will explain it with more details.
A Solution for the concrete Problem, thx to oleg:
editoptions : {
value : function(){
//a function can be called here:
currentRow=$("#order_items").getGridParam('selrow');
currentState=$("#order_items").getCell(currentRow,"state");
nastyGeneratedThings=function(){
... do some nasty things with currentState
... and generate what you want
}
return nastyGeneratedThings
}
I ran into some trouble, cause the function was only called once. So I have to set the recreateForm option in Navgrid.
navGrid("#pager", {
edit : true,
add : true,
del : true
}, {
height : 500,
width : 500,
// recreate the form every time when edit button is clicked.
// Default is false.
recreateForm : true
}
});
After that my function fires each time I click edit. Hope this helps someone somehow.