jQWidgets Forums

jQuery UI Widgets Forums TreeGrid comma in .csv file

This topic contains 4 replies, has 2 voices, and was last updated by  prunk 10 years, 1 month ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
  • comma in .csv file #68625

    prunk
    Participant

    Good Day, I know this has been addressed in earlier posts, but I cannot seem to find the fix. I have a .csv file containing text with commas (short paragraph with words with some commas inserted for grammer purposes). I cannot find a way to escape these commas. I tried the double quote as suggested, but that does not seem to work. Inserting the double quote around the comma just makes the rest of the line after the first quote disappear. I tried backslashes and had no luck either. Any help would be appreciated. Thanks.

    comma in .csv file #68630

    Peter Stoev
    Keymaster

    Hi prunk,

    Add double quotes around each entry. Ex: “1”,”18″,”Guy”,”Gilbert”,”Production Technician”

    Best Regards,
    Peter Stoev

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

    comma in .csv file #68636

    prunk
    Participant

    Thank you for your response. I am not getting it to work. So I created two lines of text below that represents what I have in a .csv. file. Perhaps you could format it for me using the double quotes so I can see what I am doing wrong. Thanks.

    1. The footbal player, after running 5 yards, threw a touchdown.,
    2. The basketball player, who is 7 ft, can dunk a basketball.

    comma in .csv file #68674

    Peter Stoev
    Keymaster

    Hi prunk,

    Example:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <script type="text/javascript" src="../../scripts/jquery-1.11.1.min.js"></script>
        <link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" />
        <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" src="../../jqwidgets/jqxdatatable.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxtreegrid.js"></script>
        <script type="text/javascript" src="../sampledata/generatedata.js"></script>
        <script type="text/javascript">
            $(document).ready(function () {
                var source =
                {
                    localdata: '"1. The footbal player", "after running 5 yards", "threw a touchdown.,"\n' + '"2. The basketball player", "who is 7 ft", "can dunk a basketball"',
                    datatype: "csv",
                    datafields:
                    [
                        { name: 'value1', type: 'string' },
                        { name: 'value2', type: 'string' },
                        { name: 'value3', type: 'string' },
                    ]
                };
    
                var dataAdapter = new $.jqx.dataAdapter(source, {
                    beforeLoadComplete: function (data) {
                        var records = new Array();
                        for (var i = 0; i < data.length; i++) {
                            var record = {};
                            record.value1 = data[i].value1.replace(/"/g, "");
                            record.value2 = data[i].value2.replace(/"/g, "");
                            record.value3 = data[i].value3.replace(/"/g, "");
                            records.push(record);
                        }
                        return records;
                    }
                }
                );
    
                $("#tree").jqxTreeGrid(
                {
                    source: dataAdapter,                
                    altRows: true,
                    columns: [
                      { text: 'value1', dataField: 'value1', width: 200 },
                      { text: 'value2', dataField: 'value2', width: 200 },
                      { text: 'value3', editable: false, dataField: 'value3', width: 180 }
                    ]
                });
            });
        </script>
    </head>
    <body class='default'>
        <div id="tree">
        </div>
    </body>
    </html>
    

    Best Regards,
    Peter Stoev

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

    comma in .csv file #68730

    prunk
    Participant

    Thank you for your assistance and the code.

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

You must be logged in to reply to this topic.