Search code examples
javajqueryjspstruts2jqgrid

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?


Solution

  • 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;
    }