0

I am working on wijmo grid and I want to add selection box inside the grid whos data is coming form JSON.

Here are my code which I tried but its not showing the option data inside box.

<script type="text/javascript">
$.ajax({ 
    url: "DeviceType",
    type: "GET",
    dataType: "json",
    contentType : "application/json",
    success: function (responce) { 
        if (responce.listResponse.items.length > 0) {
            $.each(responce.listResponse.items, function (i, entity) {                   
                $('#devicetype').append(
                    $('<select/>', {
                        'id': 'deviceType' + entity.paramCode,
                        'type': 'select', 
                        'name':         'deviceType', 
                        'value': entity.paramValue
                    }),
                    $('<options />', {
                        'for': 'deviceType' + entity.paramValue, 
                        'text':         entity.paramValue
                        }).click(function() {
                        alert(entity.paramCode);
                    })  
                    );                  
            });
        }
    }
});
</script>
<body>  
<div id="devicetype" name="deviceType" ></div>
</body>
1
  • 2
    did you try <option /> instead of <options />? Commented Sep 10, 2012 at 11:17

1 Answer 1

1

You are appending the options to the #devicetype, but you need to append them to the select:

/* not tested */
$( '#devicetype' ).append(
    $( '<select/>', {
        'id': 'deviceType' + entity.paramCode,
        'type': 'select',
        'name': 'deviceType',
        'value': entity.paramValue
    } ).append(
        $( '<option />', {
            'for': 'deviceType' + entity.paramValue,
            'text': entity.paramValue
        } )
    ).click( function() {
        alert( entity.paramCode );
    } )
);

UPDATE: Oh – and as tpaksu stated in the comment above, you have misspelled option. Maybe you should compile all the options first in a separate loop – the current version only works for one option.

Sign up to request clarification or add additional context in comments.

3 Comments

:Its working fine....but there is one more problem...It is showing too many selection box but I want only one and the Param value should show inside and when select paramCode will select....please help!!
As I said in the update: you wont create the select in a loop, but the option tags; store them into a variable and append them to a single select.
I have tried the code but its still giving the same output...can you please give me the code..? Thanks Tina!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.