English 中文(简体)
jqGrid dynamic select fields
原标题:

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.

最佳回答

The value property from the editoptions can be not only a string but also a function. The function can return either a string like "0:state0;1:state1;2:state2;3:state3;4:state4" or a object like {"0":"state0", "1":"state1", "2":"state2", "3":"state3", "4":"state4"}. The last format by the way has some advantages: you can for example use : , ; inside of the values.

The function has no parameters, but you can get the current selected row with a coll like getGridParam( selrow ) method and with getCell(rowid,iCol) or getCell(rowid,"state") the current value of the "state" column.

See more in the description of the value property on http://www.trirand.com/jqgridwiki/doku.php?id=wiki:common_rules#editoptions). Probably this can solve your problem?

问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签