Column Render not rendering properly.

Column Render not rendering properly.

AkashvinoAkashvino Posts: 7Questions: 5Answers: 0
edited February 15 in Free community support

Hi All,

Request your help, when I manually execute the php program the output is as below(PHP Output), the "Output" column is an array , so in my ajax i have the below lines(AJAX Query), it is rendering the first array (0) properly , but the second array(1) the value is display as single line "FAILED FAILED FAILED" rather than multiple lines as

FAILED
FAILED
FAILED

PHP Output

    [0] => Array
        (
            [Server] => T1
            [Task] => T01
            [Output] => Array
                (
                    [0] => FAILED
                )

        )

    [1] => Array
        (
            [Server] => T2
            [Task] => T01
            [Output] => Array
                (
                    [0] => FAILED 
                    [1] => FAILED
                    [2] => FAILED
                )

        )

AJAX Query

            columns: [
                        { data: "Server" },
                        { data: "Task", className: "dt-body-left h8" },
                        { data: "Output",
                          render: function (data, type, row) {
                                           var odata = '';
                                           for (i=0; i<data.length; i++) {
                                                odata += '<p class="dt-body-left h8 text-danger" colspan="2">' + data[i] + '</p>'
                                           }
                                           return odata;
                                  }
                        }
            ]

Answers

  • kthorngrenkthorngren Posts: 8,082Questions: 25Answers: 1,816

    Your code snipper works here:
    http://live.datatables.net/xuzizoso/1/edit

    The first thing to do is verify that Output is an array. An easy way is to use console.log(data); in the render function, between lines 5 and 6. Or use a console.log(data[i]); inside the for loop.

    We will need to see an example of it not working to provide suggestions. Please post a link to your page or update my test case with your specific data.

    Kevin

  • AkashvinoAkashvino Posts: 7Questions: 5Answers: 0

    Hi Kevin,
    Thank you, Some findings, in my database table the value of field output for the Server 1 data is stored as a single line "FAILED FAILED FAILED" using php "(array_filter(explode(PHP_EOL, $i["output"]));" i have converted this line into an array, and the returned json data has the same structure as stated above, but still in ajax is seem to be the output as a single line.

  • kthorngrenkthorngren Posts: 8,082Questions: 25Answers: 1,816

    I would start by using the browser's developer tools to get the JSON response from the Network tab. Steps can be found in this technote. Take that data and update the example I provided. This will allow us to see exactly the data you have and can offer suggestions.

    Or you can use a console.log statement in the render function or debugger to find out what is the type and structure of the data variable.

    Kevin

Sign In or Register to comment.