Column Data being displayed with only first character of data.

Column Data being displayed with only first character of data.

ashishreddyvashishreddyv Posts: 2Questions: 1Answers: 0

I have a datatable which is being populated on a button click. I am adding rows to the table on ajax success call using table.rows.add(data), where 'data' is the data returned from the server. Sample data returned from the server is of type List<String>, when printed on the console looks like ["Nothing", "Something"]. My datatable is intended to have two columns, Description | Select.

Here 'Description' is the data that has been returned from the server using ajax call and Select is a button link which calls an action when clicked.

The code for my datatable is as below :

$("#datatable").DataTable({
            "deferRender": true,
            "iDisplayLength": 25,
            "columnDefs":[
                          {
                                "targets": -1,
                           "data":null,
                        "defaultContent": "<span class='glyphicon glyphicon-info-sign'></span>",
                        "orderable" : false,
                            "searchable": false,
                            "width": "20%"
                            }
                          ],
             "order": [[0, 'asc']]
        });

The problem here is that the data in the first column displays only the first character as shown in the attached screenshot. Am I missing some configuration for the datatable which is the cause of this problem ?

Answers

  • ashishreddyvashishreddyv Posts: 2Questions: 1Answers: 0
    edited August 2016

    Found a workaround for this problem by iterating through the json object and adding values for each cell in the row like below :

    $.each(data, function(index, value) {
         table.row.add([value,'']).draw();
    });

    Note that I had two display columns in the Datatable, hence I have added value for first cell and '' (no value) for the select column.

  • jLinuxjLinux Posts: 981Questions: 73Answers: 75

    Hm.. typically, thats a sign that a string is being treated as an array..

    EG:

    var str = 'foo'
    alert( str[0] ) // alerts 'f'
    

    If you could replicate this on http://live.datatables.net/ for me to see, then we could find the "real" solution for this.

This discussion has been closed.