datatable d.date and d.images undefined even though they exist

datatable d.date and d.images undefined even though they exist

TheNerdy97TheNerdy97 Posts: 25Questions: 6Answers: 1

**

      function format ( d ) {
    // `d` is the original data object for the row
    return '<table cellpadding="5" cellspacing="0" border="0" style="padding-left:50px;">' +
        '<tr>' +
        '<b>' +
        d.code +'<br></br>' +'Last Updated ('+ d.date + ')' +
        '</b><br><br>' +
        '<td>' +
        d.images +
        '</td>' +
        '</tr>' +
        '<tr>' +
        '</tr>' +
        '</table>'
}
$(document).ready(function() {

    var table = $('#Fresh').DataTable( {
        processing: true,
        serverSide: true,
        ajax:{

            url:'api/fresh/?format=datatables',


        },

        columns: [
            { data: "code" },
            { data: "orbs",
            render: function ( data, type, row ) {
                return '<img src="  static/images/items/orb.png " width="22" height="22" styleL="padding-bottom:3px;" /> '+ data;
    } },
            { data: "price",
            render: function ( data, type, row ) {
            return '$'+ data;
    } },

        ],

        initComplete: function( settings, json ) {
          this.api().rows().every( function () {
            this.child( format(this.data()) ).show();
          });
        }

    } );

} );
</script>

**:

**Everything is working perfectly but what was working before server-side processing which is the "d.date" and "d.images" aren't working now and I have to define them in the column data for them to work, but I don't want to make them into a col **:

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,349Questions: 26Answers: 4,955
    edited June 2022

    First make sure they are retuned in your Ajax response. They can exist in the row data without actually creating the columns. This example shows d.extn. Its in the row data but not defined as a column. You need to do the same.

    Kevin

  • TheNerdy97TheNerdy97 Posts: 25Questions: 6Answers: 1

    The values are returned in my Ajax response, and I followed this example to do it.

    If I replaced any one of: "code", "orbs", or "price" with either "date" or "images" it will display correctly on the table, but it will not work with my current configurations

  • kthorngrenkthorngren Posts: 21,349Questions: 26Answers: 4,955
    edited June 2022

    Please post an example of the JSON response using the browser's network inspector.

    Is the problem with the display in the parent table or child detail rows?

    In your post subject you mention they are undefined. Does that mean you are getting a console error stating d.code or d.images are undefined?

    Best option is to post a link to your page or a test case showing the issue so we can help debug.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • kthorngrenkthorngren Posts: 21,349Questions: 26Answers: 4,955

    Or are you saying the image doesn't render in the child row. If not you may need to wrap it in an img tag like you have for the orbs column.

    Kevin

  • TheNerdy97TheNerdy97 Posts: 25Questions: 6Answers: 1
    Answer ✓

    I made both 'date' and 'images' always serialized and it fixed the error.

Sign In or Register to comment.