data is truncated at the comma

data is truncated at the comma

hank scorpiohank scorpio Posts: 7Questions: 1Answers: 0

Hi--

Whenever my cell's data contains a comma, the text after it is truncated. Is there way around this?

I'm getting my data from an Ajax post, and creating the table like this:

var rt=$("#resultsTable").DataTable({
    data:s
});

What I see, for example, is this:

Some Company

Instead of this:

Some Company, Inc.

Any help is appreciated. Thank you!

This question has an accepted answers - jump to answer

Answers

  • hank scorpiohank scorpio Posts: 7Questions: 1Answers: 0

    Oh, using version DataTables 1.10.13.

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951

    data:s

    How are you building s?

    Kevin

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Also, could you use the debugger so we can see the configuration.

    Thanks,
    Allan

  • bindridbindrid Posts: 730Questions: 0Answers: 119

    Have you looked at the raw data in s? If you have a string "Company, Inc", DataTables is not going to change that so I would start looking at your data.

    Are your columns wide enough?

  • hank scorpiohank scorpio Posts: 7Questions: 1Answers: 0

    @kthorngren -- s is returned from an Ajax post. I have a PHP script running a query, then returning the data. The process is a bit messy because the names and amount of columns are dynamic. I send a query to my script by AJAX, then get a string back. I use JavaScript to build a table and add it to my DOM. Like this:

    var x=data.split("~||");
    var s=[];
    var d=x[0].split("~");
    
    for (i=0;i<d.length;i++) {
        xx=d[i].split(",");
        s[i]=[];
        for (j=0;j<xx.length;j++) {
            s[i].push(xx[j]);                       
        }
    }
    
    var f=x[1].split(",");
    var t="<table id=\"resultsTable\" class=\"display\" width=\"100%\">\n";
    t+="<thead>\n";
    t+="<tr>";
    
    for (i=0;i<f.length;i++) {
        t+="<th>"+f[i]+"</th>\n";
    }
                        
    t+="</tr>\n";
    t+="</thead>\n";
    t+="</table>\n";
    
    $("#results").html(t);
    
    var rt=$("#resultsTable").DataTable({
        data:s
    });
    

    @bindrid -- Looking at the data logged in my console, it looks fine there. I'm getting data back in this format:

    column data,column data,column data~column data,column data,column data~column data,column data,column data~||column name,column name,column name

    I really need to build the table dynamically because my client wants to choose which columns will display. It's messy, but the whole thing works almost perfectly, except this comma problem.

    @allan -- I haven't used the debugger before. That's a good idea. Let me try this and see what happens.

    Thank you!

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951
    Answer ✓

    I'm unclear what your data structure is that is returned from ajax but I think the problem is with the xx=d[i].split(","); in line 6. Looks like this might result in two array elements for the column with "Some Company, Inc.". If this is the case then it seems Datatables will only use the first array element.

    I may be wrong. I would recommend using console.log to see how your loops are building your data.

    Kevin

  • hank scorpiohank scorpio Posts: 7Questions: 1Answers: 0

    Well, crap. I see the problem now. I'm splitting my string on a comma. I need to find a different delimiter.

    Thanks everyone and sorry for wasting your time. ;)

  • hank scorpiohank scorpio Posts: 7Questions: 1Answers: 0

    @kthorngren ... thank you. I spotted that after posting my code and I really appreciate your response.

    Changing that comma to a caret did the trick.

This discussion has been closed.