jQWidgets Forums

jQuery UI Widgets Forums Lists DropDownList custom rendering list with JSON/PHP

This topic contains 3 replies, has 3 voices, and was last updated by  jb 10 years ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • custom rendering list with JSON/PHP #54413

    jcf378
    Participant

    Hi –
    I think i’m overlooking something relatively simple:
    I’m trying to use the renderer property within a DropDownList widget to achieve a 2-row table for each dropdown item (very similar to the demo shown on jqwidgets website at ‘demos/jqxdropdownlist/rendering.htm’).
    This particular dropDownList widget is populated with JSON data from a separate PHP file — the PHP file is coded fine and generates the appropriate array string.
    However, I cannot seem to figure out how to get the renderer property to display the JSON data properly. If I remove the renderer property from the widget initiation, I get a perfectly functioning dropDownList, but without the 2-row table rendering (so therefore I know the PHP linkage is working OK). Yet with the renderer property written as in the code below, I can get the widget to display, but the dropdown is completely empty. I think my error is in how I’m defining variables within the renderer’s assigned function, but I’ve tried a bunch of options and the best I can get is a two-table row that gives me a bunch of “undefined” items in the dropdown…. Thoughts?
    –Jason
    ————————————-
    var source =
    { datatype: “json”,
    datafields: [
    { name: ‘code’ },
    { name: ‘text’ }
    ],
    url: ‘data.php’};
    var dataAdapter = new $.jqx.dataAdapter(source);

    $(“#dropdownlist”).jqxDropDownList(
    {
    source: dataAdapter,
    theme: theme,
    width: 100,
    height: 28,
    displayMember: ‘code’,
    valueMember: ‘code’,
    renderer: function (index, label, value) {
    var datarecord = source[index];
    var table = ‘<table><tr><td>’ + datarecord.code + ‘</td></tr><tr><td>’ + datarecord.text + ‘</td></tr></table>’;
    return table;
    }
    });


    Peter Stoev
    Keymaster

    Hi jcf378,

    That part: var datarecord = source[index]; is the issue. According to me, it should be: var datarecord = dataAdapter.records[index];

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com


    jcf378
    Participant

    Yup… works perfect!
    Thanks so much, Peter.
    –Jason

    custom rendering list with JSON/PHP #70021

    jb
    Participant

    Helped me too, thanks!

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

You must be logged in to reply to this topic.