Is there a way to delete rows after doing a sort?

Is there a way to delete rows after doing a sort?

leftfieldleftfield Posts: 3Questions: 1Answers: 0

I have a DataTable where I've used the rowGroup extension in order to group by a certain value. Within the rowGroup I used the endRender option to have a grouping "summary" row (like in this example).

What I want to achieve is if the table is sorted by any column, I want to get rid of that "summary" row. Otherwise the table is weirdly littered with it, and it makes no sense anymore in the context of the new sort. So, I tried to do an order event, like so (assume all the summary rows to remove have a .summary-row class so I can easily grab them):

$('#my-table').on( 'order.dt', function () { my_table.row('.summary-row').remove().draw(); });

This does not work and results in stack level too deep when I call draw(). Can anyone help me accomplish this?

Thanks!

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954

    You can use rowGroup().disable() to disable row grouping in the order event.

    Kevin

  • leftfieldleftfield Posts: 3Questions: 1Answers: 0

    Thanks. I must be missing some js fundamental here, because I keep ending up at Uncaught RangeError: Maximum call stack size exceeded.

    So I have my datatable set up:

    var my_table = $("#my-table").DataTable({ ...all the options... });

    Then right under that I have the code I want to run upon ordering:

    $('#my-table').on( 'order.dt', function () { my_table.rowGroup().disable().draw(); });

    That results in the error when I order by any column.

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954
    Answer ✓

    Sorry, the draw() is causing the problem. Instead of using $('#my-table').on(...) you will want to use one(), for example:
    http://live.datatables.net/woboyeze/1/edit

    Kevin

  • leftfieldleftfield Posts: 3Questions: 1Answers: 0

    You rock @kthorngren, that did it!

This discussion has been closed.