facebook

CSV READ in MobiOne

  1. MobiOne Archive
  2.  > 
  3. Getting Help – General
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #336421 Reply

    vacrob0
    Member

    Hi all.

    I’ve a csv file. I would like to read it inside a kind of table with jscript. I want data included in the application without reading from internet!..

    Thanks a lot!

    #336479 Reply

    Brandon
    Member

    How is your data formatted? comma separated, line break separated?

    This will determine the code you need to read it.

    If you code is in standard csv format this should work:

    $(document).ready(function() {
        $.ajax({
            type: "GET",
            url: "data.csv",
            dataType: "text",
            success: function(data) {processData(data);}
         });
    });
    
    function processData(allText) {
        var allTextLines = allText.split(/\r\n|\n/);
        var headers = allTextLines[0].split(',');
        var lines = [];
    
        for (var i=0; i<allTextLines.length; i++) {
            var data = allTextLines[i].split(',');
            if (data.length == headers.length) {
    
                var tarr = [];
                for (var j=0; j<headers.length; j++) {
                    tarr.push(headers[j]+":"+data[j]);
                }
                lines.push(tarr);
            }
        }
        // alert(lines);
    }
Viewing 2 posts - 1 through 2 (of 2 total)
Reply To: CSV READ in MobiOne

You must be logged in to post in the forum log in