jQWidgets Forums

jQuery UI Widgets Forums Plugins Data Adapter data adapter records data

Tagged: 

This topic contains 5 replies, has 2 voices, and was last updated by  PiDome 11 years, 2 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
  • data adapter records data #50929

    PiDome
    Participant

    Hi all,

    I have the next code:

    
                                                    var deviceCommandGroupActionList = {
                                                        datatype: "json",
                                                        datafields: [
                                                            {name: 'id', type: 'string', map: 'typedetails>id'},
                                                            {name: 'label', type: 'string', map: 'typedetails>label'},
                                                            {name: 'prefix', type: 'string', map: 'typedetails>prefix'},
                                                            {name: 'suffix', type: 'string', map: 'typedetails>suffix'},
                                                            {name: 'commandtype', type: 'string', map: 'commandtype'},
                                                            {name: 'commandset', map: 'commandset'}
                                                        ],
                                                        url: '/jsonrpc.json?rpc={"jsonrpc": "2.0", "method": "DeviceService.getDeviceActionGroupCommands", "params":{"id":' + $("#itemMatchDevice").val() + ', "groupid":"' + item.value + '", "filter":["' + optionsSet.devicefilter + '"]},"id":"DeviceService.getDeviceActionGroupCommands"}',
                                                        root: "result>data"
                                                    };
                                                    var dataDeviceCommandGroupActionList = new $.jqx.dataAdapter(deviceCommandGroupActionList);
    

    The record commandset is an array which i need to use in a callback function to fill a jqxdropdownlist with. What i’m facing is that even when there is no datatype supplied it seems like the array is not left as is.

    When i do a alert(JSON.stringify(dataDeviceCommandGroupActionList )); i can see that the records parameter has the “commandset” field, but it is filled with [Object, Object] instead of the expected array.

    But, i also see the original array in the popup. But i just can’t quite see which property it is where the original commandset array is put.

    Can you guys help me out with the parameter to get the untouched array or is there a possibility to give a ‘json’ data type to a record parameter?

    P.S. This is pastebin example result which is retrieved by the data adapter: http://pastebin.com/7WK8rNJN

    Best regards,
    John.

    data adapter records data #50930

    PiDome
    Participant

    Sorry, this is the correct pastebin: http://pastebin.com/3veSBKMc

    data adapter records data #50966

    Peter Stoev
    Keymaster

    Hi John,

    Here’s an example which shows how to load your data:

    <!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.10.2.min.js"></script>
        <script type="text/javascript" src="http://www.jqwidgets.com/jquery-widgets-demo/jqwidgets/jqx-all.js"></script>
        <script type="text/javascript">
            $(document).ready(function () {
                var data = { "jsonrpc": "2.0", "id": "DeviceService.getDeviceActionGroupCommands", "result": { "message": "", "data": [{ "typedetails": { "id": "runscripts", "label": "Choose script", "datatype": "hex", "shortcut": "false", "pos": "0" }, "commandtype": "select", "currentvalue": null, "commandset": [{ "name": "Select a script", "value": "" }, { "name": "Startup script", "value": "0x70 0x00 0x00 0x00" }, { "name": "RGB loop", "value": "0x70 0x01 0x00 0x00" }, { "name": "Pulse white", "value": "0x70 0x02 0x00 0x00" }, { "name": "Pulse red", "value": "0x70 0x03 0x00 0x00" }, { "name": "Pulse green", "value": "0x70 0x04 0x00 0x00" }, { "name": "Pulse blue", "value": "0x70 0x05 0x00 0x00" }, { "name": "Pulse cyan", "value": "0x70 0x06 0x00 0x00" }, { "name": "Pulse magenta", "value": "0x70 0x07 0x00 0x00" }, { "name": "Pulse yellow", "value": "0x70 0x08 0x00 0x00" }, { "name": "Hue cycle", "value": "0x70 0x0a 0x00 0x00" }, { "name": "Mood light", "value": "0x70 0x0b 0x00 0x00" }, { "name": "Virtual candle", "value": "0x70 0x0c 0x00 0x00" }, { "name": "Water reflections", "value": "0x70 0x0d 0x00 0x00" }, { "name": "Broken old neon", "value": "0x70 0x0e 0x00 0x00" }, { "name": "The 4 seasons", "value": "0x70 0x0f 0x00 0x00" }, { "name": "Thunderstorm", "value": "0x70 0x10 0x00 0x00" }, { "name": "Traffic light", "value": "0x70 0x11 0x00 0x00" }, { "name": "S.O.S. morse", "value": "0x70 0x12 0x00 0x00" }] }, { "typedetails": { "id": "blackout", "value": "0x70 0x09 0x00 0x00", "label": "Blackout", "datatype": "hex", "shortcut": "false" }, "commandtype": "button", "currentvalue": null, "commandset": {} }, { "typedetails": { "id": "scriptstop", "value": "0x6f", "label": "Stop current running script", "datatype": "hex", "shortcut": "false" }, "commandtype": "button", "currentvalue": null, "commandset": {} }], "success": true } };
    
                var deviceCommandGroupActionList = {
                    datatype: "json",
                    datafields: [
                        { name: 'id', type: 'string', map: 'typedetails>id' },
                        { name: 'label', type: 'string', map: 'typedetails>label' },
                        { name: 'prefix', type: 'string', map: 'typedetails>prefix' },
                        { name: 'suffix', type: 'string', map: 'typedetails>suffix' },
                        { name: 'commandtype', type: 'string', map: 'commandtype' },
                        { name: 'commandset', type: 'array' }
                    ],
                    localdata: data,
                    root: "result>data"
                };
                var dataAdapter = new $.jqx.dataAdapter(deviceCommandGroupActionList);
                // perform data binding.
                dataAdapter.dataBind();
            });
        </script>
    </head>
    <body class='default'>
        <div id="table">
            Loading...
        </div>
     </body>
    </html>
    

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    data adapter records data #50982

    PiDome
    Participant

    Hi Peter,

    This works perfectly when commandset is an array, but that is not always the case, sometimes it is an object like below:

    
    {
    -typedetails: {
    id: "cPAUA4LGMu"
    label: "Switch device"
    datatype: "hex"
    shortcut: "true"
    pos: "0"
    }
    commandtype: "toggle"
    currentvalue: null
    -commandset: {
    -off: {
    value: "0x00"
    }
    -on: {
    value: "0x54"
    }
    }
    }
    

    Maybe the follow up code which makes use of for example this data adapter may clear’s it up a little bit what i’m trying to achieve

    
                                                    $("#itemMatchDevicegroupaction").jqxDropDownList({source: DataDeviceCommandGroupActionList, valueMember: "id", displayMember: "label", width: '200', theme: siteSettings.getTheme()});
                                                    $("#itemMatchDevicegroupaction").on('select', function(event) {
                                                        if (event.args) {
                                                            var item = event.args.item;
                                                            if (item) {
                                                                var deviceItem = $("#itemMatchDevice").jqxComboBox('getItem', $("#itemMatchDevice").jqxComboBox('getSelectedIndex'));
                                                                var groupItem = $("#itemMatchDevicegroup").jqxDropDownList('getItem', $("#itemMatchDevicegroup").jqxDropDownList('getSelectedIndex'));
                                                                var actionItem = $("#itemMatchDevicegroupaction").jqxDropDownList('getItem', $("#itemMatchDevicegroupaction").jqxDropDownList('getSelectedIndex'));
                                                                try {
                                                                    var prefix = DataDeviceCommandGroupActionList.records[$("#itemMatchDevicegroupaction").jqxDropDownList('getSelectedIndex')].prefix;
                                                                    var suffix = DataDeviceCommandGroupActionList.records[$("#itemMatchDevicegroupaction").jqxDropDownList('getSelectedIndex')].suffix;
                                                                } catch (err) {}
                                                                callBackData = {
                                                                    "itemType" : "device",
                                                                    "deviceId" : deviceItem.value,
                                                                    "deviceGroupId" : groupItem.value,
                                                                    "deviceCommandId" : actionItem.value,
                                                                    "deviceName" : deviceItem.label,
                                                                    "deviceGroupName" : groupItem.label,
                                                                    "deviceCommandName" : actionItem.label,
                                                                    "deviceCommandPrefix": prefix===undefined?"":prefix,
                                                                    "deviceCommandSuffix" : suffix===undefined?"":suffix,
                                                                    "deviceCommandType" : DataDeviceCommandGroupActionList.records[$("#itemMatchDevicegroupaction").jqxDropDownList('getSelectedIndex')].commandtype,
                                                                    "deviceCommandSet" : DataDeviceCommandGroupActionList.records[$("#itemMatchDevicegroupaction").jqxDropDownList('getSelectedIndex')].commandset
                                                                };
                                                            }
                                                        }
                                                    });
    

    When a button is pressed to confirm the selections a previous set callback function will be executed and is passed the callBackData parameter.

    I understand the data adapter is meant to supply record data for for example the widgets, but is there a possibility to have a an option which says “type : ‘object'” when the datatype is json or can i do a feature request for it?

    Best regards,
    John.

    data adapter records data #50983

    Peter Stoev
    Keymaster

    Hi John,

    No, there’s no option the type to be object.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    data adapter records data #50987

    PiDome
    Participant

    Hi Peter,

    No problem, just created a workaround, thank you for the response.

    John.

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

You must be logged in to reply to this topic.