jQWidgets Forums

jQuery UI Widgets Forums Lists DropDownList jqxDropdownlist custom rendering issue

This topic contains 1 reply, has 2 voices, and was last updated by  Dimitar 8 years, 10 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author

  • magostoni
    Participant

    Actually I’m using a jqxDropDownList widgets, loading data from a service written in php that send back JSON data.

    these are the json data returned back by Produzione_materiali/get_elenco_materiali service:
    [{"TotalRows":"6","Rows":[{"codmateriale":"ALLUMINIO","unita":"PZ","prezzo":"0.00000"},{"codmateriale":"FERRO","unita":"PZ","prezzo":"0.00000"},{"codmateriale":"LEGNO","unita":"PZ","prezzo":"0.00000"},{"codmateriale":"OTTONE","unita":"PZ","prezzo":"0.00000"},{"codmateriale":"PLASTICA","unita":"PZ","prezzo":"0.00000"},{"codmateriale":"ZAMA","unita":"KG","prezzo":"2.25000"}]}]

    This is the javascript code to display jqwidget:

            var source =
            {
                datatype: "json",
                datafields: [
                    { name: 'codmateriale' },
                    { name: 'unita' }
                ],
                url: '<?php echo site_url("/Produzione_materiali/get_elenco_materiali/");?>',
                root: 'Rows',
                async: false
            };
            var dataAdapter = new $.jqx.dataAdapter(source);
    
            $("#materiale").jqxDropDownList({
                source: dataAdapter, displayMember: "codmateriale", valueMember: "codmateriale", width: '100%', height: 25
            });

    What I would need, is to show in the dropdown something like “codmateriale” + “[” + unita + “]”
    I would like to use custom rendering but I was not able to figure out how to get the 2 fields:

                renderer: function (index, label, value) {
                    var datarecord = source[index];
                    var text = source.codmateriale + "[" + source.unita + "]"
                    return text;
                }

    Could someone help me?

    Regards,
    Matt


    Dimitar
    Participant

    Hello Matt,

    Here is how to achieve your requirement:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" />
        <script type="text/javascript" src="../../scripts/jquery-1.11.1.min.js"></script>
        <script type="text/javascript" src="../../scripts/demos.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxcore.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxdata.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxbuttons.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxscrollbar.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxlistbox.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxdropdownlist.js"></script>
        <script type="text/javascript">
            $(document).ready(function () {
                var data = [{
                    "TotalRows": "6",
                    "Rows": [{
                        "codmateriale": "ALLUMINIO",
                        "unita": "PZ",
                        "prezzo": "0.00000"
                    }, {
                        "codmateriale": "FERRO",
                        "unita": "PZ",
                        "prezzo": "0.00000"
                    }, {
                        "codmateriale": "LEGNO",
                        "unita": "PZ",
                        "prezzo": "0.00000"
                    }, {
                        "codmateriale": "OTTONE",
                        "unita": "PZ",
                        "prezzo": "0.00000"
                    }, {
                        "codmateriale": "PLASTICA",
                        "unita": "PZ",
                        "prezzo": "0.00000"
                    }, {
                        "codmateriale": "ZAMA",
                        "unita": "KG",
                        "prezzo": "2.25000"
                    }]
                }];
    
                var source = {
                    datatype: "json",
                    datafields: [{
                        name: 'codmateriale'
                    }, {
                        name: 'unita'
                    }],
                    localdata: data,
                    root: 'Rows',
                    async: false
                };
                var dataAdapter = new $.jqx.dataAdapter(source);
    
                $("#materiale").jqxDropDownList({
                    source: dataAdapter,
                    displayMember: "codmateriale",
                    valueMember: "codmateriale",
                    width: '100%',
                    height: 25,
                    renderer: function (index, label, value) {
                        var datarecord = dataAdapter.records[index];
                        var text = datarecord.codmateriale + "[" + datarecord.unita + "]";
                        return text;
                    }
                });
            });
        </script>
    </head>
    <body>
        <div id='materiale'>
        </div>
    </body>
    </html>

    Best Regards,
    Dimitar

    jQWidgets team
    http://www.jqwidgets.com/

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

You must be logged in to reply to this topic.