jQWidgets Forums

jQuery UI Widgets Forums Grid problem with dynamic columns

This topic contains 2 replies, has 1 voice, and was last updated by  jbrahy 10 years, 5 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • problem with dynamic columns #64503

    jbrahy
    Participant

    Hello JQWidgets Team,

    I love your products and thanks for adding the functionality for dynamic columns in grids. I am trying to send all the info to generate a grid in a single json document as shown below. The error I keep getting is, “Uncaught TypeError: #<Object> is not a function” and it’s on this line. I’m not sure what I’m doing wrong and hoping that you can point me in the right direction.

    $(“#jqxgrid”).jqxGrid({
    source: gridAdapter,
    columns: columns
    });

    Here’s the JSON document:

    
    {
        "header": [
            "Server_Name",
            "Server_Size"
        ],
        "body": [
            {
                "Server_Name": "Server 1",
                "Server_Size": "911481"
            },
            {
                "Server_Name": "Server 2",
                "Server_Size": "918951"
            },
            {
                "Server_Name": "Server 3",
                "Server_Size": "808673"
            },
            {
                "Server_Name": "Server 4",
                "Server_Size": "917263"
            },
            {
                "Server_Name": "Server 5",
                "Server_Size": "378562"
            },
            {
                "Server_Name": "Server 6",
                "Server_Size": "323561"
            }
        ]
    }
    

    Here’s my javascript:

    
    <script type="text/javascript">
        //<![CDATA[
        $(document).ready(function () {
            var url = "/sample.json";
            // prepare the data
            var source =
            {
                datatype: "json",
                url: url
            };
            var dataAdapter = new $.jqx.dataAdapter(source, {
                    autoBind: true,
                    downloadComplete: function (data) {
    
                        var header = data.header;
                        var rows = data.body;
                        var datafields = [];
                        var columns = [];
    
                        for (header_index = 0; header_index < header.length; header_index++) {
                            datafields[header_index] = [];
                            datafields[header_index].name = header[header_index];
                            datafields[header_index].type = "string";
    
                            columns[header_index] = [];
                            columns[header_index].text = header[header_index];
                            columns[header_index].datafield = header[header_index];
                            columns[header_index].width = 100;
                        }
    
                        var gridAdapter = new $.jqx.dataAdapter({
                            datafields: datafields,
                            localdata: rows
                        });
    
                        $("#jqxgrid").jqxGrid('hideloadelement');
                        $("#jqxgrid").jqxGrid('beginupdate', true);
                        $("#jqxgrid").jqxGrid({
                            source: gridAdapter,
                            columns: columns
                        });
                        $("#jqxgrid").jqxGrid('endupdate');
                    }
                }
            );
            $("#jqxgrid").jqxGrid(
                {
                    width: 850,
                    columnsresize: true
                });
            $("#jqxgrid").jqxGrid('showloadelement');
        });
        //]]>
    </script>

    And here’s the HTML:

    <div id="jqxgrid">
    
    </div>
    problem with dynamic columns #64504

    jbrahy
    Participant

    It looks like it’s this section of jqx-all.js that is having problems. aq = ak.map(an)

    ak is an array with name and type defined as name: “Server_Name”, type: “string” and has map and part of the prototype of an array.
    an is an object with these properties.

    Server_Name: “Server 1”
    Server_Size: “911481”

    if (ak.map) {
        if (i.isFunction(ak.map)) {
            aq = ak.map(an)
        } else {
            var ai = ak.map.split(ag.mapChar);
            if (ai.length > 0) {
                var am = an;
                for (var aj = 0; aj < ai.length; aj++) {
                    if (!am) {
                        continue
                    }
                    am = am[ai[aj]]
                }
                aq = am
            } else {
                aq = an[ak.map]
            }
        }
        if (aq != undefined && aq != null) {
            aq = aq.toString()
        } else {
            if (aq == undefined && aq != null) {
                aq = ""
            }
        }
    }
    problem with dynamic columns #64505

    jbrahy
    Participant

    ok, I figured it out. I was using arrays where I needed objects.

    datafields[header_index] = [];
    columns[header_index] = [];

    had to be

    datafields[header_index] = {};
    columns[header_index] = {};
Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.