RowGroup 1.0.0 sets colspan=0 when table is hidden

RowGroup 1.0.0 sets colspan=0 when table is hidden

harakanharakan Posts: 4Questions: 1Answers: 0

RowGroup 1.0.0 has a bug where it sets "colspan=0" if the datatable is hidden during initialisation. This looks like the same issue as a generic case in the main code:

https://github.com/DataTables/DataTablesSrc/commit/9946f7c81e530c0fcf65f0bd38ea5364741bb268

It looks like RowGroup uses this same "filter(':visible')" code, but I can't see exactly how to modify it in the same way as the main code change.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,726Questions: 1Answers: 10,110 Site admin

    Its here. That code should probably be updated to be:

    return this.s.dt.columns( ':visible' ).count();
    

    which I believe should do the trick.

    Rushing a little at the moment I'm afraid so I've not actually tried it out yet.

    Allan

  • harakanharakan Posts: 4Questions: 1Answers: 0

    Thanks for the quick reply! Unfortunately replacing that line with the code you gave seems to behave in exactly the same way (returning colspan=0 if the table is initially hidden). I'm sure I'm running the patched version as I put a breakpoint on the relevant line...

  • allanallan Posts: 61,726Questions: 1Answers: 10,110 Site admin

    This one will do it:

    this.s.dt.columns().visible().reduce( function (a, b) {
        return a + b;
    }, 0 )
    

    That uses the columns().visible() method which only checks the visible flag of the column and not if it is actually in the document or not. It then uses reduce() to basically sum the values.

    Allan

  • harakanharakan Posts: 4Questions: 1Answers: 0
    edited May 2017

    Unfortunately this also doesn't seem to work. Putting a breakpoint on the "return" statement shows "a: 0" and "b: false". The complete code fragment from my modified source:

    _colspan: function ()
    {
    // return $( this.s.dt.columns().header() ).filter(':visible').length;
    this.s.dt.columns().visible().reduce( function (a, b) { return a + b; }, 0 )
    },

  • allanallan Posts: 61,726Questions: 1Answers: 10,110 Site admin
    Answer ✓

    It would need to be:

    _colspan: function ()
    {
      return this.s.dt.columns().visible().reduce( function (a, b) { return a + b; }, 0 )
    },
    

    Allan

  • harakanharakan Posts: 4Questions: 1Answers: 0

    Thank you so much! I can confirm that code works correctly in my test; apologies for mis-implementing your original code and missing the extra return.

    Thanks again for developing such an awesome tool!

  • allanallan Posts: 61,726Questions: 1Answers: 10,110 Site admin

    Excellent - great to hear that helped. I'll test it locally as well and then include it in the RowGroup extension.

    Thanks for the feedback!
    Allan

  • allanallan Posts: 61,726Questions: 1Answers: 10,110 Site admin

    Just a quick update here - I've finally committed the fix. The nightly will update with the change shortly.

    Regards,
    Allan

This discussion has been closed.