jQuery UI Widgets Forums Plugins Data Adapter DataAdapter doesn't parse empty string ("") of array of arrays

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

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

  • Nicolas
    Participant

    Hello again!

    I have a weird problem : my DataAdapter have to parse an Array of Array. But in such a situation, if it finds a empty string, it will not parse it.

    example, let say my source is this : [[“john”, “canada”, 34], [“alexander”, “”, 23]]

    Then, the DataAdapter records will be
    {
    { firstname : “john”, country : “canada”, age : 34 },
    { firstname : “john”, age : 34 }
    }

    You see, the “country” property of the second item isn’t present in the dataadapter’s record if the string of the source is empty.

    This is a problem when sorting a column; with a undefined value, the sort then act strangely. Don’t know what have to be fix, the DataAdapter or the sorting?

    Here is a jsFiddle to show better the problem. Look in the console for values of records and source. And see the result in the sorted column.

    http://jsfiddle.net/7wRN4/1/

    Regards


    Peter Stoev
    Keymaster

    Hi Nicolas,

    According to me, the dataAdapter loads the records correctly.

    Example:

    <!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="../../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/jqxmenu.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxgrid.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxgrid.selection.js"></script> 
        <script type="text/javascript" src="../../jqwidgets/jqxdatatable.js"></script> 
        <script type="text/javascript" src="../../jqwidgets/jqxgrid.columnsresize.js"></script> 
        <script type="text/javascript"> 
        $(document).ready(function(){
            var data = '[["john", "canada", 34], ["alexander", "", 23]]';
    
            var source =
            {
                localdata: data,
                datatype: "json",
                datafields:
                [
                    { name: 'name', map: '0', type: 'string' },
                    { name: 'country', map: '1', type: 'string' },
                    { name: 'age', map: '2', type: 'number' }
                ]
            };
            var dataAdapter = new $.jqx.dataAdapter(source)
            //initialize jqxGrid
            $("#grid").jqxGrid(
            {
                source: dataAdapter,
                width: 450,
                columns:
                [
                    { text: 'name', datafield: 'name', width: 150 },
                    { text: 'country', columntype: 'textbox', datafield: 'country', width: 150 },
                    { text: 'age', columntype: 'textbox', datafield: 'age', width: 150 }
                ]        
            });
        });
    </script>
    </head>
    <body>
    <div id='jqxWidget'>
        <div id="grid"></div>
    </div>
    </body>
    </html>

    The result is 2 rows with data in the both rows. The “country” field of the second row is empty and would be displayed as empty, but there is dataAdapter.records[1].country member. It is just empty as it is defined in the data source.

    Best Regards,
    Peter Stoev

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


    Nicolas
    Participant

    Hi Peter! Sorry for that late answer.

    I just upgraded jqWidgets from version 3.1.0 to 3.2.1 and it seems to solve the problem. The sort on a column that contains empty values seems more consistent now. The jsfiddle I posted confirm it.

    Thank you for your great work!
    Regards!

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

You must be logged in to reply to this topic.