jQWidgets Forums

jQuery UI Widgets Forums Lists DropDownList DropDownList with numbers

Tagged: 

This topic contains 6 replies, has 2 voices, and was last updated by  AJRames 10 years, 10 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
  • DropDownList with numbers #57195

    AJRames
    Participant

    Hello,
    I am trying to bind a json data source to a dropdownlist.
    The source contains a Title (string) and an ID (number).

    
    var source =
                {
                    datatype: "json",
                    datafields: [
                        { name: 'Title', type: 'string' },
                        { name: 'ID', type: 'number' }
                    ],
                    url: url,
                    id: "ID",
                    async: false
                };
    
    var dataAdapter = new $.jqx.dataAdapter(source);
                // Create a jqxDropDownList
                $("#jqxDdl").jqxDropDownList(
                    {
                        source: dataAdapter,
                        selectedIndex: 1,
                        width: 400,
                        height: 25,
                        displayMember: "Title",
                        valueMember: "ID"
                    });
    

    Unfortunately the dropdownlist does not display any items.
    It only works, if I change the valueMember to “Title”.
    So I think that it cannot work with numbers!?

    I also tried to set the datafields like that:

    
    datafields: [
                        { name: 'Title', type: 'string' },
                        { name: 'ID', type: 'string' }
                    ]
    

    But it still does not work.

    Do you have any ideas how to fix this problem?

    Thanks in advance!

    DropDownList with numbers #57198

    Peter Stoev
    Keymaster

    Hi AJRames,

    There is no problem on our side. Please, look at: http://jsfiddle.net/jqwidgets/Ztv9e/ which shows that the widget works with Numbers. If you don’t see any data, then I suggest you to check your Data Binding and whether the URL is correct and whetehr your server returns any data.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    DropDownList with numbers #57203

    AJRames
    Participant

    Hi Peter,

    thanks for you answer.
    I use the same source for jqxGrid and jqxTreeGrid, too (e.g. http://www.jqwidgets.com/jquery-widgets-demo/demos/jqxgrid/bindingtojson.htm)
    It works there.
    Therefore the datasource has the required fields for sure.

    Thx

    DropDownList with numbers #57206

    Peter Stoev
    Keymaster

    Hi AJRames,

    It works in the DropDownList, as it usees the absolutely same data binding. If you experience an issue, please prepare and provide an example(preferably using jsfiddle) so we can test your scenario locally.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    DropDownList with numbers #57212

    AJRames
    Participant

    Ok, I understand that it is tricky to understand without an example.

    We access the data through odata.
    The result looks like this:

    ...
                  <content type="application/xml">
                         <m:properties>
                                <d:Id m:type="Edm.Int32">562</d:Id>
                                <d:ManualVersionGeb>1.0</d:ManualVersionGeb>
                                <d:ID m:type="Edm.Int32">562</d:ID>
                            </m:properties>
                     </content>
    ...
    

    Every property that is of type string will be displayed in the right way (example: “ManualVersionGeb”).
    If I want the ID it does not show anything.

    thx

    DropDownList with numbers #57216

    Peter Stoev
    Keymaster

    Hi AJRames,

    All I am saying is that your data binding code is obviously failing to load the data in the jqxDataAdapter. I cannot know what goes wrong without an example. So probably you have to set “map”, “root”, “record” or additional fields in the source object. The sample I sent you proves clearly that DropDownList can work with either Strings or Numbers, which your post states to be false. So, please, prepare an example an share it if you would like someone to try to help you. Giving parts of code which we or someone else cannot test will not be helpful for anyone.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    DropDownList with numbers #57230

    AJRames
    Participant

    Ok thanks for your help.
    We solved this issue by changing the result type to xml

    
    var source =
                {
                    datatype: "xml",
                    datafields: [
                        { name: 'Title', map: 'm\\:properties>d\\:Title', type: 'string' },
                        { name: 'ID', map: 'm\\:properties>d\\:ID', type:'string' }
                    ],
                    url: url,
                    root: "entry",
                    record: "content"
                };
    

    with this it works.
    It can be that the problem occurs because of the absence of root/record.

    Sorry that there wasnt a good example…

    best regards

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.