Add a fixed, unsortable row every N rows.

Add a fixed, unsortable row every N rows.

fssghtfssght Posts: 2Questions: 1Answers: 0

Hello all,

I'm using a Wordpress plugin that uses DataTables, and I want to know if there's a way of adding a fixed/unsortable row every N rows in a table.

A little like this: https://datatables.net/examples/advanced_init/row_grouping.html but the "header" row in this case wouldn't move, while everything else could be sorted normally, without being grouped. If necessary I can add a <tr class="no-sort"> every N rows in my data from the backend, though from my Googling this doesn't seem like the correct way to go about it.

This is the code I'm working with: https://plugins.trac.wordpress.org/browser/posts-data-table/tags/1.0.4/assets/js/posts-data-table.js

I don't have the slightest clue when it comes to JavaScript, so any help is welcome, even if it's something obvious.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,794Questions: 1Answers: 10,514 Site admin
    Answer ✓

    Sort of. You can use orderFixed to apply fixed ordering to the table, forcing DataTables to always sort by the given column first, before then sorting by the user defined column.

    Example (same as the example link, just with orderFixed defined).

    Allan

  • fssghtfssght Posts: 2Questions: 1Answers: 0

    Hi Allan,

    Thank you for your suggestion, but it didn't quite do what I wanted. I've figured out how to do it, posting here for posterity.

                $(window).load(function(e) {
                    $('#posts-table-1 tr:nth-child(5n)').after('<tr><td>stuff</td></tr>');
                });
    

    And

                $(this).on('draw.dt', function () {
                    $('#posts-table-1 tr:nth-child(5n)').after('<tr><td>stuff</td></tr>');
                });
    

    Probably pretty crude, but gets the job done.

This discussion has been closed.