filamentgroup / tablesaw

A group of plugins for responsive tables.
MIT License
5.48k stars 434 forks source link

Sorting & showing \ hiding detail rows #148

Closed swifferly closed 7 years ago

swifferly commented 9 years ago

Dear filamentgroup

Question – I am using this snippet of jQuery to hide detail rows:

<script>
      $(document).ready(function() {
      $('table.tablesaw').each(function() {
        var $table = $(this);
        $table.find('.parent').click(function() {
            $(this).nextUntil('.parent').toggle(); // must use jQuery 1.4 for nextUntil() method
        });
        var $childRows = $table.find('tbody tr').not('.parent').hide();
        $table.find('button.hide').click(function() {
            $childRows.hide();
        });
        $table.find('button.show').click(function() {
            $childRows.show();
        });
    });
});
</script>

What I can’t work out is how to get this functionality working after the table has been sorted. I’ve tried limiting your getTableSort function to just the .parent, like so:

getTableRows: function(){
           return $( this ).find( "tbody tr.parent" ); // filters out detail rows
  },

Which seems to work well – except that the detail rows get deleted once the table is sorted.

I found a Stackoverflow solution which suggests associating the child rows with the .parent class pre-sort, and then redrawing them post-sort.

Unfortunately I’m not familiar enough with jQuery or your code to know where to integrate this.

Any thoughts would be hugely appreciated.

jeepstone commented 8 years ago

Swifferly, did you find a solution to this? I have a similar problem.

swifferly commented 8 years ago

Not yet.

From: Pete Jones [mailto:notifications@github.com] Sent: 19 April 2016 18:08 To: filamentgroup/tablesaw tablesaw@noreply.github.com Cc: Hesseltje van Goor hesseltje.vangoor@eigentech.com Subject: Re: [filamentgroup/tablesaw] Sorting & showing \ hiding detail rows (#148)

Swifferly, did you find a solution to this? I have a similar problem.

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHubhttps://github.com/filamentgroup/tablesaw/issues/148#issuecomment-212021093

zachleat commented 7 years ago

There are two kind-of hidden features in Tablesaw to deal with this (available in 3.x):