Complex headers plus sign not in separate column (SOLVED)

Complex headers plus sign not in separate column (SOLVED)

legendslegends Posts: 16Questions: 5Answers: 0
edited February 2017 in Free community support

I am implementing the complex headers table using responsive plugin, but I get the following outcome:

The plus sign is in the name column, which is not desired, it should be in a new column before the name column.

Html is like in the example, but my js code is the following:

$('#tblComplexHeaders').DataTable({
    "sDom": "<'dt-toolbar'<'col-xs-12 col-sm-6'f><'col-sm-6 col-xs-12 hidden-xs'l>r>" +
    "t" +
    "<'dt-toolbar-footer'<'col-sm-6 col-xs-12 hidden-xs'i><'col-xs-12 col-sm-6'p>>",
    "oLanguage": {
        "sSearch": '<span class="input-group-addon"><i class="glyphicon glyphicon-search"></i></span>',
        sLengthMenu: "_MENU_"  
    },
    responsive: {
        details: {
            type: 'column'
        }
    },
    columnDefs: [{
        className: 'control',
        orderable: false,
        targets: 0
    }],
    order: [1, 'asc']
});




The table looks good, only the plus sign is a problem.
I use the following plugins:

require(
[
    "jquery",
    "datatables.net",
    "datatables.net-bs",
    "datatables.net-responsive",
    "datatables.responsive.bootstrap",
    "datatables.responsive.helper",
    "datatables.net-buttons",
    "datatables-buttons.html5",
    "datatables.net-buttons-print",
    "datatables.net-buttons-colVis",
    "jszip", "pdfmake", "vfsfonts"
], function ($) {...

The function sets up different types of datatables, that's why I need the different plugins.
Any hint how to get the plus sign in a separate column before the "names" column?

The generated markup:

This question has an accepted answers - jump to answer

Answers

  • legendslegends Posts: 16Questions: 5Answers: 0

    Here is reproduction of the problem: jsbin.com/dezuga/edit?html,js,output

  • legendslegends Posts: 16Questions: 5Answers: 0
    edited February 2017

    SOLVED
    If you take a look at this example https://datatables.net/extensions/responsive/examples/child-rows/column-control.html

    you can see that the details type is set to column. The example also shows, that the plus sign has it's own column. But when I set it to column, the plus sign is part of the first data column.
    When I change the details type to inline, I get what I want, a separate column with a plus sign.

    Is this a bug in your demo or a bug in the naming?
    Because when I hear "inline" , I would not think of a separate column...

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395
  • legendslegends Posts: 16Questions: 5Answers: 0
    edited February 2017

    It's clear, but in my case it works the opposite way:

    inline - where the first column in the table has additional padding added to it and the :before pseudo element is used to display the button.

    and column:

    column - where a whole column is dedicated to the show / hide control.

    In my case inline creates a new column for the button. And "column" does what "inline" should do!!!

    Here is a repro: jsbin.com/dezuga/edit?html,js,output

    As you can see,... column does it inline...

    Thanks, for reading ;-)

  • allanallan Posts: 63,160Questions: 1Answers: 10,406 Site admin
    Answer ✓

    If you want to use the column type, you need to give a column that is can use - i.e. insert an empty column: http://jsbin.com/yanugatopa/edit?html,js,output .

    In the example you give it is still using the first column, but the first column has data in it, hence why it looks nasty!

    Allan

  • legendslegends Posts: 16Questions: 5Answers: 0
    edited February 2017

    I just took a look at my repro and yes you are right inline stays inline.
    Adding a new column does the "trick".
    Should stop working after 12h, thanks allan!

    One issue I have regarding your jsBin example, when the page width goes below for example 400px (tested on latest chrome,desktop) the contact header stays visible, while the data for this header is not displayed anymore, any suggestions what I can do?

  • allanallan Posts: 63,160Questions: 1Answers: 10,406 Site admin

    Unfortunately, Responsive doesn't currently play nicely with complex headers. I'm afraid that's a limitation in the current release software and one I plan to address in future.

    Allan

  • legendslegends Posts: 16Questions: 5Answers: 0
    edited February 2017

    I created a hot-fix for this.
    While this works on my page where I have different types of datatables, it is not tested, means no unit tests exist. Cannot assure that it has no side effects.

    It's not perfect, but it looks good on my S3 and LG v10.
    This patch will keep the headers on screens which are more narrow then the S3 screen:
    jsbin.com/dezuga/8/edit?html,js,output

    _setColumnVis: function (col, showHide) {
        var dt = this.s.dt;
        var display = showHide ? '' : 'none'; // empty string will remove the attr
    
        $(dt.column(col).header()).css('display', display);
        $(dt.column(col).footer()).css('display', display);
        dt.column(col).nodes().to$().css('display', display);
    
        var parentrow = $(dt.column(col).header()).parent().prev("tr");
    
        var visibleSiblingCount = $(dt.column(col).header()).siblings("th").filter(function (idx, el) {
            return $(el).is(":visible");
        }).length;
    
        if (parentrow.length > 0 && visibleSiblingCount != 1) {
    
            if (parentrow.find("th:nth-child(" + col + ")").attr("rowspan") == 1) {
                parentrow.find("th:nth-child(" + col + ")").css('display', display);
            } else {
                parentrow.find("th:nth-child(" + (col + 1) + ")").css('display', display);
            }
    
        }
    },
    
  • allanallan Posts: 63,160Questions: 1Answers: 10,406 Site admin

    Nice one thanks!

    My current plan is to improve the complex header support in DataTables core so it can be used by the extensions such as Buttons and Responsive via an API (which is yet to be defined).

    That looks like a nice workaround for now :smile:.

    Allan

This discussion has been closed.