Pradnya
Pradnya

Reputation: 669

Get selected value in the formatter of select in Struts 2 jQuery grid

This is my Struts 2 grid column:

<sjg:gridColumn name="interview_notif" index="interview_notif" title="Interview Notification" editable="true" sortable="false" formatter="IntrvNot"/> 

And this is the formatter I have used:

function IntrvNot(value, options, rowObject){
 var radioHtml = '<select><option value="1">Yes</option><option value="2">No</option></select>';         
 return radioHtml;

The formatter creates a select with two options but it does not select the one which is in the array.

How do set the selected value to that in the database(array) when the grid populates?

Upvotes: 1

Views: 617

Answers (1)

Roman C
Roman C

Reputation: 1

the value in the dropdown list shuld be selected as that in the arraylist

providing a map of options instead of arraylist

function IntrvNot(value, options, rowObject){
    var option = {1:"Yes", 2: "No"};
    var radioHtml = '<select>';
    $.each(option, function(key, val){
        radioHtml+='<option value="'+key+'"'+(key==value?' selected="selected"':'')+'>'+val+'</option>';
    });
    radioHtml+='</select>';
    return radioHtml;
}

Upvotes: 1

Related Questions