Export child rows using pdfHtml5

Export child rows using pdfHtml5

jimbrewjimbrew Posts: 5Questions: 1Answers: 0

Hello I have a table that shows a list of log events an dusers can add comment, a one to many relationship. Following from this example I can show the child elements by clicking on the details button. It isn't added in yet just the blank cell to the left of actions as the image below.

However, when exporting to pdf I would like to include this data. Is this possible?

Answers

  • colincolin Posts: 8,661Questions: 0Answers: 1,449

    This thread should help, it's asking the same thing.

    Cheers,

    Colin

  • jimbrewjimbrew Posts: 5Questions: 1Answers: 0

    I have seen that thread. However reading it I thought it was aimed at a single table when some of the columns don't fit on the screen.

    Mine uses an onclick event and from here shows the many table of a one-to-many relationship with MVC.

    var table = _logEventRepository.GetAll().Include(c => c.Comments);

    My table uses ajax function to get the data from an API, but on the main table I couldn't find out to display each of the comments.

    Therefore a onclick event was created and from here it generates the comments.

    _$logEventsTable.on('click', 'td.comments-control', function () {
        var tr = $(this).closest('tr');
        var row = dataTable.row(tr);
    
        if (row.child.isShown()) {
            // This row is already open - close it
            row.child.hide();
            tr.removeClass('shown');
        }
        else {
            // Open this row
            row.child(format(row.data())).show();
            tr.addClass('shown');
        }
    });
    
    function format(row) {
        var _comments = row.logEvent.comments;
        if (_comments.length > 0) {
            var items = '<div class="list-group">';
            for (var i = 0, l = _comments.length; i < l; i++) {
                items += '<div class="list-group-item">' +
                    '<p class="list-group-item-heading">' + _comments[i].comment + '</p>' +
                    '<p class="list-group-item-text">Creted by: ' + _comments[i].creatorUserFullName +
                    ', ' + moment(_comments[i].creationTime).format('L LT') + '</p></div>';
            }
            items += '</div>';
            return items;
        }
        else {
            return false;
        }
    }
    

    If I could create the comments in the main table as a sub entry that might solve my problems

  • colincolin Posts: 8,661Questions: 0Answers: 1,449

    My link in that thread was saying child rows aren't supported in the Excel, then the discussion went on to say that Responsive could be used as a workaround. So, long story short, that's not supported.

    Colin

  • jimbrewjimbrew Posts: 5Questions: 1Answers: 0

    @colin thanks for this. I am already using responsive but the suggestion is not workable for my solution, since my data is dynamically sized, i.e one event could have 3 comments another, might have none.

    I will need to rethink the pdf export.

  • kthorngrenkthorngren Posts: 8,931Questions: 25Answers: 2,040
    edited April 7

    I'm confused. Are you using both the Responsive extension and Child Detail Rows like this example which does not use Responsive?

    If you want to export Child Detail Rows (not Responsive) then you will need to use the pdfHtml5 Customize Function to insert the child rows. I haven't done this with PDF export but I did create an example in this thread for Excel. Don't look at the details fo the example because the PDF export format is different but the high level flow may help. I haven't worked much with PDF export but I helped, in another recent thread, to insert RowGroups endRender rows. The same idea applies, see this example from the thread.

    If you would like help with this then please put together a test case that has an example of your data with Child rows and PDF export working. And any code you may have tried for the child rows.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • kthorngrenkthorngren Posts: 8,931Questions: 25Answers: 2,040

    I created a simple PDF export with Child Rows example:
    http://live.datatables.net/hepopote/1/edit

    Hopefully it will get you started. Again if you need help please provide a test case for us to work from.

    Kevin

  • jimbrewjimbrew Posts: 5Questions: 1Answers: 0

    Cheers @kthorngren I will have a look at this. Your js example you provided looks like it would do the trick. I will try and implement in my own solution.

Sign In or Register to comment.