Child Row - Data object "d"?

Child Row - Data object "d"?

FD1234FD1234 Posts: 4Questions: 1Answers: 0

Hey,

This is a complete noob question, but.... I'm trying to install child rows on a table. I'm following the example here (https://datatables.net/examples/api/row_details.html), but I can't work out what to replace "d" with in the first ,js function.

Code here: https://jsfiddle.net/dpgwqxL9/#&togetherjs=LacK5nTenu

My apologizes for the stupid question!

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,301Questions: 26Answers: 4,946

    d is the data object for the row. You have first_name, surname, level, email defined as columns. Are you returning other data from your query that you want to display in the child row?

    In line 6 you need to add the d back to look like this:

    function format ( d ) {

    Lets say you are retuning shoe_size and harness_size in addition to the above 4 columns. You can display those in the child row with the following:

    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>'+
                '<td>Show size:</td>'+
                '<td>'+d.show_size+'</td>'+
            '</tr>'+
            '<tr>'+
                '<td>Harness size:</td>'+
                '<td>'+d.harness_size+'</td>'+
            '</tr>'+
        '</table>
    

    If you need further help please post an example of the data you are returning and what you want in the child row.

    Kevin

  • FD1234FD1234 Posts: 4Questions: 1Answers: 0

    Hi Kevin,

    Thanks for the quick reply,

    I have 6 objects (First_name , Surname, Level, student_id_number, email & assessor ). I want all 6 displayed in the child row, but only the first three to be displayed in the main table.

    I have updated the JS file (and the fiddle one) with your suggestion, by adding the 'd ' and all 6 objects to the format function. However the child row is still not displaying...

    In addition to that, I have added a blank column in the HTML page, plus the remaining JS as suggested by the example file.

    Advice going forward would be very helpful..

  • kthorngrenkthorngren Posts: 21,301Questions: 26Answers: 4,946

    I'm not seeing any data in the table. However I think I see an issue in line 108. You have #climbing. I think selectors are case sensitive. Try changing the line to this:

    $('#Climbing tbody').on('click', 'td.details-control', function () {

    Kevin

  • FD1234FD1234 Posts: 4Questions: 1Answers: 0

    Hey,

    Sorry, the ajax is pulling an internal database to the server. (http://nuigmc.com/climbing_database/index.html)

    I fixed the case edit, well spotted! But still no joy

  • kthorngrenkthorngren Posts: 21,301Questions: 26Answers: 4,946
    Answer ✓

    You have a syntax error:
    table.Climbing.js:100 Uncaught SyntaxError: Unexpected token {

                {
                    "data": "level"
                },  //add comma here
    
                {   "data": "Email" ,"visible": false }
    

    You need to add a comma.

    Kevin

  • FD1234FD1234 Posts: 4Questions: 1Answers: 0

    Hey Kevin,

    Thanks for help but I decided to leave the child row feature for the time being. I don't have enough experience with the system to get it working right.

    Thanks again for your help

  • KennethWintherKennethWinther Posts: 5Questions: 2Answers: 0

    I have the same issue and I don't know if anyone understood the question.
    What do i replace d with to get my chilrow data from my second table.
    Example:
    Main DataTable is Department and then in child rows i want all Employees.
    I'm getting my Department table as it's my main table, but all Employees data is undefined.
    '<td>Show size:</td>'+
    '<td>'+d.show_size+'</td>'+
    Is not getting filled with the expected data. I would except to do something like Model.Employee.Name instead og at least have the d replaced with a relevant data source somehow?
    Anyone still on this? And understand the problem?

  • kthorngrenkthorngren Posts: 21,301Questions: 26Answers: 4,946

    It would help to understand your data structure. Is the data from the second table returned with the query response of the first table?

    Maybe you can post examples of your data structure.

    If the first line of the format function you can use console.log(d); to see what d is then maybe you can workout how to display the desired data.

    Kevin

This discussion has been closed.